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

5088 r36 cancel group member dependent #40

Merged
merged 12 commits into from
Feb 2, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@
import ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPED0Converter;
import ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPEE0Converter;
import ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPWC0Converter;
import ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPWP0Converter;
import ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPXP0Converter;
import ca.bc.gov.hlth.hnweb.exception.HNWebException;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPED0;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPEE0;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPWC0;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPWP0;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPXP0;
import ca.bc.gov.hlth.hnweb.model.rest.StatusEnum;
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.CancelDependentRequest;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.CancelDependentResponse;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.CancelGroupMemberRequest;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.CancelGroupMemberResponse;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.UpdateNumberAndDeptRequest;
Expand Down Expand Up @@ -173,6 +177,42 @@ public ResponseEntity<CancelGroupMemberResponse> cancelGroupMember(@Valid @Reque
}

}

/**
* Cancels a group member's dependent coverage.
* Maps to the legacy R36.
*
* @param cancelDependentRequest
* @return The result of the operation.
*/
@PostMapping("/cancel-dependent")
public ResponseEntity<CancelDependentResponse> cancelDependent(@Valid @RequestBody CancelDependentRequest cancelDependentRequest) {

try {
RPBSPWP0Converter converter = new RPBSPWP0Converter();
RPBSPWP0 rpbspwp0 = converter.convertRequest(cancelDependentRequest);
RPBSPWP0 rpbspwc0Response = groupMemberService.cancelDependent(rpbspwp0);
CancelDependentResponse cancelDependentResponse = converter.convertResponse(rpbspwc0Response);

ResponseEntity<CancelDependentResponse> response = ResponseEntity.ok(cancelDependentResponse);

logger.info("CancelDependentResponse response: {} ", cancelDependentResponse);
return response;
} catch (HNWebException hwe) {
switch (hwe.getType()) {
case DOWNSTREAM_FAILURE:
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, hwe.getMessage(), hwe);
default:
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Bad /cancel-dependent request", hwe);
}
} catch (WebClientException wce) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, wce.getMessage(), wce);
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Bad /cancel-dependent request", e);
}

}


private UpdateNumberAndDeptResponse handleUpdateGroupMemberResponse(UpdateNumberAndDeptResponse deptNumberResponse, UpdateNumberAndDeptResponse empNumberResponse) {
UpdateNumberAndDeptResponse response = new UpdateNumberAndDeptResponse();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ca.bc.gov.hlth.hnweb.converter.rapid;

import ca.bc.gov.hlth.hnweb.model.rapid.RPBSHeader;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPWP0;
import ca.bc.gov.hlth.hnweb.model.rapid.WP0;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.CancelDependentRequest;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.CancelDependentResponse;;

public class RPBSPWP0Converter extends BaseRapidConverter {
private static final String TRAN_CODE = "RPBSPWP0";

public RPBSPWP0Converter() {
super();
}

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

WP0 wp0 = new WP0();
wp0.setGroupNumber(request.getGroupNumber());
wp0.setSubscriberPhn(request.getPhn());
wp0.setBeneficiaryPhn(request.getDependentPhn());
wp0.setCoverageCancelDate(formatDate(request.getCoverageCancelDate()));
wp0.setPayerCancelReason(request.getCancelReason());

RPBSPWP0 rpbspwp0 = new RPBSPWP0();
rpbspwp0.setRpbsHeader(rpbsHeader);
rpbspwp0.setWp0(wp0);

return rpbspwp0;
}

public CancelDependentResponse convertResponse(RPBSPWP0 rpbspwp0) {
CancelDependentResponse response = new CancelDependentResponse();
RPBSHeader header = rpbspwp0.getRpbsHeader();

handleStatus(header, response);
response.setPhn(rpbspwp0.getWp0().getSubscriberPhn());

return response;
}

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

}
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 RPBSPWP0 {
private RPBSHeader rpbsHeader = new RPBSHeader();
private WP0 wp0 = new WP0();

public RPBSPWP0() {
super();
}

public RPBSPWP0(String message) {
String headerText = StringUtils.substring(message, 0, RPBSHeader.SEGMENT_LENGTH);
String bodyText = StringUtils.substring(message, RPBSHeader.SEGMENT_LENGTH);

rpbsHeader = new RPBSHeader(headerText);

wp0 = new WP0(bodyText);
}

public WP0 getWp0() {
return wp0;
}

public void setWp0(WP0 wp0) {
this.wp0 = wp0;
}

public RPBSHeader getRpbsHeader() {
return rpbsHeader;
}

public void setRpbsHeader(RPBSHeader rpbsHeader) {
this.rpbsHeader = rpbsHeader;
}

public String serialize() {
return rpbsHeader.serialize() + wp0.serialize();
}

}
84 changes: 84 additions & 0 deletions backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rapid/WP0.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package ca.bc.gov.hlth.hnweb.model.rapid;

