Search in sources :

Example 1 with RPBSPEE0Converter

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;
    }
}
Also used : Transaction(ca.bc.gov.hlth.hnweb.persistence.entity.Transaction) RPBSPEE0(ca.bc.gov.hlth.hnweb.model.rapid.RPBSPEE0) RPBSPED0(ca.bc.gov.hlth.hnweb.model.rapid.RPBSPED0) RPBSPED0Converter(ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPED0Converter) UpdateNumberAndDeptResponse(ca.bc.gov.hlth.hnweb.model.rest.groupmember.UpdateNumberAndDeptResponse) ResponseStatusException(org.springframework.web.server.ResponseStatusException) ResponseStatusException(org.springframework.web.server.ResponseStatusException) RPBSPEE0Converter(ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPEE0Converter) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

RPBSPED0Converter (ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPED0Converter)1 RPBSPEE0Converter (ca.bc.gov.hlth.hnweb.converter.rapid.RPBSPEE0Converter)1 RPBSPED0 (ca.bc.gov.hlth.hnweb.model.rapid.RPBSPED0)1 RPBSPEE0 (ca.bc.gov.hlth.hnweb.model.rapid.RPBSPEE0)1 UpdateNumberAndDeptResponse (ca.bc.gov.hlth.hnweb.model.rest.groupmember.UpdateNumberAndDeptResponse)1 Transaction (ca.bc.gov.hlth.hnweb.persistence.entity.Transaction)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 ResponseStatusException (org.springframework.web.server.ResponseStatusException)1