-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from bcgov/5266-reinstate-over-age-dependent
5266 reinstate over age dependent
- Loading branch information
Showing
25 changed files
with
1,155 additions
and
135 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/MaintenanceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package ca.bc.gov.hlth.hnweb.controller; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.validation.Valid; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPRE0Converter; | ||
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPRE0; | ||
import ca.bc.gov.hlth.hnweb.model.rest.maintenance.ReinstateOverAgeDependentRequest; | ||
import ca.bc.gov.hlth.hnweb.model.rest.maintenance.ReinstateOverAgeDependentResponse; | ||
import ca.bc.gov.hlth.hnweb.persistence.entity.AffectedPartyDirection; | ||
import ca.bc.gov.hlth.hnweb.persistence.entity.IdentifierType; | ||
import ca.bc.gov.hlth.hnweb.persistence.entity.Transaction; | ||
import ca.bc.gov.hlth.hnweb.security.TransactionType; | ||
import ca.bc.gov.hlth.hnweb.service.MaintenanceService; | ||
|
||
/** | ||
* Handles request related to Coverage Maintenance. | ||
*/ | ||
@RequestMapping("/maintenance") | ||
@RestController | ||
public class MaintenanceController extends BaseController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(MaintenanceController.class); | ||
|
||
@Autowired | ||
private MaintenanceService maintenanceService; | ||
|
||
@PostMapping("/reinstate-over-age-dependent") | ||
public ResponseEntity<ReinstateOverAgeDependentResponse> reinstateOverAgeDependent(@Valid @RequestBody ReinstateOverAgeDependentRequest reinstateRequest, HttpServletRequest request) { | ||
|
||
logger.info("Reinstate over age dependent request: {} ", reinstateRequest.getPhn()); | ||
|
||
Transaction transaction = auditReinstateOverAgeDependentStart(reinstateRequest, request); | ||
|
||
try { | ||
RPBSPRE0Converter converter = new RPBSPRE0Converter(); | ||
RPBSPRE0 pre0Request = converter.convertRequest(reinstateRequest); | ||
|
||
RPBSPRE0 pre0Response = maintenanceService.reinstateOverAgeDependent(pre0Request, transaction); | ||
|
||
ReinstateOverAgeDependentResponse reinstateResponse = converter.convertResponse(pre0Response); | ||
|
||
ResponseEntity<ReinstateOverAgeDependentResponse> response = ResponseEntity.ok(reinstateResponse); | ||
logger.info("reinstateOverAgeDependent response: {} ", reinstateResponse); | ||
|
||
transactionComplete(transaction); | ||
addAffectedParty(transaction, IdentifierType.PHN, reinstateResponse.getPhn(), AffectedPartyDirection.OUTBOUND); | ||
|
||
return response; | ||
} catch (Exception e) { | ||
handleException(transaction, e); | ||
return null; | ||
} | ||
} | ||
|
||
private Transaction auditReinstateOverAgeDependentStart(ReinstateOverAgeDependentRequest reinstateRequest, HttpServletRequest request) { | ||
Transaction transaction = transactionStart(request, TransactionType.REINSTATE_OVER_AGE_DEPENDENT); | ||
addAffectedParty(transaction, IdentifierType.GROUP_NUMBER, reinstateRequest.getGroupNumber(), AffectedPartyDirection.INBOUND); | ||
addAffectedParty(transaction, IdentifierType.PHN, reinstateRequest.getPhn(), AffectedPartyDirection.INBOUND); | ||
addAffectedParty(transaction, IdentifierType.PHN, reinstateRequest.getDependentPhn(), AffectedPartyDirection.INBOUND); | ||
return transaction; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
backend/src/main/java/ca/bc/gov/hlth/hnweb/converter/rapid/RPBSPRE0Converter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package ca.bc.gov.hlth.hnweb.converter.rapid; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
|
||
import ca.bc.gov.hlth.hnweb.model.rapid.RE0; | ||
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSHeader; | ||
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPRE0; | ||
import ca.bc.gov.hlth.hnweb.model.rest.maintenance.ReinstateOverAgeDependentRequest; | ||
import ca.bc.gov.hlth.hnweb.model.rest.maintenance.ReinstateOverAgeDependentResponse; | ||
|
||
public class RPBSPRE0Converter extends BaseRapidConverter { | ||
private static final String TRAN_CODE = "RPBSPRE0"; | ||
|
||
public RPBSPRE0Converter() { | ||
super(); | ||
} | ||
|
||
public RPBSPRE0 convertRequest(ReinstateOverAgeDependentRequest request) { | ||
RPBSHeader rpbsHeader = new RPBSHeader(); | ||
rpbsHeader.setOrganization(userInfo.getOrganization()); | ||
rpbsHeader.setTranCode(getTranCode()); | ||
|
||
RE0 re0 = new RE0(); | ||
re0.setSubscriberPHN(request.getPhn()); | ||
re0.setGroupNumber(request.getGroupNumber()); | ||
re0.setDependentPHN(request.getDependentPhn()); | ||
re0.setDependentDOB(formatDate(request.getDependentDateOfBirth())); | ||
re0.setCanadianStudent(request.getIsStudent()); | ||
LocalDate studentEndDate = request.getStudentEndDate() != null ? request.getStudentEndDate() : calculateStudentEndDate(request.getDependentDateOfBirth()); | ||
re0.setStudentEndDate(studentEndDate.format(DateTimeFormatter.ofPattern(RAPID_YYYY_MM_FORMAT))); | ||
|
||
RPBSPRE0 rpbspre0 = new RPBSPRE0(); | ||
rpbspre0.setRpbsHeader(rpbsHeader); | ||
rpbspre0.setRe0(re0); | ||
|
||
return rpbspre0; | ||
} | ||
|
||
public ReinstateOverAgeDependentResponse convertResponse(RPBSPRE0 rpbspre0) { | ||
ReinstateOverAgeDependentResponse response = new ReinstateOverAgeDependentResponse(); | ||
RPBSHeader header = rpbspre0.getRpbsHeader(); | ||
|
||
handleStatus(header, response); | ||
|
||
response.setPhn(rpbspre0.getRe0().getDependentPHN()); | ||
|
||
return response; | ||
} | ||
|
||
@Override | ||
public String getTranCode() { | ||
return TRAN_CODE; | ||
} | ||
|
||
private LocalDate calculateStudentEndDate(LocalDate birthDate) { | ||
// The end date is to be stripped of the dd portion. If the end date is empty then a new end date | ||
// is to be made up from the dependents birth date and the current year plus one | ||
return LocalDate.of(LocalDate.now().getYear(), birthDate.getMonth(), birthDate.getDayOfMonth()).plusYears(1); | ||
} | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rapid/RE0.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package ca.bc.gov.hlth.hnweb.model.rapid; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class RE0 { | ||
|
||
/** 1 SubscriberPHN String No 0...10 .. */ | ||
private String subscriberPHN; | ||
/** 2 GroupNumber String No 0...7 .. */ | ||
private String groupNumber; | ||
/** 3 DependentPHN String No 0...10 .. */ | ||
private String dependentPHN; | ||
/** 4 DependentDOB RPBSDate No 0...10 .. */ | ||
private String dependentDOB; | ||
/** 5 CanadianStudent String No 0...1 .. (Valid values are 'Y', 'N') **/ | ||
private String canadianStudent; | ||
/** 6 StudentEndDate String No 0...10 .. */ | ||
private String studentEndDate; | ||
|
||
public RE0() { | ||
super(); | ||
} | ||
|
||
public RE0(String message) { | ||
super(); | ||
subscriberPHN = StringUtils.substring(message, 0, 10); | ||
groupNumber = StringUtils.substring(message, 10, 17); | ||
dependentPHN = StringUtils.substring(message, 17, 27); | ||
dependentDOB = StringUtils.substring(message, 27, 34); | ||
canadianStudent = StringUtils.substring(message, 34, 35); | ||
studentEndDate = StringUtils.substring(message, 35, 42); | ||
} | ||
|
||
public String serialize() { | ||
// Serialize is only used in when creating the request | ||
StringBuilder sb = new StringBuilder(); | ||
sb.append(StringUtils.rightPad(subscriberPHN, 10)); | ||
sb.append(StringUtils.rightPad(groupNumber, 7)); | ||
sb.append(StringUtils.rightPad(dependentPHN, 10)); | ||
sb.append(StringUtils.rightPad(dependentDOB, 10)); | ||
sb.append(StringUtils.rightPad(canadianStudent, 1)); | ||
sb.append(StringUtils.rightPad(studentEndDate, 7)); | ||
|
||
return sb.toString(); | ||
} | ||
|
||
public String getSubscriberPHN() { | ||
return subscriberPHN; | ||
} | ||
|
||
public void setSubscriberPHN(String subscriberPHN) { | ||
this.subscriberPHN = subscriberPHN; | ||
} | ||
|
||
public String getGroupNumber() { | ||
return groupNumber; | ||
} | ||
|
||
public void setGroupNumber(String groupNumber) { | ||
this.groupNumber = groupNumber; | ||
} | ||
|
||
public String getDependentPHN() { | ||
return dependentPHN; | ||
} | ||
|
||
public void setDependentPHN(String dependentPHN) { | ||
this.dependentPHN = dependentPHN; | ||
} | ||
|
||
public String getDependentDOB() { | ||
return dependentDOB; | ||
} | ||
|
||
public void setDependentDOB(String dependentDOB) { | ||
this.dependentDOB = dependentDOB; | ||
} | ||
|
||
public String getCanadianStudent() { | ||
return canadianStudent; | ||
} | ||
|
||
public void setCanadianStudent(String canadianStudent) { | ||
this.canadianStudent = canadianStudent; | ||
} | ||
|
||
public String getStudentEndDate() { | ||
return studentEndDate; | ||
} | ||
|
||
public void setStudentEndDate(String studentEndDate) { | ||
this.studentEndDate = studentEndDate; | ||
} | ||
|
||
|
||
|
||
} |
42 changes: 42 additions & 0 deletions
42
backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rapid/RPBSPRE0.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package ca.bc.gov.hlth.hnweb.model.rapid; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public class RPBSPRE0 { | ||
private RPBSHeader rpbsHeader = new RPBSHeader(); | ||
private RE0 re0 = new RE0(); | ||
|
||
public RPBSPRE0() { | ||
super(); | ||
} | ||
|
||
public RPBSPRE0(String message) { | ||
String headerText = StringUtils.substring(message, 0, RPBSHeader.SEGMENT_LENGTH); | ||
String bodyText = StringUtils.substring(message, RPBSHeader.SEGMENT_LENGTH); | ||
|
||
rpbsHeader = new RPBSHeader(headerText); | ||
|
||
re0 = new RE0(bodyText); | ||
} | ||
|
||
public RPBSHeader getRpbsHeader() { | ||
return rpbsHeader; | ||
} | ||
|
||
public void setRpbsHeader(RPBSHeader rpbsHeader) { | ||
this.rpbsHeader = rpbsHeader; | ||
} | ||
|
||
public String serialize() { | ||
return rpbsHeader.serialize() + re0.serialize(); | ||
} | ||
|
||
public RE0 getRe0() { | ||
return re0; | ||
} | ||
|
||
public void setRe0(RE0 re0) { | ||
this.re0 = re0; | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
...in/java/ca/bc/gov/hlth/hnweb/model/rest/maintenance/ReinstateOverAgeDependentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ca.bc.gov.hlth.hnweb.model.rest.maintenance; | ||
|
||
import java.time.LocalDate; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
|
||
public class ReinstateOverAgeDependentRequest { | ||
|
||
private String phn; | ||
|
||
private String groupNumber; | ||
|
||
private String dependentPhn; | ||
|
||
@JsonFormat(pattern = "yyyy-MM-dd") | ||
private LocalDate dependentDateOfBirth; | ||
|
||
private String isStudent; | ||
|
||
@JsonFormat(pattern = "yyyy-MM-dd") | ||
private LocalDate studentEndDate; | ||
|
||
public String getPhn() { | ||
return phn; | ||
} | ||
|
||
public void setPhn(String phn) { | ||
this.phn = phn; | ||
} | ||
|
||
public String getGroupNumber() { | ||
return groupNumber; | ||
} | ||
|
||
public void setGroupNumber(String groupNumber) { | ||
this.groupNumber = groupNumber; | ||
} | ||
|
||
public String getDependentPhn() { | ||
return dependentPhn; | ||
} | ||
|
||
public void setDependentPhn(String dependentPhn) { | ||
this.dependentPhn = dependentPhn; | ||
} | ||
|
||
public LocalDate getDependentDateOfBirth() { | ||
return dependentDateOfBirth; | ||
} | ||
|
||
public void setDependentDateOfBirth(LocalDate dependentDateOfBirth) { | ||
this.dependentDateOfBirth = dependentDateOfBirth; | ||
} | ||
|
||
public String getIsStudent() { | ||
return isStudent; | ||
} | ||
|
||
public void setIsStudent(String isStudent) { | ||
this.isStudent = isStudent; | ||
} | ||
|
||
public LocalDate getStudentEndDate() { | ||
return studentEndDate; | ||
} | ||
|
||
public void setStudentEndDate(LocalDate studentEndDate) { | ||
this.studentEndDate = studentEndDate; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...n/java/ca/bc/gov/hlth/hnweb/model/rest/maintenance/ReinstateOverAgeDependentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package ca.bc.gov.hlth.hnweb.model.rest.maintenance; | ||
|
||
import ca.bc.gov.hlth.hnweb.model.rest.BaseResponse; | ||
|
||
public class ReinstateOverAgeDependentResponse extends BaseResponse { | ||
|
||
private String phn; | ||
|
||
public String getPhn() { | ||
return phn; | ||
} | ||
|
||
public void setPhn(String pid) { | ||
this.phn = pid; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.