Skip to content

Commit

Permalink
Merge pull request #105 from bcgov/5266-reinstate-over-age-dependent
Browse files Browse the repository at this point in the history
5266 reinstate over age dependent
  • Loading branch information
weskubo-cgi authored Aug 4, 2022
2 parents 83c2427 + de17df6 commit b8bb0f6
Show file tree
Hide file tree
Showing 25 changed files with 1,155 additions and 135 deletions.
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public abstract class BaseRapidConverter {

protected static final String RAPID_DATE_FORMAT = "yyyy-MM-dd";

protected static final String RAPID_YYYY_MM_FORMAT = "yyyy-MM";

protected static final String STATUS_CODE_SUCCESS = "RPBS9014";

protected static final String SUCCESS_MESSAGE = "TRANSACTION COMPLETED";
Expand Down
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 backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rapid/RE0.java
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;
}



}
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;
}

}
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;
}
}
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ protected void configure(HttpSecurity http) throws Exception {
.mvcMatchers(HttpMethod.POST, "/group-member/add-group-member").hasRole("AddGroupMember")
.mvcMatchers(HttpMethod.POST, "/group-member/cancel-dependent").hasRole("CancelDependent")
.mvcMatchers(HttpMethod.POST, "/group-member/cancel-group-member").hasRole("CancelGroupMember")
.mvcMatchers(HttpMethod.POST, "/group-member/update-number-and-dept").hasRole("UpdateNumberAndDept")
.mvcMatchers(HttpMethod.POST, "/group-member/update-number-and-dept").hasRole("UpdateNumberAndDept")
.mvcMatchers(HttpMethod.POST, "/group-member/reinstate-over-age-dependent").hasRole("ReinstateOverAgeDependent")
.mvcMatchers(HttpMethod.POST, "/msp-contracts/get-contract-periods").hasRole("GetContractPeriods")
.mvcMatchers(HttpMethod.POST, "/msp-contracts/update-contract-address").hasRole("UpdateContractAddress")
.mvcMatchers(HttpMethod.POST, "/msp-contracts/inquire-contract").hasAnyRole("ContractInquiry", "GetGroupMembersContractAddress") //inquire-contract endpoint will require this multi role as it is used by both R40 and R37 transactions
Expand Down
Loading

0 comments on commit b8bb0f6

Please sign in to comment.