Skip to content

Commit

Permalink
Merge branch '5268-renew-cancelled-group-coverage'
Browse files Browse the repository at this point in the history
  • Loading branch information
AnumehaSrivastava05 committed Oct 18, 2022
2 parents 82a6f62 + 4279c54 commit c585ba9
Show file tree
Hide file tree
Showing 21 changed files with 1,054 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,31 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import ca.bc.gov.hlth.hnweb.converter.rapid.BaseRapidConverter;
import ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPAG0Converter;
import ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPAI0Converter;
import ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPAJ0Converter;
import ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPRE0Converter;
import ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPXP0Converter;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPAG0;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPAI0;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPAJ0;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPRE0;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPXP0;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.AddGroupMemberRequest;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.ChangeEffectiveDateRequest;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.ChangeEffectiveDateResponse;
import ca.bc.gov.hlth.hnweb.model.rest.maintenance.ChangeCancelDateRequest;
import ca.bc.gov.hlth.hnweb.model.rest.maintenance.ChangeCancelDateResponse;
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.model.rest.maintenance.RenewCancelledGroupCoverageRequest;
import ca.bc.gov.hlth.hnweb.model.rest.maintenance.RenewCancelledGroupCoverageResponse;
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.GroupMemberService;
import ca.bc.gov.hlth.hnweb.service.MaintenanceService;

/**
Expand All @@ -42,6 +51,9 @@ public class MaintenanceController extends BaseController {

@Autowired
private MaintenanceService maintenanceService;

@Autowired
private GroupMemberService groupMemberService;

/**
* Changes coverage effective date for the group number. Maps to the legacy
Expand Down Expand Up @@ -140,6 +152,55 @@ public ResponseEntity<ReinstateOverAgeDependentResponse> reinstateOverAgeDepende
return null;
}
}

/**
* Renew the coverage effective date of an employee and spouse/dependents.
* Maps to the legacy R45 (Z27).
*
* @param RenewCancelledGroupCoverageRequest
* @return The result of the operation.
*/
@PostMapping("/renew-cancelled-group-coverage")
public ResponseEntity<RenewCancelledGroupCoverageResponse> renewCancelledGroupCoverage(
@Valid @RequestBody RenewCancelledGroupCoverageRequest renewCancelledGroupCoverageRequest,
HttpServletRequest request) {

Transaction transaction = auditRenewCancelledCoverageStart(renewCancelledGroupCoverageRequest.getPhn(),
request);

try {
RPBSPAI0Converter converter = new RPBSPAI0Converter();
RPBSPAI0 rpbspai0Request = converter.convertRequest(renewCancelledGroupCoverageRequest);
RPBSPAI0 rpbspai0Response = maintenanceService.renewCoverageEffectiveDate(rpbspai0Request, transaction);
RenewCancelledGroupCoverageResponse renewCancelledGroupCoverageResponse;

// Execute if RPBSPAI0 returns successfully
if (StringUtils.equals(rpbspai0Response.getRpbsHeader().getStatusCode(), BaseRapidConverter.STATUS_CODE_SUCCESS)) {
RPBSPXP0Converter rpbspxp0Converter = new RPBSPXP0Converter();

// Creates/Clones a new Coverage entry, not simply an update but an Add
AddGroupMemberRequest addGroupMemberRequest = converter.buildAddGroupMemberRequest(rpbspai0Response);
RPBSPXP0 rpbspxp0 = rpbspxp0Converter.convertRequest(addGroupMemberRequest);

RPBSPXP0 rpbspxp0Response = groupMemberService.addGroupMember(rpbspxp0, transaction);
renewCancelledGroupCoverageResponse = rpbspxp0Converter.convertResponseForRenewal(rpbspxp0Response);
} else {
renewCancelledGroupCoverageResponse = converter.convertResponse(rpbspai0Response);
}

ResponseEntity<RenewCancelledGroupCoverageResponse> response = ResponseEntity
.ok(renewCancelledGroupCoverageResponse);

logger.info("RenewCancelledGroupCoverageResponse response: {} ", response);

auditRenewCancelledCoverageComplete(transaction, renewCancelledGroupCoverageResponse.getPhn());

return response;
} catch (Exception e) {
handleException(transaction, e);
return null;
}
}

