Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5271 r51 extend cancel date for visa resident #135

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
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.ExtendCancelDateRequest;
import ca.bc.gov.hlth.hnweb.model.rest.maintenance.ExtendCancelDateResponse;
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;
Expand Down Expand Up @@ -118,7 +120,38 @@ public ResponseEntity<ChangeCancelDateResponse> changeCancelDate(
return null;
}
}
/**
* Extend the premium cancellation date of an employee. Maps to the legacy R51(z25).
*
* @param extendCancelDateRequest
* @return The result of the operation.
*/
@PostMapping("/extend-cancel-date")
public ResponseEntity<ExtendCancelDateResponse> extendCancelDate(
@Valid @RequestBody ExtendCancelDateRequest extendCancelDateRequest, HttpServletRequest request) {

Transaction transaction = auditExtendCancelDateStart(extendCancelDateRequest.getPhn(), request);

try {
RPBSPAG0Converter converter = new RPBSPAG0Converter();
RPBSPAG0 rpbspag0Request = converter.convertRequest(extendCancelDateRequest);
RPBSPAG0 rpbspag0Response = maintenanceService.extendCancelDate(rpbspag0Request, transaction);
ExtendCancelDateResponse extendCancelDateResponse = converter
.convertExtendCancelDateResponse(rpbspag0Response);

ResponseEntity<ExtendCancelDateResponse> response = ResponseEntity.ok(extendCancelDateResponse);

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

auditExtendCancelDateComplete(transaction, extendCancelDateResponse.getPhn());

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

/**
* Reinstates coverage for an overage dependent. Maps to the legacy R43.
*
Expand Down Expand Up @@ -225,6 +258,25 @@ private void auditChangeEffectiveDateComplete(Transaction transaction,
}
}

private Transaction auditExtendCancelDateStart(String phn, HttpServletRequest request) {

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

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

private void auditExtendCancelDateComplete(Transaction transaction, String phn) {

transactionComplete(transaction);

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

private Transaction auditChangeCancelDateStart(String phn, HttpServletRequest request) {

Transaction transaction = transactionStart(request, TransactionType.CHANGE_CANCEL_DATE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPAG0;
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.ExtendCancelDateRequest;
import ca.bc.gov.hlth.hnweb.model.rest.maintenance.ExtendCancelDateResponse;

public class RPBSPAG0Converter extends BaseRapidConverter {
private static final String TRAN_CODE = "RPBSPAG0";
Expand All @@ -31,6 +33,27 @@ public RPBSPAG0 convertRequest(ChangeCancelDateRequest request) {
return rpbspag0;
}

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

AG0 ag0 = new AG0();
ag0.setGroupNumber(request.getGroupNumber());
ag0.setPhn(request.getPhn());
ag0.setExistingCancellationDate(formatDate(request.getExistingCancellationDate()));
ag0.setNewCancellationDate(formatDate(request.getNewCancellationDate()));
ag0.setImmigrationCode(request.getImmigrationCode());
ag0.setPermitIssueDate(formatDate(request.getPermitIssueDate()));
ag0.setPermitExpiryDate(formatDate(request.getPermitExpiryDate()));

RPBSPAG0 rpbspag0 = new RPBSPAG0();
rpbspag0.setRpbsHeader(rpbsHeader);
rpbspag0.setAg0(ag0);

return rpbspag0;
}

public ChangeCancelDateResponse convertResponse(RPBSPAG0 rpbspag0) {
ChangeCancelDateResponse response = new ChangeCancelDateResponse();
RPBSHeader header = rpbspag0.getRpbsHeader();
Expand All @@ -40,6 +63,16 @@ public ChangeCancelDateResponse convertResponse(RPBSPAG0 rpbspag0) {

return response;
}

public ExtendCancelDateResponse convertExtendCancelDateResponse(RPBSPAG0 rpbspag0) {
ExtendCancelDateResponse response = new ExtendCancelDateResponse();
RPBSHeader header = rpbspag0.getRpbsHeader();

handleStatus(header, response);
response.setPhn(rpbspag0.getAg0().getPhn());

return response;
}

@Override
public String getTranCode() {
Expand Down
47 changes: 47 additions & 0 deletions backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rapid/AG0.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ public class AG0 {
private String existingCancellationDate;
/** 4 NewCancellationDate RPBSDate No 0...10 .. */
private String newCancellationDate;
/** 5 ImmigrationCode String No 0...1 .. */
private String immigrationCode;
/** 6 PermitIssueDate RPBSDate No 0...10 .. */
private String permitIssueDate;
/** 6 PermitExpiryDate RPBSDate No 0...10 .. */
private String permitExpiryDate;


public AG0() {
super();
Expand All @@ -23,6 +30,9 @@ public AG0(String message) {
phn = StringUtils.substring(message, 7, 17);
existingCancellationDate = StringUtils.substring(message, 17, 27);
newCancellationDate = StringUtils.substring(message, 27, 37);
immigrationCode = StringUtils.substring(message, 37, 38);
permitIssueDate = StringUtils.substring(message, 38, 48);
permitExpiryDate = StringUtils.substring(message, 48, 58);

}

Expand All @@ -37,6 +47,19 @@ public String serialize() {

return sb.toString();
}

public String serializeECD() {
// Serialize is only used in when creating the request
StringBuilder sb = new StringBuilder();
sb.append(StringUtils.rightPad(groupNumber, 7));
sb.append(StringUtils.rightPad(phn, 10));
sb.append(StringUtils.rightPad(existingCancellationDate, 10));
sb.append(StringUtils.rightPad(newCancellationDate, 10));
sb.append(StringUtils.rightPad(immigrationCode, 1));
sb.append(StringUtils.rightPad(permitIssueDate, 10));
sb.append(StringUtils.rightPad(permitExpiryDate, 10));
return sb.toString();
}

public String getGroupNumber() {
return groupNumber;
Expand Down Expand Up @@ -70,4 +93,28 @@ public void setNewCancellationDate(String newCancellationDate) {
this.newCancellationDate = newCancellationDate;
}

public String getImmigrationCode() {
return immigrationCode;
}

public void setImmigrationCode(String immigrationCode) {
this.immigrationCode = immigrationCode;
}

public String getPermitIssueDate() {
return permitIssueDate;
}

public void setPermitIssueDate(String permitIssueDate) {
this.permitIssueDate = permitIssueDate;
}

public String getPermitExpiryDate() {
return permitExpiryDate;
}

public void setPermitExpiryDate(String permitExpiryDate) {
this.permitExpiryDate = permitExpiryDate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ public void setRpbsHeader(RPBSHeader rpbsHeader) {
public String serialize() {
return rpbsHeader.serialize() + ag0.serialize();
}

public String serializeECD() {
return rpbsHeader.serialize() + ag0.serializeECD();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package ca.bc.gov.hlth.hnweb.model.rest.maintenance;

import java.time.LocalDate;

public class ExtendCancelDateRequest {
private String groupNumber;
private String phn;
private LocalDate existingCancellationDate;
private LocalDate newCancellationDate;
private String immigrationCode;
private LocalDate permitIssueDate;
private LocalDate permitExpiryDate;

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 LocalDate getExistingCancellationDate() {
return existingCancellationDate;
}

public void setExistingCancellationDate(LocalDate existingCancellationDate) {
this.existingCancellationDate = existingCancellationDate;
}

public LocalDate getNewCancellationDate() {
return newCancellationDate;
}

public void setNewCancellationDate(LocalDate newCancellationDate) {
this.newCancellationDate = newCancellationDate;
}

public String getImmigrationCode() {
return immigrationCode;
}

public void setImmigrationCode(String immigrationCode) {
this.immigrationCode = immigrationCode;
}

public LocalDate getPermitIssueDate() {
return permitIssueDate;
}

public void setPermitIssueDate(LocalDate permitIssueDate) {
this.permitIssueDate = permitIssueDate;
}

public LocalDate getPermitExpiryDate() {
return permitExpiryDate;
}

public void setPermitExpiryDate(LocalDate permitExpiryDate) {
this.permitExpiryDate = permitExpiryDate;
}

@Override
public String toString() {
return "ExtendCancelDateRequest [groupNumber=" + groupNumber + ", phn=" + phn + ", existingCancellationDate="
+ existingCancellationDate + ", newCancellationDate=" + newCancellationDate + ", immigrationCode="
+ immigrationCode + ", permitIssueDate=" + permitIssueDate + ", permitExpiryDate=" + permitExpiryDate
+ "]";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ca.bc.gov.hlth.hnweb.model.rest.maintenance;

import ca.bc.gov.hlth.hnweb.model.rest.BaseResponse;

public class ExtendCancelDateResponse extends BaseResponse {
private String phn;

public String getPhn() {
return phn;
}

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

@Override
public String toString() {
return "ExtendCancelDateResponse [phn=" + phn + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum TransactionType {
RENEW_CANCELLED_COVERAGE("RenewCancelledCoverage"), // R45
CHANGE_EFFECTIVE_DATE("ChangeEffectiveDate"), // R46a
CHANGE_CANCEL_DATE("ChangeCancelDate"), // R46b
EXTEND_CANCEL_DATE("ExtendCancelDate"), // R51
GET_PATIENT_REGISTRATION("GetPatientRegistration"), // R70
UNKNOWN("Unknown");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public class MaintenanceService extends BaseService {

@Value("${rapid.r46Path:}")
private String r46Path;

@Value("${rapid.r51Path:}")
private String r51Path;

@Autowired
private WebClient rapidWebClient;
Expand Down Expand Up @@ -97,6 +100,35 @@ public RPBSPAG0 changeCancelDate(RPBSPAG0 rpbspag0, Transaction transaction) thr
return rpbspag0Response;
}

/**
* Extends Coverage Cancellation Date for the group member based on the R51/RPBSPAG0 request.
*
* @param rpbspag0
* @param transaction
* @return The RPBSPAG0 response.
* @throws HNWebException
*/
public RPBSPAG0 extendCancelDate(RPBSPAG0 rpbspag0, Transaction transaction) throws HNWebException {
String rpbspag0Str = rpbspag0.serializeECD();

logger.info("Request:\n{}", rpbspag0Str);

messageSent(transaction);
ResponseEntity<String> response = postRapidRequest(r46Path, rpbspag0Str,
transaction.getTransactionId().toString());
messageReceived(transaction);
logger.info("Response Status: {}; Message:\n{}", response.getStatusCode(), response.getBody());

if (response.getStatusCode() != HttpStatus.OK) {
logger.error("Could not connect to downstream service. Service returned {}", response.getStatusCode());
throw new HNWebException(ExceptionType.DOWNSTREAM_FAILURE);
}

RPBSPAG0 rpbspag0Response = new RPBSPAG0(response.getBody());

return rpbspag0Response;
}

/**
* Reinstate an Over Age Dependent based on the R43/RPBSPRE0 request.
*
Expand Down
Loading