import org.apache.commons.lang3.StringUtils;

public class WP0 {

/** 1 SubscriberPHN String No 0...10 */
private String subscriberPhn;
/** 2 GroupNumber String No 0...7 */
private String groupNumber;
/** 3 BeneficiaryPHN String No 0...10 */
private String beneficiaryPhn;
/** 4 CoverageCancelDate String No 0...10 */
private String coverageCancelDate;
/** 5 PayerCancelReason String No 0...1 */
private String payerCancelReason;

public WP0() {
super();
}

public WP0(String message) {
super();
subscriberPhn = StringUtils.substring(message, 0, 10);
groupNumber = StringUtils.substring(message, 10, 17);
beneficiaryPhn = StringUtils.substring(message, 17, 27);
coverageCancelDate = StringUtils.substring(message, 27, 37);
// I , E or P
payerCancelReason = StringUtils.substring(message, 37, 38);
}

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(beneficiaryPhn, 10));
sb.append(StringUtils.rightPad(coverageCancelDate, 10));
sb.append(StringUtils.rightPad(payerCancelReason, 1));

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 getBeneficiaryPhn() {
return beneficiaryPhn;
}

public void setBeneficiaryPhn(String beneficiaryPhn) {
this.beneficiaryPhn = beneficiaryPhn;
}

public String getCoverageCancelDate() {
return coverageCancelDate;
}

public void setCoverageCancelDate(String coverageCancelDate) {
this.coverageCancelDate = coverageCancelDate;
}

public String getPayerCancelReason() {
return payerCancelReason;
}

public void setPayerCancelReason(String payerCancelReason) {
this.payerCancelReason = payerCancelReason;
}

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

import java.time.LocalDate;

public class CancelDependentRequest {
private String phn;
private String groupNumber;
private String dependentPhn;
private LocalDate coverageCancelDate;
// Valid values are I, E and P
private String cancelReason;

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 getCoverageCancelDate() {
return coverageCancelDate;
}

public void setCoverageCancelDate(LocalDate coverageCancelDate) {
this.coverageCancelDate = coverageCancelDate;
}

public String getCancelReason() {
return cancelReason;
}

public void setCancelReason(String cancelReason) {
this.cancelReason = cancelReason;
}

@Override
public String toString() {
return "CancelGroupMemberRequest [phn=" + phn + ", groupNumber=" + groupNumber + ",dependentPhn=" + dependentPhn + ", coverageCancelDate=" + coverageCancelDate
+ ", cancelReason=" + cancelReason + "]";
}

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

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

public class CancelDependentResponse extends BaseResponse {
private String phn;

public String getPhn() {
return phn;
}

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

@Override
public String toString() {
return "CancelGroupMemberResponse [phn=" + phn + ", status=" + status + ", message=" + message + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPED0;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPEE0;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPWC0;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPWP0;
import ca.bc.gov.hlth.hnweb.model.rapid.RPBSPXP0;

/**
Expand All @@ -39,6 +40,9 @@ public class GroupMemberService {
@Value("${rapid.r35Path}")
private String r35Path;

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

@Autowired
private WebClient rapidWebClient;

Expand Down Expand Up @@ -145,6 +149,32 @@ public RPBSPWC0 cancelGroupMember(RPBSPWC0 rpbspwc0) throws HNWebException {

return rpbspwc0Response;
}

/**
* Cancels the group member's dependent coverage based on the R36/RPBSPWP0.
*
* @param rpbspwp0
* @return The RPBSPWP0 response.
* @throws HNWebException
*/
public RPBSPWP0 cancelDependent(RPBSPWP0 rpbspwp0) throws HNWebException {
String rpbspwp0Str = rpbspwp0.serialize();

logger.info("Request {}", rpbspwp0Str);

ResponseEntity<String> response = postRapidRequest(r36Path, rpbspwp0Str);

logger.debug("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);
}

RPBSPWP0 rpbspwp0Response = new RPBSPWP0(response.getBody());

return rpbspwp0Response;
}

private ResponseEntity<String> postRapidRequest(String path, String body) {
return rapidWebClient
Expand Down
Loading