private Transaction auditChangeEffectiveDateStart(ChangeEffectiveDateRequest changeEffectiveDateRequest,
HttpServletRequest request) {
Expand Down Expand Up @@ -190,5 +251,24 @@ private Transaction auditReinstateOverAgeDependentStart(ReinstateOverAgeDependen
addAffectedParty(transaction, IdentifierType.PHN, reinstateRequest.getDependentPhn(), AffectedPartyDirection.INBOUND);
return transaction;
}

private Transaction auditRenewCancelledCoverageStart(String phn, HttpServletRequest request) {

Transaction transaction = transactionStart(request, TransactionType.RENEW_CANCELLED_COVERAGE);

if (StringUtils.isNotBlank(phn)) {
addAffectedParty(transaction, IdentifierType.PHN, phn, AffectedPartyDirection.INBOUND);
}
return transaction;
}

private void auditRenewCancelledCoverageComplete(Transaction transaction, String phn) {

transactionComplete(transaction);

if (StringUtils.isNotBlank(phn)) {
addAffectedParty(transaction, IdentifierType.PHN, phn, AffectedPartyDirection.OUTBOUND);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class BaseRapidConverter {

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

protected static final String STATUS_CODE_SUCCESS = "RPBS9014";
public 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,91 @@
package ca.bc.gov.hlth.hnweb.converter.rapid;

import java.time.LocalDate;

import ca.bc.gov.hlth.hnweb.model.rapid.AI0;
import ca.bc.gov.hlth.hnweb.model.rapid.R45NewPayer;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSAddress;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSHeader;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPAI0;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.AddGroupMemberRequest;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.MemberAddress;
import ca.bc.gov.hlth.hnweb.model.rest.maintenance.RenewCancelledGroupCoverageRequest;
import ca.bc.gov.hlth.hnweb.model.rest.maintenance.RenewCancelledGroupCoverageResponse;

public class RPBSPAI0Converter extends BaseRapidConverter {
private static final String TRAN_CODE = "RPBSPAI0";

public RPBSPAI0Converter() {
super();
}

public RPBSPAI0 convertRequest(RenewCancelledGroupCoverageRequest request) {
RPBSHeader rpbsHeader = new RPBSHeader();
rpbsHeader.setOrganization(userInfo.getOrganization());
rpbsHeader.setTranCode(getTranCode());

AI0 ai0 = new AI0();
ai0.setGroupNumber(request.getGroupNumber());
ai0.setPhn(request.getPhn());
ai0.setNewCoverageEffectiveDate(formatDate(request.getNewCoverageEffectiveDate()));

RPBSPAI0 rpbspai0 = new RPBSPAI0();
rpbspai0.setRpbsHeader(rpbsHeader);
rpbspai0.setAi0(ai0);

return rpbspai0;
}

public RenewCancelledGroupCoverageResponse convertResponse(RPBSPAI0 rpbspai0) {
RenewCancelledGroupCoverageResponse response = new RenewCancelledGroupCoverageResponse();
RPBSHeader header = rpbspai0.getRpbsHeader();

handleStatus(header, response);
response.setPhn(rpbspai0.getAi0().getPhn());

return response;
}

public AddGroupMemberRequest buildAddGroupMemberRequest(RPBSPAI0 rpbspai0) {
R45NewPayer newPayerData = rpbspai0.getAi0().getNewPayerData();
AddGroupMemberRequest request = new AddGroupMemberRequest();
request.setEffectiveDate(LocalDate.parse(rpbspai0.getAi0().getNewCoverageEffectiveDate()));
request.setPhn(newPayerData.getPhn());
request.setSpousePhn(newPayerData.getSpousePhn());
request.setDependentPhn1(newPayerData.getDependentPhn1());
request.setDependentPhn2(newPayerData.getDependentPhn2());
request.setDependentPhn3(newPayerData.getDependentPhn3());
request.setDependentPhn4(newPayerData.getDependentPhn4());
request.setDependentPhn5(newPayerData.getDependentPhn5());
request.setDependentPhn6(newPayerData.getDependentPhn6());
request.setDependentPhn7(newPayerData.getDependentPhn7());
request.setGroupNumber(newPayerData.getGroupNumber());
request.setGroupMemberNumber(newPayerData.getEmployeeNumber());
request.setDepartmentNumber(newPayerData.getDepartmentNumber());
request.setHomeAddress(convertToMemberAddress(newPayerData.getHomeAddress()));
request.setMailingAddress(convertToMemberAddress(newPayerData.getMailAddress()));
request.setPhone(newPayerData.getPhone1().getPhoneNumber());
return request;
}

private MemberAddress convertToMemberAddress(RPBSAddress rpbsAddress) {
MemberAddress memberAddress = new MemberAddress();

if (rpbsAddress == null) {
return memberAddress;
}
memberAddress.setAddressLine1(rpbsAddress.getAddressLine1());
memberAddress.setAddressLine2(rpbsAddress.getAddressLine2());
memberAddress.setAddressLine3(rpbsAddress.getAddressLine3());
memberAddress.setAddressLine4(rpbsAddress.getAddressLine4());
memberAddress.setPostalCode(rpbsAddress.getPostalCode());

return memberAddress;
}

@Override
public String getTranCode() {
return TRAN_CODE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.AddGroupMemberRequest;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.AddGroupMemberResponse;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.MemberAddress;
import ca.bc.gov.hlth.hnweb.model.rest.maintenance.RenewCancelledGroupCoverageResponse;

public class RPBSPXP0Converter extends BaseRapidConverter {
private static final String TRAN_CODE = "RPBSPXP0";
Expand Down Expand Up @@ -72,6 +73,16 @@ public AddGroupMemberResponse convertResponse(RPBSPXP0 rpbspxp0) {
return response;
}

public RenewCancelledGroupCoverageResponse convertResponseForRenewal(RPBSPXP0 rpbspxp0) {
RenewCancelledGroupCoverageResponse response = new RenewCancelledGroupCoverageResponse();
RPBSHeader header = rpbspxp0.getRpbsHeader();

handleStatus(header, response);
response.setPhn(rpbspxp0.getXp0().getPhn());

return response;
}

private RPBSAddress convertAddress(MemberAddress memberAddress) {
RPBSAddress rpbsAddress = new RPBSAddress();

Expand All @@ -87,7 +98,6 @@ private RPBSAddress convertAddress(MemberAddress memberAddress) {
return rpbsAddress;
}


@Override
public String getTranCode() {
return TRAN_CODE;
Expand Down
72 changes: 72 additions & 0 deletions backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rapid/AI0.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package ca.bc.gov.hlth.hnweb.model.rapid;

import org.apache.commons.lang3.StringUtils;

public class AI0 {

/** 1 GroupNumber String No 0...7 .. */
private String groupNumber;
/** 2 PHN String No 0...10 .. */
private String phn;
/** 3 NewCoverageEffectiveDate RPBSDate No 0...10 .. */
private String newCoverageEffectiveDate;
/** 4 NewPayerData String No 0...394 .. */
private R45NewPayer newPayerData;

public AI0() {
super();
}

public AI0(String message) {
super();
phn = StringUtils.substring(message, 0, 10);
groupNumber = StringUtils.substring(message, 10, 17);
newCoverageEffectiveDate = StringUtils.substring(message, 17, 27);
newPayerData = new R45NewPayer(StringUtils.substring(message, 27,421));

}

public String serialize() {
// Serialize is only used in when creating the request
// where only the first three fields are used
StringBuilder sb = new StringBuilder();
sb.append(StringUtils.rightPad(phn, 10));
sb.append(StringUtils.rightPad(groupNumber, 7));
sb.append(StringUtils.rightPad(newCoverageEffectiveDate, 10));

return sb.toString();
}

public String getGroupNumber() {
return groupNumber;
}

public void setGroupNumber(String groupNumber) {
this.groupNumber = groupNumber;
}

public String getPhn() {
return phn;
}

public void setPhn(String phn) {
this.phn = phn;
}

public String getNewCoverageEffectiveDate() {
return newCoverageEffectiveDate;
}

public void setNewCoverageEffectiveDate(String newCoverageEffectiveDate) {
this.newCoverageEffectiveDate = newCoverageEffectiveDate;
}

public R45NewPayer getNewPayerData() {
return newPayerData;
}

public void setNewPayerData(R45NewPayer ai0payeeData) {
this.newPayerData = ai0payeeData;
}

}
Loading

0 comments on commit c585ba9

Please sign in to comment.