diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/BcscPayeeMappingController.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/BcscPayeeMappingController.java deleted file mode 100644 index 037b63da..00000000 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/BcscPayeeMappingController.java +++ /dev/null @@ -1,157 +0,0 @@ -package ca.bc.gov.hlth.hnweb.controller; - -import java.util.Optional; - -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.server.ResponseStatusException; - -import ca.bc.gov.hlth.hnweb.exception.BcscPayeeMappingException; -import ca.bc.gov.hlth.hnweb.model.rest.pbf.BcscPayeeMappingRequest; -import ca.bc.gov.hlth.hnweb.model.rest.pbf.BcscPayeeMappingResponse; -import ca.bc.gov.hlth.hnweb.persistence.entity.pbf.BcscPayeeMapping; -import ca.bc.gov.hlth.hnweb.service.BcscPayeeMappingService; -import ca.bc.gov.hlth.hnweb.service.PBFClinicPayeeService; - -/** - * Controller to handle CRUD requests for maintaining BC Services Card (BCSC) Users to their PBF MSP Payee Number mappings. - * - */ -@RequestMapping("/payee-mapping") -@RestController -public class BcscPayeeMappingController { - - private static final Logger logger = LoggerFactory.getLogger(BcscPayeeMappingController.class); - - @Autowired - private BcscPayeeMappingService bcscPayeeMappingService; - - @Autowired - private PBFClinicPayeeService pbfClinicPayeeService; - - /** - * Create a BCSC User to MSP Payee Number mapping - * - * @param bcscPayeeMappingRequest - * @return the response containing the newly created mapping if successful otherwise an error status - */ - @PostMapping("") - public ResponseEntity addBcscPayeeMapping(@RequestBody BcscPayeeMappingRequest bcscPayeeMappingRequest) { - logger.info("Adding a new BCSC User to Payee Mapping:\n{}", bcscPayeeMappingRequest.toString()); - - if (StringUtils.isBlank(bcscPayeeMappingRequest.getBcscGuid())) { - throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Missing value in required request field bcscGuid."); - } - if (StringUtils.isBlank(bcscPayeeMappingRequest.getPayeeNumber())) { - throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Missing value in required request field payeeNumber."); - } - - try { - BcscPayeeMapping bcscPayeeMapping = mapRequestToEntity(bcscPayeeMappingRequest); - BcscPayeeMapping newBcscPayeeMapping = bcscPayeeMappingService.add(bcscPayeeMapping); - BcscPayeeMappingResponse bcscPayeeMappingResponse = mapEntityToRepsonse(newBcscPayeeMapping); - return ResponseEntity.ok(bcscPayeeMappingResponse); - } catch(Exception exception) { - HttpStatus status = handleException(exception); - throw new ResponseStatusException(status, exception.getMessage(), exception); - } - } - - @PutMapping("/{id}") - public ResponseEntity updateBcscPayeeMapping(@RequestBody BcscPayeeMappingRequest bcscPayeeMappingRequest, @PathVariable String id) { - logger.info("Updating a BCSC User to Payee Mapping for ID: {}; Updated entity: \n{}", id, bcscPayeeMappingRequest.toString()); - - if (StringUtils.isBlank(bcscPayeeMappingRequest.getPayeeNumber())) { - throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Missing value in required request field payeeNumber"); - } - - try { - BcscPayeeMapping bcscPayeeMapping = mapRequestToEntity(bcscPayeeMappingRequest); - BcscPayeeMapping updatedBcscPayeeMapping = bcscPayeeMappingService.update(bcscPayeeMapping, id); - BcscPayeeMappingResponse bcscPayeeMappingResponse = mapEntityToRepsonse(updatedBcscPayeeMapping); - return ResponseEntity.ok(bcscPayeeMappingResponse); - } catch(Exception exception) { - HttpStatus status = handleException(exception); - throw new ResponseStatusException(status, exception.getMessage(), exception); - } - } - - @GetMapping("/{id}") - public ResponseEntity getBcscPayeeMapping(@PathVariable String id) { - logger.info("Getting a BCSC User to Payee Mapping for ID: {}", id); - - Optional bcscPayeeMappingOptional = bcscPayeeMappingService.find(id); - if (bcscPayeeMappingOptional.isEmpty()) { - throw new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Entity not found for ID %s", id)); - } - - BcscPayeeMapping bcscPayeeMapping = bcscPayeeMappingOptional.get(); - BcscPayeeMappingResponse bcscPayeeMappingResponse = mapEntityToRepsonse(bcscPayeeMapping); - - bcscPayeeMappingResponse.setPayeeIsActive(pbfClinicPayeeService.getPayeeActiveStatus(bcscPayeeMapping.getPayeeNumber())); - - return ResponseEntity.ok(bcscPayeeMappingResponse); - } - - @DeleteMapping("/{id}") - public ResponseEntity deleteBcscPayeeMapping(@PathVariable String id) { - logger.info("Deleting a BCSC User to Payee Mapping for ID: {}", id); - - try { - bcscPayeeMappingService.delete(id); - return ResponseEntity.noContent().build(); - } catch(Exception exception) { - HttpStatus status = handleException(exception); - throw new ResponseStatusException(status, exception.getMessage(), exception); - } - } - - private BcscPayeeMappingResponse mapEntityToRepsonse(BcscPayeeMapping newBcscPayeeMapping) { - BcscPayeeMappingResponse bcscPayeeMappingResponse = new BcscPayeeMappingResponse(); - bcscPayeeMappingResponse.setBcscGuid(newBcscPayeeMapping.getBcscGuid()); - bcscPayeeMappingResponse.setPayeeNumber(newBcscPayeeMapping.getPayeeNumber()); - return bcscPayeeMappingResponse; - } - - private BcscPayeeMapping mapRequestToEntity(BcscPayeeMappingRequest bcscPayeeMappingRequest) { - BcscPayeeMapping bcscPayeeMapping = new BcscPayeeMapping(); - bcscPayeeMapping.setBcscGuid(bcscPayeeMappingRequest.getBcscGuid()); - bcscPayeeMapping.setPayeeNumber(bcscPayeeMappingRequest.getPayeeNumber()); - return bcscPayeeMapping; - } - - private HttpStatus handleException(Exception exception) { - HttpStatus status; - - if (exception instanceof BcscPayeeMappingException) { - BcscPayeeMappingException bpme = (BcscPayeeMappingException)exception; - switch (bpme.getType()) { - case ENTITY_ALREADY_EXISTS: - status = HttpStatus.CONFLICT; - break; - case ENTITY_NOT_FOUND: - status = HttpStatus.NOT_FOUND; - break; - default: - status = HttpStatus.BAD_REQUEST; - } - } else { - status = HttpStatus.BAD_REQUEST; - } - - return status; - } - -} \ No newline at end of file diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/PatientRegistrationController.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/PatientRegistrationController.java index 8438afe7..141881d6 100644 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/PatientRegistrationController.java +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/PatientRegistrationController.java @@ -38,12 +38,12 @@ import ca.bc.gov.hlth.hnweb.persistence.entity.AffectedPartyDirection; import ca.bc.gov.hlth.hnweb.persistence.entity.IdentifierType; import ca.bc.gov.hlth.hnweb.persistence.entity.Transaction; -import ca.bc.gov.hlth.hnweb.persistence.entity.pbf.BcscPayeeMapping; +import ca.bc.gov.hlth.hnweb.persistence.entity.pbf.UserPayeeMapping; import ca.bc.gov.hlth.hnweb.persistence.entity.pbf.PatientRegister; import ca.bc.gov.hlth.hnweb.security.SecurityUtil; import ca.bc.gov.hlth.hnweb.security.TransactionType; import ca.bc.gov.hlth.hnweb.security.UserInfo; -import ca.bc.gov.hlth.hnweb.service.BcscPayeeMappingService; +import ca.bc.gov.hlth.hnweb.service.UserPayeeMappingService; import ca.bc.gov.hlth.hnweb.service.EnrollmentService; import ca.bc.gov.hlth.hnweb.service.PBFClinicPayeeService; import ca.bc.gov.hlth.hnweb.service.PatientRegistrationService; @@ -76,7 +76,7 @@ public class PatientRegistrationController extends BaseController { private PatientRegistrationService patientRegistrationService; @Autowired - private BcscPayeeMappingService bcscPayeeMappingService; + private UserPayeeMappingService userPayeeMappingService; @Autowired private PBFClinicPayeeService pbfClinicPayeeService; @@ -142,19 +142,19 @@ public ResponseEntity getPatientRegistration( } /** - * The Payee number submitted in the request must match the Payee Number mapped to the current user in the BCSC to Payee Number mappings. + * The Payee number submitted in the request must match the Payee Number mapped to the current user in the User to Payee Number mappings. * * @param patientRegistrationRequest * @throws HNWebException */ private void validatePayeeNumberMapping(PatientRegistrationRequest patientRegistrationRequest) { UserInfo userInfo = SecurityUtil.loadUserInfo(); - Optional bcscPayeeMappingOptional = bcscPayeeMappingService.find(userInfo.getUserId()); - if (bcscPayeeMappingOptional.isEmpty()) { + Optional userPayeeMappingOptional = userPayeeMappingService.find(userInfo.getUserId()); + if (userPayeeMappingOptional.isEmpty()) { logger.error("No Payee Number mapping was found for the current user"); throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No Payee Number mapping was found for the current user"); } - String mappedPayeeNumber = bcscPayeeMappingOptional.get().getPayeeNumber(); + String mappedPayeeNumber = userPayeeMappingOptional.get().getPayeeNumber(); String requestPayeeNumber = patientRegistrationRequest.getPayee(); if (!StringUtils.equals(requestPayeeNumber, mappedPayeeNumber)) { logger.error("Payee field value {} does not match the Payee Number mapped to this user", requestPayeeNumber); diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/UserPayeeMappingController.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/UserPayeeMappingController.java new file mode 100644 index 00000000..34ffd05a --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/controller/UserPayeeMappingController.java @@ -0,0 +1,157 @@ +package ca.bc.gov.hlth.hnweb.controller; + +import java.util.Optional; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.server.ResponseStatusException; + +import ca.bc.gov.hlth.hnweb.exception.UserPayeeMappingException; +import ca.bc.gov.hlth.hnweb.model.rest.pbf.UserPayeeMappingRequest; +import ca.bc.gov.hlth.hnweb.model.rest.pbf.UserPayeeMappingResponse; +import ca.bc.gov.hlth.hnweb.persistence.entity.pbf.UserPayeeMapping; +import ca.bc.gov.hlth.hnweb.service.UserPayeeMappingService; +import ca.bc.gov.hlth.hnweb.service.PBFClinicPayeeService; + +/** + * Controller to handle CRUD requests for maintaining Keycloak Users to their PBF MSP Payee Number mappings. + * + */ +@RequestMapping("/payee-mapping") +@RestController +public class UserPayeeMappingController { + + private static final Logger logger = LoggerFactory.getLogger(UserPayeeMappingController.class); + + @Autowired + private UserPayeeMappingService userPayeeMappingService; + + @Autowired + private PBFClinicPayeeService pbfClinicPayeeService; + + /** + * Create a User to MSP Payee Number mapping + * + * @param userPayeeMappingRequest + * @return the response containing the newly created mapping if successful otherwise an error status + */ + @PostMapping("") + public ResponseEntity addUserPayeeMapping(@RequestBody UserPayeeMappingRequest userPayeeMappingRequest) { + logger.info("Adding a new User to Payee Mapping:\n{}", userPayeeMappingRequest.toString()); + + if (StringUtils.isBlank(userPayeeMappingRequest.getUserGuid())) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Missing value in required request field userGuid."); + } + if (StringUtils.isBlank(userPayeeMappingRequest.getPayeeNumber())) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Missing value in required request field payeeNumber."); + } + + try { + UserPayeeMapping userPayeeMapping = mapRequestToEntity(userPayeeMappingRequest); + UserPayeeMapping newUserPayeeMapping = userPayeeMappingService.add(userPayeeMapping); + UserPayeeMappingResponse userPayeeMappingResponse = mapEntityToRepsonse(newUserPayeeMapping); + return ResponseEntity.ok(userPayeeMappingResponse); + } catch(Exception exception) { + HttpStatus status = handleException(exception); + throw new ResponseStatusException(status, exception.getMessage(), exception); + } + } + + @PutMapping("/{id}") + public ResponseEntity updateUserPayeeMapping(@RequestBody UserPayeeMappingRequest userPayeeMappingRequest, @PathVariable String id) { + logger.info("Updating a User to Payee Mapping for ID: {}; Updated entity: \n{}", id, userPayeeMappingRequest.toString()); + + if (StringUtils.isBlank(userPayeeMappingRequest.getPayeeNumber())) { + throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Missing value in required request field payeeNumber"); + } + + try { + UserPayeeMapping userPayeeMapping = mapRequestToEntity(userPayeeMappingRequest); + UserPayeeMapping updatedUserPayeeMapping = userPayeeMappingService.update(userPayeeMapping, id); + UserPayeeMappingResponse userPayeeMappingResponse = mapEntityToRepsonse(updatedUserPayeeMapping); + return ResponseEntity.ok(userPayeeMappingResponse); + } catch(Exception exception) { + HttpStatus status = handleException(exception); + throw new ResponseStatusException(status, exception.getMessage(), exception); + } + } + + @GetMapping("/{id}") + public ResponseEntity getUserPayeeMapping(@PathVariable String id) { + logger.info("Getting a User to Payee Mapping for ID: {}", id); + + Optional userPayeeMappingOptional = userPayeeMappingService.find(id); + if (userPayeeMappingOptional.isEmpty()) { + throw new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Entity not found for ID %s", id)); + } + + UserPayeeMapping userPayeeMapping = userPayeeMappingOptional.get(); + UserPayeeMappingResponse userPayeeMappingResponse = mapEntityToRepsonse(userPayeeMapping); + + userPayeeMappingResponse.setPayeeIsActive(pbfClinicPayeeService.getPayeeActiveStatus(userPayeeMapping.getPayeeNumber())); + + return ResponseEntity.ok(userPayeeMappingResponse); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteUserPayeeMapping(@PathVariable String id) { + logger.info("Deleting a User to Payee Mapping for ID: {}", id); + + try { + userPayeeMappingService.delete(id); + return ResponseEntity.noContent().build(); + } catch(Exception exception) { + HttpStatus status = handleException(exception); + throw new ResponseStatusException(status, exception.getMessage(), exception); + } + } + + private UserPayeeMappingResponse mapEntityToRepsonse(UserPayeeMapping newUserPayeeMapping) { + UserPayeeMappingResponse userPayeeMappingResponse = new UserPayeeMappingResponse(); + userPayeeMappingResponse.setUserGuid(newUserPayeeMapping.getUserGuid()); + userPayeeMappingResponse.setPayeeNumber(newUserPayeeMapping.getPayeeNumber()); + return userPayeeMappingResponse; + } + + private UserPayeeMapping mapRequestToEntity(UserPayeeMappingRequest userPayeeMappingRequest) { + UserPayeeMapping userPayeeMapping = new UserPayeeMapping(); + userPayeeMapping.setUserGuid(userPayeeMappingRequest.getUserGuid()); + userPayeeMapping.setPayeeNumber(userPayeeMappingRequest.getPayeeNumber()); + return userPayeeMapping; + } + + private HttpStatus handleException(Exception exception) { + HttpStatus status; + + if (exception instanceof UserPayeeMappingException) { + UserPayeeMappingException bpme = (UserPayeeMappingException)exception; + switch (bpme.getType()) { + case ENTITY_ALREADY_EXISTS: + status = HttpStatus.CONFLICT; + break; + case ENTITY_NOT_FOUND: + status = HttpStatus.NOT_FOUND; + break; + default: + status = HttpStatus.BAD_REQUEST; + } + } else { + status = HttpStatus.BAD_REQUEST; + } + + return status; + } + +} \ No newline at end of file diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/exception/BcscPayeeMappingException.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/exception/BcscPayeeMappingException.java deleted file mode 100644 index 388fbdd6..00000000 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/exception/BcscPayeeMappingException.java +++ /dev/null @@ -1,28 +0,0 @@ -package ca.bc.gov.hlth.hnweb.exception; - -import ca.bc.gov.hlth.hnweb.persistence.entity.pbf.BcscPayeeMapping; - -/** - * Exception class for errors related to the {@link BcscPayeeMapping} entity. - * - */ -public class BcscPayeeMappingException extends Exception { - - private static final long serialVersionUID = 1L; - - private BcscPayeeMappingExceptionType type; - - public BcscPayeeMappingException(BcscPayeeMappingExceptionType type) { - super(type.getMessage()); - this.type = type; - } - - public BcscPayeeMappingExceptionType getType() { - return type; - } - - public void setType(BcscPayeeMappingExceptionType type) { - this.type = type; - } - -} diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/exception/UserPayeeMappingException.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/exception/UserPayeeMappingException.java new file mode 100644 index 00000000..a1e7850e --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/exception/UserPayeeMappingException.java @@ -0,0 +1,28 @@ +package ca.bc.gov.hlth.hnweb.exception; + +import ca.bc.gov.hlth.hnweb.persistence.entity.pbf.UserPayeeMapping; + +/** + * Exception class for errors related to the {@link UserPayeeMapping} entity. + * + */ +public class UserPayeeMappingException extends Exception { + + private static final long serialVersionUID = 1L; + + private UserPayeeMappingExceptionType type; + + public UserPayeeMappingException(UserPayeeMappingExceptionType type) { + super(type.getMessage()); + this.type = type; + } + + public UserPayeeMappingExceptionType getType() { + return type; + } + + public void setType(UserPayeeMappingExceptionType type) { + this.type = type; + } + +} diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/exception/BcscPayeeMappingExceptionType.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/exception/UserPayeeMappingExceptionType.java similarity index 61% rename from backend/src/main/java/ca/bc/gov/hlth/hnweb/exception/BcscPayeeMappingExceptionType.java rename to backend/src/main/java/ca/bc/gov/hlth/hnweb/exception/UserPayeeMappingExceptionType.java index deaad374..9a4b6d64 100644 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/exception/BcscPayeeMappingExceptionType.java +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/exception/UserPayeeMappingExceptionType.java @@ -1,17 +1,17 @@ package ca.bc.gov.hlth.hnweb.exception; /** - * enum for possible types of {@link BcscPayeeMappingException} + * enum for possible types of {@link UserPayeeMappingException} * */ -public enum BcscPayeeMappingExceptionType { +public enum UserPayeeMappingExceptionType { ENTITY_ALREADY_EXISTS("Entity already exists."), ENTITY_NOT_FOUND("Entity not found."); private final String message; - private BcscPayeeMappingExceptionType(String message) { + private UserPayeeMappingExceptionType(String message) { this.message = message; } diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/pbf/BcscPayeeMappingRequest.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/pbf/BcscPayeeMappingRequest.java deleted file mode 100644 index 52ddc3e8..00000000 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/pbf/BcscPayeeMappingRequest.java +++ /dev/null @@ -1,30 +0,0 @@ -package ca.bc.gov.hlth.hnweb.model.rest.pbf; - -public class BcscPayeeMappingRequest { - - private String bcscGuid; - - private String payeeNumber; - - public String getBcscGuid() { - return bcscGuid; - } - - public void setBcscGuid(String bcscGuid) { - this.bcscGuid = bcscGuid; - } - - public String getPayeeNumber() { - return payeeNumber; - } - - public void setPayeeNumber(String payeeNumber) { - this.payeeNumber = payeeNumber; - } - - @Override - public String toString() { - return "BcscPayeeMapping [bcscGuid=" + bcscGuid + ", payeeNumber=" + payeeNumber + "]"; - } - -} diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/pbf/BcscPayeeMappingResponse.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/pbf/BcscPayeeMappingResponse.java deleted file mode 100644 index 38e92f36..00000000 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/pbf/BcscPayeeMappingResponse.java +++ /dev/null @@ -1,41 +0,0 @@ -package ca.bc.gov.hlth.hnweb.model.rest.pbf; - -public class BcscPayeeMappingResponse { - - private String bcscGuid; - - private String payeeNumber; - - private Boolean payeeIsActive; - - public String getBcscGuid() { - return bcscGuid; - } - - public void setBcscGuid(String bcscGuid) { - this.bcscGuid = bcscGuid; - } - - public String getPayeeNumber() { - return payeeNumber; - } - - public void setPayeeNumber(String payeeNumber) { - this.payeeNumber = payeeNumber; - } - - public Boolean getPayeeIsActive() { - return payeeIsActive; - } - - public void setPayeeIsActive(Boolean payeeIsActive) { - this.payeeIsActive = payeeIsActive; - } - - @Override - public String toString() { - return "BcscPayeeMappingResponse [bcscGuid=" + bcscGuid + ", payeeNumber=" + payeeNumber + ", payeeIsActive=" - + payeeIsActive + "]"; - } - -} diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/pbf/UserPayeeMappingRequest.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/pbf/UserPayeeMappingRequest.java new file mode 100644 index 00000000..446513ba --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/pbf/UserPayeeMappingRequest.java @@ -0,0 +1,30 @@ +package ca.bc.gov.hlth.hnweb.model.rest.pbf; + +public class UserPayeeMappingRequest { + + private String userGuid; + + private String payeeNumber; + + public String getUserGuid() { + return userGuid; + } + + public void setUserGuid(String userGuid) { + this.userGuid = userGuid; + } + + public String getPayeeNumber() { + return payeeNumber; + } + + public void setPayeeNumber(String payeeNumber) { + this.payeeNumber = payeeNumber; + } + + @Override + public String toString() { + return "UserPayeeMappingRequest [userGuid=" + userGuid + ", payeeNumber=" + payeeNumber + "]"; + } + +} \ No newline at end of file diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/pbf/UserPayeeMappingResponse.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/pbf/UserPayeeMappingResponse.java new file mode 100644 index 00000000..7d8ec697 --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/model/rest/pbf/UserPayeeMappingResponse.java @@ -0,0 +1,40 @@ +package ca.bc.gov.hlth.hnweb.model.rest.pbf; + +public class UserPayeeMappingResponse { + + private String userGuid; + + private String payeeNumber; + + private Boolean payeeIsActive; + + public String getUserGuid() { + return userGuid; + } + + public void setUserGuid(String userGuid) { + this.userGuid = userGuid; + } + + public String getPayeeNumber() { + return payeeNumber; + } + + public void setPayeeNumber(String payeeNumber) { + this.payeeNumber = payeeNumber; + } + + public Boolean getPayeeIsActive() { + return payeeIsActive; + } + + public void setPayeeIsActive(Boolean payeeIsActive) { + this.payeeIsActive = payeeIsActive; + } + + @Override + public String toString() { + return "UserPayeeMappingResponse [userGuid=" + userGuid + ", payeeNumber=" + payeeNumber + ", payeeIsActive=" + payeeIsActive + "]"; + } + +} diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/pbf/BcscPayeeMapping.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/pbf/UserPayeeMapping.java similarity index 55% rename from backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/pbf/BcscPayeeMapping.java rename to backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/pbf/UserPayeeMapping.java index 67ddcc50..5cb8418c 100644 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/pbf/BcscPayeeMapping.java +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/entity/pbf/UserPayeeMapping.java @@ -6,26 +6,26 @@ import javax.persistence.Table; /** - * Entity for table bcsc_payee_mapping which contains BCSC Users to MSP Payee Number mappings + * Entity for table user_payee_mapping which contains Keycloak Users to MSP Payee Number mappings * */ @Entity -@Table(name = "bcsc_payee_mapping") -public class BcscPayeeMapping { +@Table(name = "user_payee_mapping") +public class UserPayeeMapping { @Id - @Column(name = "bcsc_guid") - private String bcscGuid; + @Column(name = "user_guid") + private String userGuid; @Column(name = "msp_payee_number", nullable = false) private String payeeNumber; - public String getBcscGuid() { - return bcscGuid; + public String getUserGuid() { + return userGuid; } - public void setBcscGuid(String bcscGuid) { - this.bcscGuid = bcscGuid; + public void setUserGuid(String userGuid) { + this.userGuid = userGuid; } public String getPayeeNumber() { @@ -38,7 +38,9 @@ public void setPayeeNumber(String payeeNumber) { @Override public String toString() { - return "BcscPayeeMapping [bcscGuid=" + bcscGuid + ", payeeNumber=" + payeeNumber + "]"; + return "UserPayeeMapping [userGuid=" + userGuid + ", payeeNumber=" + payeeNumber + "]"; } + + } \ No newline at end of file diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/repository/pbf/BcscPayeeMappingRepository.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/repository/pbf/BcscPayeeMappingRepository.java deleted file mode 100644 index cbd29fec..00000000 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/repository/pbf/BcscPayeeMappingRepository.java +++ /dev/null @@ -1,17 +0,0 @@ -package ca.bc.gov.hlth.hnweb.persistence.repository.pbf; - -import java.util.List; - -import org.springframework.data.jpa.repository.JpaRepository; - -import ca.bc.gov.hlth.hnweb.persistence.entity.pbf.BcscPayeeMapping; - -/** - * Repository for {@link BcscPayeeMapping} - * - */ -public interface BcscPayeeMappingRepository extends JpaRepository { - - public List findByPayeeNumber(String payeeNumber); - -} diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/repository/pbf/UserPayeeMappingRepository.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/repository/pbf/UserPayeeMappingRepository.java new file mode 100644 index 00000000..f8ed7366 --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/persistence/repository/pbf/UserPayeeMappingRepository.java @@ -0,0 +1,17 @@ +package ca.bc.gov.hlth.hnweb.persistence.repository.pbf; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; + +import ca.bc.gov.hlth.hnweb.persistence.entity.pbf.UserPayeeMapping; + +/** + * Repository for {@link UserPayeeMapping} + * + */ +public interface UserPayeeMappingRepository extends JpaRepository { + + public List findByPayeeNumber(String payeeNumber); + +} diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/service/BcscPayeeMappingService.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/service/BcscPayeeMappingService.java deleted file mode 100644 index ba90acc6..00000000 --- a/backend/src/main/java/ca/bc/gov/hlth/hnweb/service/BcscPayeeMappingService.java +++ /dev/null @@ -1,93 +0,0 @@ -package ca.bc.gov.hlth.hnweb.service; - -import java.util.Optional; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import ca.bc.gov.hlth.hnweb.exception.BcscPayeeMappingException; -import ca.bc.gov.hlth.hnweb.exception.BcscPayeeMappingExceptionType; -import ca.bc.gov.hlth.hnweb.persistence.entity.pbf.BcscPayeeMapping; -import ca.bc.gov.hlth.hnweb.persistence.repository.pbf.BcscPayeeMappingRepository; - -/** - * Service for maintaining BCSC Users to MSP Payee Number mappings - */ -@Service -public class BcscPayeeMappingService { - - private static final Logger logger = LoggerFactory.getLogger(BcscPayeeMappingService.class); - - @Autowired - private BcscPayeeMappingRepository bcscPayeeMappingRepository; - - /** - * Adds a mapping. - * - * @param bcscPayeeMapping the mapping information being added - * @return the newly created entity - * @throws BcscPayeeMappingException if the a BcscPayeeMapping entity for the new ID is already present - */ - public BcscPayeeMapping add(BcscPayeeMapping bcscPayeeMapping) throws BcscPayeeMappingException { - Optional optional = bcscPayeeMappingRepository.findById(bcscPayeeMapping.getBcscGuid()); - - if (optional.isPresent()) { - logger.info("BcscPayeeMapping entity already exists with ID {}", bcscPayeeMapping.getBcscGuid()); - throw new BcscPayeeMappingException(BcscPayeeMappingExceptionType.ENTITY_ALREADY_EXISTS); - } - - return bcscPayeeMappingRepository.save(bcscPayeeMapping); - } - - /** - * Updates a mapping. - * - * @param bcscPayeeMapping the new mapping information - * @param id the id of the entity to be updated - * @return the updated BcscPayeeMapping entity - * @throws BcscPayeeMappingException if the BcscPayeeMapping entity does not exist - */ - public BcscPayeeMapping update(BcscPayeeMapping bcscPayeeMapping, String id) throws BcscPayeeMappingException { - Optional optional = bcscPayeeMappingRepository.findById(id); - - if (optional.isEmpty()) { - logger.info("BcscPayeeMapping entity not found for ID {}", id); - throw new BcscPayeeMappingException(BcscPayeeMappingExceptionType.ENTITY_NOT_FOUND); - } - - BcscPayeeMapping existingEntity = optional.get(); - existingEntity.setPayeeNumber(bcscPayeeMapping.getPayeeNumber()); - - return bcscPayeeMappingRepository.save(existingEntity); - } - - /** - * Finds a BcscPayeeMapping for the given id - * @param id the id of the entity to be found. - * @return an Optional with BcscPayeeMapping entity or empty if not found - */ - public Optional find(String id) { - return bcscPayeeMappingRepository.findById(id); - } - - /** - * Deletes the BcscPayeeMapping entity for the give ID - * - * @param id the id of the BcscPayeeMapping entity to be deleted - * @throws BcscPayeeMappingException if the BcscPayeeMapping entity does not exist - */ - public void delete(String id) throws BcscPayeeMappingException { - Optional optional = bcscPayeeMappingRepository.findById(id); - - if (optional.isEmpty()) { - logger.info("BcscPayeeMapping entity not found for ID {}", id); - throw new BcscPayeeMappingException(BcscPayeeMappingExceptionType.ENTITY_NOT_FOUND); - } - - bcscPayeeMappingRepository.deleteById(id); - } - -} - diff --git a/backend/src/main/java/ca/bc/gov/hlth/hnweb/service/UserPayeeMappingService.java b/backend/src/main/java/ca/bc/gov/hlth/hnweb/service/UserPayeeMappingService.java new file mode 100644 index 00000000..49e6c3ee --- /dev/null +++ b/backend/src/main/java/ca/bc/gov/hlth/hnweb/service/UserPayeeMappingService.java @@ -0,0 +1,93 @@ +package ca.bc.gov.hlth.hnweb.service; + +import java.util.Optional; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import ca.bc.gov.hlth.hnweb.exception.UserPayeeMappingException; +import ca.bc.gov.hlth.hnweb.exception.UserPayeeMappingExceptionType; +import ca.bc.gov.hlth.hnweb.persistence.entity.pbf.UserPayeeMapping; +import ca.bc.gov.hlth.hnweb.persistence.repository.pbf.UserPayeeMappingRepository; + +/** + * Service for maintaining Keycloak Users to MSP Payee Number mappings + */ +@Service +public class UserPayeeMappingService { + + private static final Logger logger = LoggerFactory.getLogger(UserPayeeMappingService.class); + + @Autowired + private UserPayeeMappingRepository userPayeeMappingRepository; + + /** + * Adds a mapping. + * + * @param userPayeeMapping the mapping information being added + * @return the newly created entity + * @throws UserPayeeMappingException if the a UserPayeeMapping entity for the new ID is already present + */ + public UserPayeeMapping add(UserPayeeMapping userPayeeMapping) throws UserPayeeMappingException { + Optional optional = userPayeeMappingRepository.findById(userPayeeMapping.getUserGuid()); + + if (optional.isPresent()) { + logger.info("UserPayeeMapping entity already exists with ID {}", userPayeeMapping.getUserGuid()); + throw new UserPayeeMappingException(UserPayeeMappingExceptionType.ENTITY_ALREADY_EXISTS); + } + + return userPayeeMappingRepository.save(userPayeeMapping); + } + + /** + * Updates a mapping. + * + * @param userPayeeMapping the new mapping information + * @param id the id of the entity to be updated + * @return the updated UserPayeeMapping entity + * @throws UserPayeeMappingException if the UserPayeeMapping entity does not exist + */ + public UserPayeeMapping update(UserPayeeMapping userPayeeMapping, String id) throws UserPayeeMappingException { + Optional optional = userPayeeMappingRepository.findById(id); + + if (optional.isEmpty()) { + logger.info("UserPayeeMapping entity not found for ID {}", id); + throw new UserPayeeMappingException(UserPayeeMappingExceptionType.ENTITY_NOT_FOUND); + } + + UserPayeeMapping existingEntity = optional.get(); + existingEntity.setPayeeNumber(userPayeeMapping.getPayeeNumber()); + + return userPayeeMappingRepository.save(existingEntity); + } + + /** + * Finds a UserPayeeMapping for the given id + * @param id the id of the entity to be found. + * @return an Optional with UserPayeeMapping entity or empty if not found + */ + public Optional find(String id) { + return userPayeeMappingRepository.findById(id); + } + + /** + * Deletes the UserPayeeMapping entity for the give ID + * + * @param id the id of the UserPayeeMapping entity to be deleted + * @throws UserPayeeMappingException if the UserPayeeMapping entity does not exist + */ + public void delete(String id) throws UserPayeeMappingException { + Optional optional = userPayeeMappingRepository.findById(id); + + if (optional.isEmpty()) { + logger.info("UserPayeeMapping entity not found for ID {}", id); + throw new UserPayeeMappingException(UserPayeeMappingExceptionType.ENTITY_NOT_FOUND); + } + + userPayeeMappingRepository.deleteById(id); + } + +} + diff --git a/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/BcscPayeeMappingControllerTest.java b/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/BcscPayeeMappingControllerTest.java deleted file mode 100644 index bf1b62c9..00000000 --- a/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/BcscPayeeMappingControllerTest.java +++ /dev/null @@ -1,234 +0,0 @@ -package ca.bc.gov.hlth.hnweb.controller; - -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.UUID; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.server.ResponseStatusException; - -import ca.bc.gov.hlth.hnweb.model.rest.pbf.BcscPayeeMappingRequest; -import ca.bc.gov.hlth.hnweb.model.rest.pbf.BcscPayeeMappingResponse; - -/** - * Tests for {@link BcscPayeeMappingController} - * - */ -@SpringBootTest -@Transactional -@Sql({ "classpath:scripts/bcsc_payee_mapping.sql", "classpath:scripts/pbf_clinic_payee.sql" }) -public class BcscPayeeMappingControllerTest { - - @Autowired - private BcscPayeeMappingController bcscPayeeMappingController; - - @Test - public void testAddBcscPayeeMapping_success() { - - String bcscGuid = UUID.randomUUID().toString(); - String payeeNumber = "00063"; - - BcscPayeeMappingRequest bcscPayeeMappingRequest = createBcscPayeeMappingRequest(bcscGuid, payeeNumber); - - ResponseEntity response = bcscPayeeMappingController.addBcscPayeeMapping(bcscPayeeMappingRequest); - assertEquals(HttpStatus.OK, response.getStatusCode()); - BcscPayeeMappingResponse bcscPayeeMappingResponse = response.getBody(); - assertNotNull(bcscPayeeMappingResponse); - assertEquals(bcscGuid, bcscPayeeMappingResponse.getBcscGuid()); - assertEquals(payeeNumber, bcscPayeeMappingResponse.getPayeeNumber()); - } - - @Test - public void testAddBcscPayeeMapping_fail_missing_bcsc_guid() { - - String bcscGuid = null; - String payeeNumber = "00063"; - - BcscPayeeMappingRequest bcscPayeeMappingRequest = createBcscPayeeMappingRequest(bcscGuid, payeeNumber); - - assertThatExceptionOfType(ResponseStatusException.class) - .isThrownBy(() -> bcscPayeeMappingController.addBcscPayeeMapping(bcscPayeeMappingRequest)) - .withMessage("400 BAD_REQUEST \"Missing value in required request field bcscGuid.\""); - } - - @Test - public void testAddBcscPayeeMapping_fail_missing_bcsc_guid_empty_value() { - - String bcscGuid = " "; //Should fail for anything except a populated String - String payeeNumber = "00063"; - - BcscPayeeMappingRequest bcscPayeeMappingRequest = createBcscPayeeMappingRequest(bcscGuid, payeeNumber); - - assertThatExceptionOfType(ResponseStatusException.class) - .isThrownBy(() -> bcscPayeeMappingController.addBcscPayeeMapping(bcscPayeeMappingRequest)) - .withMessage("400 BAD_REQUEST \"Missing value in required request field bcscGuid.\""); - } - - @Test - public void testAddBcscPayeeMapping_fail_missing_payee_number() { - - String bcscGuid = UUID.randomUUID().toString(); - String payeeNumber = " "; //Should fail for anything except a populated String - - BcscPayeeMappingRequest bcscPayeeMappingRequest = createBcscPayeeMappingRequest(bcscGuid, payeeNumber); - - assertThatExceptionOfType(ResponseStatusException.class) - .isThrownBy(() -> bcscPayeeMappingController.addBcscPayeeMapping(bcscPayeeMappingRequest)) - .withMessage("400 BAD_REQUEST \"Missing value in required request field payeeNumber.\""); - } - - @Test - public void testAddBcscPayeeMapping_fail_bcsc_already_exists() { - - String bcscGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20"; - String payeeNumber = "00063"; - - BcscPayeeMappingRequest bcscPayeeMappingRequest = createBcscPayeeMappingRequest(bcscGuid, payeeNumber); - - assertThatExceptionOfType(ResponseStatusException.class) - .isThrownBy(() -> bcscPayeeMappingController.addBcscPayeeMapping(bcscPayeeMappingRequest)) - .withMessage("409 CONFLICT \"Entity already exists.\"; nested exception is ca.bc.gov.hlth.hnweb.exception.BcscPayeeMappingException: Entity already exists."); - } - - @Test - public void testGetBcscPayeeMapping_success() { - - String bcscGuid = "14100f9b-7daa-4938-a833-c8c56a5988e9"; - final String payeeNumber = "00023"; - - ResponseEntity response = bcscPayeeMappingController.getBcscPayeeMapping(bcscGuid); - assertEquals(HttpStatus.OK, response.getStatusCode()); - BcscPayeeMappingResponse bcscPayeeMappingResponse = response.getBody(); - assertNotNull(bcscPayeeMappingResponse); - assertEquals(bcscGuid, bcscPayeeMappingResponse.getBcscGuid()); - assertEquals(payeeNumber, bcscPayeeMappingResponse.getPayeeNumber()); - assertTrue(bcscPayeeMappingResponse.getPayeeIsActive()); - } - - @Test - public void testGetBcscPayeeMapping_success_archived_payee() { - - String bcscGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20"; - final String payeeNumber = "00053"; - - ResponseEntity response = bcscPayeeMappingController.getBcscPayeeMapping(bcscGuid); - assertEquals(HttpStatus.OK, response.getStatusCode()); - BcscPayeeMappingResponse bcscPayeeMappingResponse = response.getBody(); - assertNotNull(bcscPayeeMappingResponse); - assertEquals(bcscGuid, bcscPayeeMappingResponse.getBcscGuid()); - assertEquals(payeeNumber, bcscPayeeMappingResponse.getPayeeNumber()); - assertEquals(false, bcscPayeeMappingResponse.getPayeeIsActive()); - } - - @Test - public void testGetBcscPayeeMapping_success_no_payee_status() { - - String bcscGuid = "f33c9e07-6f49-46c2-90c2-6e0013729c9d"; - final String payeeNumber = "X0054"; - - ResponseEntity response = bcscPayeeMappingController.getBcscPayeeMapping(bcscGuid); - assertEquals(HttpStatus.OK, response.getStatusCode()); - BcscPayeeMappingResponse bcscPayeeMappingResponse = response.getBody(); - assertNotNull(bcscPayeeMappingResponse); - assertEquals(bcscGuid, bcscPayeeMappingResponse.getBcscGuid()); - assertEquals(payeeNumber, bcscPayeeMappingResponse.getPayeeNumber()); - assertEquals(false, bcscPayeeMappingResponse.getPayeeIsActive()); - } - - @Test - public void testGetBcscPayeeMapping_fail_not_found() { - - String bcscGuid = UUID.randomUUID().toString(); - - assertThatExceptionOfType(ResponseStatusException.class) - .isThrownBy(() -> bcscPayeeMappingController.getBcscPayeeMapping(bcscGuid)) - .withMessage("404 NOT_FOUND \"Entity not found for ID %s\"", bcscGuid); - } - - @Test - public void testUpdateBcscPayeeMapping_success() { - - String bcscGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20"; - String updatedPayeeNumber = "00023"; - - BcscPayeeMappingRequest bcscPayeeMappingRequest = createBcscPayeeMappingRequest(bcscGuid, updatedPayeeNumber); - - ResponseEntity response = bcscPayeeMappingController.updateBcscPayeeMapping(bcscPayeeMappingRequest, bcscGuid); - assertEquals(HttpStatus.OK, response.getStatusCode()); - BcscPayeeMappingResponse updatedBcscPayeeMappingResponse = response.getBody(); - assertNotNull(updatedBcscPayeeMappingResponse); - assertEquals(bcscGuid, updatedBcscPayeeMappingResponse.getBcscGuid()); - assertEquals(updatedPayeeNumber, updatedBcscPayeeMappingResponse.getPayeeNumber()); - } - - @Test - public void testUpdateBcscPayeeMapping_fail_does_not_exist() { - - String bcscGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20"; - String updatedPayeeNumber = "00023"; - - BcscPayeeMappingRequest bcscPayeeMappingRequest = createBcscPayeeMappingRequest(bcscGuid, updatedPayeeNumber); - - String incorrectBcscGuid = UUID.randomUUID().toString(); - - assertThatExceptionOfType(ResponseStatusException.class) - .isThrownBy(() -> bcscPayeeMappingController.updateBcscPayeeMapping(bcscPayeeMappingRequest, incorrectBcscGuid)) - .withMessage("404 NOT_FOUND \"Entity not found.\"; nested exception is ca.bc.gov.hlth.hnweb.exception.BcscPayeeMappingException: Entity not found."); - } - - @Test - public void testUpdateBcscPayeeMapping_fail_missing_payee_number() { - - String bcscGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20"; - String updatedPayeeNumber = " "; - - BcscPayeeMappingRequest bcscPayeeMappingRequest = createBcscPayeeMappingRequest(bcscGuid, updatedPayeeNumber); - - assertThatExceptionOfType(ResponseStatusException.class) - .isThrownBy(() -> bcscPayeeMappingController.updateBcscPayeeMapping(bcscPayeeMappingRequest, bcscGuid)) - .withMessage("400 BAD_REQUEST \"Missing value in required request field payeeNumber\""); - } - - @Test - public void testDeleteBcscPayeeMapping_success() { - - String bcscGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20"; - - ResponseEntity deleteRresponse = bcscPayeeMappingController.deleteBcscPayeeMapping(bcscGuid); - assertEquals(HttpStatus.NO_CONTENT, deleteRresponse.getStatusCode()); - assertEquals(deleteRresponse.getBody(), null); - - assertThatExceptionOfType(ResponseStatusException.class) - .isThrownBy(() -> bcscPayeeMappingController.getBcscPayeeMapping(bcscGuid)) - .withMessage("404 NOT_FOUND \"Entity not found for ID %s\"", bcscGuid); - } - - @Test - public void testDeleteBcscPayeeMapping_fail_not_found() { - - String bcscGuid = UUID.randomUUID().toString(); - - assertThatExceptionOfType(ResponseStatusException.class) - .isThrownBy(() -> bcscPayeeMappingController.deleteBcscPayeeMapping(bcscGuid)) - .withMessage("404 NOT_FOUND \"Entity not found.\"; nested exception is ca.bc.gov.hlth.hnweb.exception.BcscPayeeMappingException: Entity not found."); - } - - private BcscPayeeMappingRequest createBcscPayeeMappingRequest(String bcscGuid, String payeeNumber) { - BcscPayeeMappingRequest bcscPayeeMappingRequest = new BcscPayeeMappingRequest(); - bcscPayeeMappingRequest.setBcscGuid(bcscGuid); - bcscPayeeMappingRequest.setPayeeNumber(payeeNumber); - return bcscPayeeMappingRequest; - } - -} - - diff --git a/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/PatientRegistrationControllerTest.java b/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/PatientRegistrationControllerTest.java index f5638c44..491b2c23 100644 --- a/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/PatientRegistrationControllerTest.java +++ b/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/PatientRegistrationControllerTest.java @@ -41,7 +41,7 @@ * JUnit test class for PatientRegistrationController * */ -@Sql({ "classpath:scripts/bcsc_payee_mapping.sql" }) +@Sql({ "classpath:scripts/user_payee_mapping.sql" }) public class PatientRegistrationControllerTest extends BaseControllerTest { @Autowired diff --git a/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/UserPayeeMappingControllerTest.java b/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/UserPayeeMappingControllerTest.java new file mode 100644 index 00000000..8cee03b1 --- /dev/null +++ b/backend/src/test/java/ca/bc/gov/hlth/hnweb/controller/UserPayeeMappingControllerTest.java @@ -0,0 +1,234 @@ +package ca.bc.gov.hlth.hnweb.controller; + +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.UUID; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.server.ResponseStatusException; + +import ca.bc.gov.hlth.hnweb.model.rest.pbf.UserPayeeMappingRequest; +import ca.bc.gov.hlth.hnweb.model.rest.pbf.UserPayeeMappingResponse; + +/** + * Tests for {@link UserPayeeMappingController} + * + */ +@SpringBootTest +@Transactional +@Sql({ "classpath:scripts/user_payee_mapping.sql", "classpath:scripts/pbf_clinic_payee.sql" }) +public class UserPayeeMappingControllerTest { + + @Autowired + private UserPayeeMappingController userPayeeMappingController; + + @Test + public void testAddUserPayeeMapping_success() { + + String userGuid = UUID.randomUUID().toString(); + String payeeNumber = "00063"; + + UserPayeeMappingRequest userPayeeMappingRequest = createUserPayeeMappingRequest(userGuid, payeeNumber); + + ResponseEntity response = userPayeeMappingController.addUserPayeeMapping(userPayeeMappingRequest); + assertEquals(HttpStatus.OK, response.getStatusCode()); + UserPayeeMappingResponse userPayeeMappingResponse = response.getBody(); + assertNotNull(userPayeeMappingResponse); + assertEquals(userGuid, userPayeeMappingResponse.getUserGuid()); + assertEquals(payeeNumber, userPayeeMappingResponse.getPayeeNumber()); + } + + @Test + public void testAddUserPayeeMapping_fail_missing_user_guid() { + + String userGuid = null; + String payeeNumber = "00063"; + + UserPayeeMappingRequest userPayeeMappingRequest = createUserPayeeMappingRequest(userGuid, payeeNumber); + + assertThatExceptionOfType(ResponseStatusException.class) + .isThrownBy(() -> userPayeeMappingController.addUserPayeeMapping(userPayeeMappingRequest)) + .withMessage("400 BAD_REQUEST \"Missing value in required request field userGuid.\""); + } + + @Test + public void testAddUserPayeeMapping_fail_missing_user_guid_empty_value() { + + String userGuid = " "; //Should fail for anything except a populated String + String payeeNumber = "00063"; + + UserPayeeMappingRequest userPayeeMappingRequest = createUserPayeeMappingRequest(userGuid, payeeNumber); + + assertThatExceptionOfType(ResponseStatusException.class) + .isThrownBy(() -> userPayeeMappingController.addUserPayeeMapping(userPayeeMappingRequest)) + .withMessage("400 BAD_REQUEST \"Missing value in required request field userGuid.\""); + } + + @Test + public void testAddUserPayeeMapping_fail_missing_payee_number() { + + String userGuid = UUID.randomUUID().toString(); + String payeeNumber = " "; //Should fail for anything except a populated String + + UserPayeeMappingRequest userPayeeMappingRequest = createUserPayeeMappingRequest(userGuid, payeeNumber); + + assertThatExceptionOfType(ResponseStatusException.class) + .isThrownBy(() -> userPayeeMappingController.addUserPayeeMapping(userPayeeMappingRequest)) + .withMessage("400 BAD_REQUEST \"Missing value in required request field payeeNumber.\""); + } + + @Test + public void testAddUserPayeeMapping_fail_user_already_exists() { + + String userGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20"; + String payeeNumber = "00063"; + + UserPayeeMappingRequest userPayeeMappingRequest = createUserPayeeMappingRequest(userGuid, payeeNumber); + + assertThatExceptionOfType(ResponseStatusException.class) + .isThrownBy(() -> userPayeeMappingController.addUserPayeeMapping(userPayeeMappingRequest)) + .withMessage("409 CONFLICT \"Entity already exists.\"; nested exception is ca.bc.gov.hlth.hnweb.exception.UserPayeeMappingException: Entity already exists."); + } + + @Test + public void testGetUserPayeeMapping_success() { + + String userGuid = "14100f9b-7daa-4938-a833-c8c56a5988e9"; + final String payeeNumber = "00023"; + + ResponseEntity response = userPayeeMappingController.getUserPayeeMapping(userGuid); + assertEquals(HttpStatus.OK, response.getStatusCode()); + UserPayeeMappingResponse userPayeeMappingResponse = response.getBody(); + assertNotNull(userPayeeMappingResponse); + assertEquals(userGuid, userPayeeMappingResponse.getUserGuid()); + assertEquals(payeeNumber, userPayeeMappingResponse.getPayeeNumber()); + assertTrue(userPayeeMappingResponse.getPayeeIsActive()); + } + + @Test + public void testGetUserPayeeMapping_success_archived_payee() { + + String userGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20"; + final String payeeNumber = "00053"; + + ResponseEntity response = userPayeeMappingController.getUserPayeeMapping(userGuid); + assertEquals(HttpStatus.OK, response.getStatusCode()); + UserPayeeMappingResponse userPayeeMappingResponse = response.getBody(); + assertNotNull(userPayeeMappingResponse); + assertEquals(userGuid, userPayeeMappingResponse.getUserGuid()); + assertEquals(payeeNumber, userPayeeMappingResponse.getPayeeNumber()); + assertEquals(false, userPayeeMappingResponse.getPayeeIsActive()); + } + + @Test + public void testGetUserPayeeMapping_success_no_payee_status() { + + String userGuid = "f33c9e07-6f49-46c2-90c2-6e0013729c9d"; + final String payeeNumber = "X0054"; + + ResponseEntity response = userPayeeMappingController.getUserPayeeMapping(userGuid); + assertEquals(HttpStatus.OK, response.getStatusCode()); + UserPayeeMappingResponse userPayeeMappingResponse = response.getBody(); + assertNotNull(userPayeeMappingResponse); + assertEquals(userGuid, userPayeeMappingResponse.getUserGuid()); + assertEquals(payeeNumber, userPayeeMappingResponse.getPayeeNumber()); + assertEquals(false, userPayeeMappingResponse.getPayeeIsActive()); + } + + @Test + public void testGetUserPayeeMapping_fail_not_found() { + + String userGuid = UUID.randomUUID().toString(); + + assertThatExceptionOfType(ResponseStatusException.class) + .isThrownBy(() -> userPayeeMappingController.getUserPayeeMapping(userGuid)) + .withMessage("404 NOT_FOUND \"Entity not found for ID %s\"", userGuid); + } + + @Test + public void testUpdateUserPayeeMapping_success() { + + String userGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20"; + String updatedPayeeNumber = "00023"; + + UserPayeeMappingRequest userPayeeMappingRequest = createUserPayeeMappingRequest(userGuid, updatedPayeeNumber); + + ResponseEntity response = userPayeeMappingController.updateUserPayeeMapping(userPayeeMappingRequest, userGuid); + assertEquals(HttpStatus.OK, response.getStatusCode()); + UserPayeeMappingResponse updatedUserPayeeMappingResponse = response.getBody(); + assertNotNull(updatedUserPayeeMappingResponse); + assertEquals(userGuid, updatedUserPayeeMappingResponse.getUserGuid()); + assertEquals(updatedPayeeNumber, updatedUserPayeeMappingResponse.getPayeeNumber()); + } + + @Test + public void testUpdateUserPayeeMapping_fail_does_not_exist() { + + String userGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20"; + String updatedPayeeNumber = "00023"; + + UserPayeeMappingRequest userPayeeMappingRequest = createUserPayeeMappingRequest(userGuid, updatedPayeeNumber); + + String incorrectUserGuid = UUID.randomUUID().toString(); + + assertThatExceptionOfType(ResponseStatusException.class) + .isThrownBy(() -> userPayeeMappingController.updateUserPayeeMapping(userPayeeMappingRequest, incorrectUserGuid)) + .withMessage("404 NOT_FOUND \"Entity not found.\"; nested exception is ca.bc.gov.hlth.hnweb.exception.UserPayeeMappingException: Entity not found."); + } + + @Test + public void testUpdateUserPayeeMapping_fail_missing_payee_number() { + + String userGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20"; + String updatedPayeeNumber = " "; + + UserPayeeMappingRequest userPayeeMappingRequest = createUserPayeeMappingRequest(userGuid, updatedPayeeNumber); + + assertThatExceptionOfType(ResponseStatusException.class) + .isThrownBy(() -> userPayeeMappingController.updateUserPayeeMapping(userPayeeMappingRequest, userGuid)) + .withMessage("400 BAD_REQUEST \"Missing value in required request field payeeNumber\""); + } + + @Test + public void testDeleteUserPayeeMapping_success() { + + String userGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20"; + + ResponseEntity deleteRresponse = userPayeeMappingController.deleteUserPayeeMapping(userGuid); + assertEquals(HttpStatus.NO_CONTENT, deleteRresponse.getStatusCode()); + assertEquals(deleteRresponse.getBody(), null); + + assertThatExceptionOfType(ResponseStatusException.class) + .isThrownBy(() -> userPayeeMappingController.getUserPayeeMapping(userGuid)) + .withMessage("404 NOT_FOUND \"Entity not found for ID %s\"", userGuid); + } + + @Test + public void testDeleteUserPayeeMapping_fail_not_found() { + + String userGuid = UUID.randomUUID().toString(); + + assertThatExceptionOfType(ResponseStatusException.class) + .isThrownBy(() -> userPayeeMappingController.deleteUserPayeeMapping(userGuid)) + .withMessage("404 NOT_FOUND \"Entity not found.\"; nested exception is ca.bc.gov.hlth.hnweb.exception.UserPayeeMappingException: Entity not found."); + } + + private UserPayeeMappingRequest createUserPayeeMappingRequest(String userGuid, String payeeNumber) { + UserPayeeMappingRequest userPayeeMappingRequest = new UserPayeeMappingRequest(); + userPayeeMappingRequest.setUserGuid(userGuid); + userPayeeMappingRequest.setPayeeNumber(payeeNumber); + return userPayeeMappingRequest; + } + +} + + diff --git a/backend/src/test/java/ca/bc/gov/hlth/hnweb/service/PBFClinicPayeeServiceTest.java b/backend/src/test/java/ca/bc/gov/hlth/hnweb/service/PBFClinicPayeeServiceTest.java index 7f329356..0e33d75f 100644 --- a/backend/src/test/java/ca/bc/gov/hlth/hnweb/service/PBFClinicPayeeServiceTest.java +++ b/backend/src/test/java/ca/bc/gov/hlth/hnweb/service/PBFClinicPayeeServiceTest.java @@ -11,7 +11,7 @@ @SpringBootTest @Transactional -@Sql({ "classpath:scripts/bcsc_payee_mapping.sql", "classpath:scripts/pbf_clinic_payee.sql" }) +@Sql({ "classpath:scripts/user_payee_mapping.sql", "classpath:scripts/pbf_clinic_payee.sql" }) public class PBFClinicPayeeServiceTest { @Autowired diff --git a/backend/src/test/resources/scripts/bcsc_payee_mapping.sql b/backend/src/test/resources/scripts/user_payee_mapping.sql similarity index 80% rename from backend/src/test/resources/scripts/bcsc_payee_mapping.sql rename to backend/src/test/resources/scripts/user_payee_mapping.sql index 0f90c208..fbe03c54 100644 --- a/backend/src/test/resources/scripts/bcsc_payee_mapping.sql +++ b/backend/src/test/resources/scripts/user_payee_mapping.sql @@ -1,5 +1,5 @@ --- Test data for BCSC to Payee Number Mappings -insert into mspdirect.bcsc_payee_mapping values +-- Test data for User to Payee Number Mappings +insert into mspdirect.user_payee_mapping values ('a9c3b536-4598-411a-bda2-4068d6b5cc20', '00053'), ('14100f9b-7daa-4938-a833-c8c56a5988e9', '00023'), ('f0945b9c-4c92-471a-a03e-e9ce62401c6d', '00033'), diff --git a/frontend/src/services/BaseService.js b/frontend/src/services/BaseService.js index d83cd3a6..2a09f766 100644 --- a/frontend/src/services/BaseService.js +++ b/frontend/src/services/BaseService.js @@ -18,8 +18,8 @@ export const resources = { patientRegistration: { getPatientRegistration: '/patient-registration/get-patient-registration', }, - bcscPayeeMappings: { - getBcscPayeeMapping: '/payee-mapping', + userPayeeMapping: { + getUserPayeeMapping: '/payee-mapping', }, groupMember: { addGroupMember: '/group-member/add-group-member', diff --git a/frontend/src/services/PatientRegistrationService.js b/frontend/src/services/PatientRegistrationService.js index ef521a56..0b48fdc4 100644 --- a/frontend/src/services/PatientRegistrationService.js +++ b/frontend/src/services/PatientRegistrationService.js @@ -4,8 +4,8 @@ export default { getPatientRegistration(request) { return apiRequest().then((axiosInstance) => axiosInstance.post(resources.patientRegistration.getPatientRegistration, request)) }, - getBcscPayeeMapping(bcscUserId) { - const url = `${resources.bcscPayeeMappings.getBcscPayeeMapping}/${bcscUserId}`; + getUserPayeeMapping(userId) { + const url = `${resources.userPayeeMapping.getUserPayeeMapping}/${userId}` return apiRequest().then((axiosInstance) => axiosInstance.get(url)) }, } diff --git a/frontend/src/views/patientregistration/ViewPatientRegistration.vue b/frontend/src/views/patientregistration/ViewPatientRegistration.vue index 574ccdf2..63545f40 100644 --- a/frontend/src/views/patientregistration/ViewPatientRegistration.vue +++ b/frontend/src/views/patientregistration/ViewPatientRegistration.vue @@ -132,13 +132,13 @@ export default { try { this.alertStore.dismissAlert() const userId = this.$keycloak.tokenParsed?.sub - const bcscPayeeMapping = (await PatientRegistrationService.getBcscPayeeMapping(userId)).data + const userPayeeMapping = (await PatientRegistrationService.getUserPayeeMapping(userId)).data /* If a Payee mapping was found the status will be checked. If there is no active status for a Payee then an error message should be displayed and the field disabled */ - this.payee = bcscPayeeMapping.payeeNumber - if (!bcscPayeeMapping.payeeIsActive) { + this.payee = userPayeeMapping.payeeNumber + if (!userPayeeMapping.payeeIsActive) { this.payeeInactive = true - this.alertStore.setErrorAlert(`Payee ${bcscPayeeMapping.payeeNumber} is not an active PBF clinic.  Please email ${config.VITE_PBF_SUPPORT_CONTACT_NO || import.meta.env.VITE_PBF_SUPPORT_CONTACT_NO} if this is incorrect`) + this.alertStore.setErrorAlert(`Payee ${userPayeeMapping.payeeNumber} is not an active PBF clinic.  Please email ${config.VITE_PBF_SUPPORT_CONTACT_NO || import.meta.env.VITE_PBF_SUPPORT_CONTACT_NO} if this is incorrect`) } } catch (err) { //Check for Not Found error and add a user friendly error message