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.CancelGroupMemberDependentRequest;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.CancelGroupMemberDependentResponse;
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 cancelGroupMemberDependentRequest
* @return The result of the operation.
*/
@PostMapping("/cancel-group-member-dependent")
public ResponseEntity<CancelGroupMemberDependentResponse> cancelGroupMemberDependent(@Valid @RequestBody CancelGroupMemberDependentRequest cancelGroupMemberDependentRequest) {
weskubo-cgi marked this conversation as resolved.
Show resolved Hide resolved

try {
RPBSPWP0Converter converter = new RPBSPWP0Converter();
RPBSPWP0 rpbspwp0 = converter.convertRequest(cancelGroupMemberDependentRequest);
RPBSPWP0 rpbspwc0Response = groupMemberService.cancelGroupMemberDependent(rpbspwp0);
CancelGroupMemberDependentResponse cancelGroupMemberDependentResponse = converter.convertResponse(rpbspwc0Response);

ResponseEntity<CancelGroupMemberDependentResponse> response = ResponseEntity.ok(cancelGroupMemberDependentResponse);

logger.info("cancelGroupMemberDependentResponse response: {} ", cancelGroupMemberDependentResponse);
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-group-member-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-group-member-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,53 @@
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.CancelGroupMemberDependentRequest;
import ca.bc.gov.hlth.hnweb.model.rest.groupmember.CancelGroupMemberDependentResponse;;

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

public RPBSPWP0Converter() {
super();
}

public RPBSPWP0 convertRequest(CancelGroupMemberDependentRequest 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;
}



weskubo-cgi marked this conversation as resolved.
Show resolved Hide resolved
public CancelGroupMemberDependentResponse convertResponse(RPBSPWP0 rpbspwp0) {
CancelGroupMemberDependentResponse response = new CancelGroupMemberDependentResponse();
RPBSHeader header = rpbspwp0.getRpbsHeader();

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

return response;
}


weskubo-cgi marked this conversation as resolved.
Show resolved Hide resolved
@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();
}

}
87 changes: 87 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,87 @@
package ca.bc.gov.hlth.hnweb.model.rapid;

import org.apache.commons.lang3.StringUtils;

public class WP0 {

/** 1 PHN String No 0...10 1..1 */
private String subscriberPhn;
/** 2 GroupNumber String No 0...7 1..1 */
private String groupNumber;
/** 3 beneficiaryPhn String No 0...10 1..1 */
private String beneficiaryPhn;
/** 4 CoverageCancelDate String No 0...10 1..1 */
private String coverageCancelDate;
/** 5 PayerCancelReason String No 0...1 1..1 */
private String payerCancelReason;
weskubo-cgi marked this conversation as resolved.
Show resolved Hide resolved

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);
// K or E
weskubo-cgi marked this conversation as resolved.
Show resolved Hide resolved
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;
}




weskubo-cgi marked this conversation as resolved.
Show resolved Hide resolved
}
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 CancelGroupMemberDependentRequest {
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 CancelGroupMemberDependentResponse 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,34 @@ 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 cancelGroupMemberDependent(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;
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove extra line breaks.


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