use of ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPEE0Converter in project moh-hnweb by bcgov.
the class GroupMemberController method updateNumberAndDept.
/**
* Updates a group member's number and/or department.
* Maps to the legacy R34.
*
* @param updateNumberAndDeptRequest
* @return The result of the update.
*/
@PostMapping("/update-number-and-dept")
public ResponseEntity<UpdateNumberAndDeptResponse> updateNumberAndDept(@Valid @RequestBody UpdateNumberAndDeptRequest updateNumberAndDeptRequest, HttpServletRequest request) {
Transaction transaction = auditUpdateNumberAndDeptStart(updateNumberAndDeptRequest, request);
// Do basic validation since there's no point in calling the downstream systems if the data isn't valid
if (StringUtils.isBlank(updateNumberAndDeptRequest.getDepartmentNumber()) && StringUtils.isBlank(updateNumberAndDeptRequest.getGroupMemberNumber())) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Department Number or Group Number is required");
}
try {
// Handle the department number
UpdateNumberAndDeptResponse deptNumberResponse = new UpdateNumberAndDeptResponse();
if (StringUtils.isNotBlank(updateNumberAndDeptRequest.getDepartmentNumber())) {
RPBSPED0Converter rpbsped0Converter = new RPBSPED0Converter();
RPBSPED0 rpbsped0Request = rpbsped0Converter.convertRequest(updateNumberAndDeptRequest);
RPBSPED0 rpbsped0Response = groupMemberService.updateGroupMemberDepartmentNumber(rpbsped0Request, transaction);
deptNumberResponse = rpbsped0Converter.convertResponse(rpbsped0Response);
}
// Handle the group member/employee number
UpdateNumberAndDeptResponse empNumberResponse = new UpdateNumberAndDeptResponse();
if (StringUtils.isNotBlank(updateNumberAndDeptRequest.getGroupMemberNumber())) {
RPBSPEE0Converter rpbspee0Converter = new RPBSPEE0Converter();
RPBSPEE0 rpbspee0Request = rpbspee0Converter.convertRequest(updateNumberAndDeptRequest);
RPBSPEE0 rpbspee0Response = groupMemberService.updateGroupMemberEmployeeNumber(rpbspee0Request, transaction);
empNumberResponse = rpbspee0Converter.convertResponse(rpbspee0Response);
}
// Combine the results
UpdateNumberAndDeptResponse updateNumberAndDeptResponse = handleUpdateGroupMemberResponse(deptNumberResponse, empNumberResponse);
ResponseEntity<UpdateNumberAndDeptResponse> response = ResponseEntity.ok(updateNumberAndDeptResponse);
logger.info("updateNumberAndDept response: {} ", updateNumberAndDeptResponse);
transactionComplete(transaction);
addAffectedParty(transaction, IdentifierType.PHN, updateNumberAndDeptResponse.getPhn());
return response;
} catch (Exception e) {
handleException(transaction, e);
return null;
}
}
Aggregations