Skip to content

Commit

Permalink
9067 pbf disable search for inactive payees (#181)
Browse files Browse the repository at this point in the history
* 9067: Added the Payee Status to the mapping response

* 9067: Updated validation to make cancel date still active

* 9067: Updated test for payee mappings

* 9067: Added validation for non active payee

* 9067: Updated to return first active payee record

* 9067: Updated to check if payee is active

* 9067: Renamed method

* 9067: Updates from code review

* 9067: Added parameter for contact number

* 9067: Updated message
  • Loading branch information
daveb-hni authored Mar 7, 2023
1 parent 52d9cd0 commit 3069fbb
Show file tree
Hide file tree
Showing 13 changed files with 264 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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.
Expand All @@ -36,6 +37,9 @@ public class BcscPayeeMappingController {

@Autowired
private BcscPayeeMappingService bcscPayeeMappingService;

@Autowired
private PBFClinicPayeeService pbfClinicPayeeService;

/**
* Create a BCSC User to MSP Payee Number mapping
Expand Down Expand Up @@ -93,7 +97,11 @@ public ResponseEntity<BcscPayeeMappingResponse> getBcscPayeeMapping(@PathVariabl
throw new ResponseStatusException(HttpStatus.NOT_FOUND, String.format("Entity not found for ID %s", id));
}

BcscPayeeMappingResponse bcscPayeeMappingResponse = mapEntityToRepsonse(bcscPayeeMappingOptional.get());
BcscPayeeMapping bcscPayeeMapping = bcscPayeeMappingOptional.get();
BcscPayeeMappingResponse bcscPayeeMappingResponse = mapEntityToRepsonse(bcscPayeeMapping);

bcscPayeeMappingResponse.setPayeeIsActive(pbfClinicPayeeService.getPayeeActiveStatus(bcscPayeeMapping.getPayeeNumber()));

return ResponseEntity.ok(bcscPayeeMappingResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import ca.bc.gov.hlth.hnweb.security.UserInfo;
import ca.bc.gov.hlth.hnweb.service.BcscPayeeMappingService;
import ca.bc.gov.hlth.hnweb.service.EnrollmentService;
import ca.bc.gov.hlth.hnweb.service.PBFClinicPayeeService;
import ca.bc.gov.hlth.hnweb.service.PatientRegistrationService;

/**
Expand Down Expand Up @@ -77,7 +78,10 @@ public class PatientRegistrationController extends BaseController {
@Autowired
private BcscPayeeMappingService bcscPayeeMappingService;

@PostMapping("/get-patient-registration")
@Autowired
private PBFClinicPayeeService pbfClinicPayeeService;

@PostMapping("/get-patient-registration")
public ResponseEntity<PatientRegistrationResponse> getPatientRegistration(
@Valid @RequestBody PatientRegistrationRequest patientRegistrationRequest, HttpServletRequest request) {

Expand Down Expand Up @@ -150,10 +154,17 @@ private void validatePayeeNumberMapping(PatientRegistrationRequest patientRegist
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");
}
if (!StringUtils.equals(patientRegistrationRequest.getPayee(), bcscPayeeMappingOptional.get().getPayeeNumber())) {
logger.error("Payee field value {} does not match the Payee Number mapped to this user", patientRegistrationRequest.getPayee());
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Payee field value %s does not match the Payee Number mapped to this user", patientRegistrationRequest.getPayee()));
String mappedPayeeNumber = bcscPayeeMappingOptional.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);
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Payee field value %s does not match the Payee Number mapped to this user", requestPayeeNumber));
}
boolean isActive = pbfClinicPayeeService.getPayeeActiveStatus(mappedPayeeNumber);
if (!isActive) {
logger.error("Payee {} is not active", requestPayeeNumber);
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Payee %s is not active", requestPayeeNumber));
}
}

private PatientRegistrationResponse handlePatientRegistrationResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public class BcscPayeeMappingResponse {
private String bcscGuid;

private String payeeNumber;

private Boolean payeeIsActive;

public String getBcscGuid() {
return bcscGuid;
Expand All @@ -22,9 +24,18 @@ public void setPayeeNumber(String payeeNumber) {
this.payeeNumber = payeeNumber;
}

@Override
public String toString() {
return "BcscPayeeMapping [bcscGuid=" + bcscGuid + ", 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 + "]";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,10 @@ public void setArchived(Boolean archived) {
this.archived = archived;
}

@Override
public String toString() {
return "PBFClinicPayee [pbfClinicPayeeId=" + pbfClinicPayeeId + ", payeeNumber=" + payeeNumber
+ ", effectiveDate=" + effectiveDate + ", cancelDate=" + cancelDate + ", reportGroup=" + reportGroup
+ ", archived=" + archived + "]";
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package ca.bc.gov.hlth.hnweb.persistence.repository.pbf;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import ca.bc.gov.hlth.hnweb.persistence.entity.pbf.PBFClinicPayee;

public interface PBFClinicPayeeRepository extends JpaRepository<PBFClinicPayee, Long> {

/**
* Counts the number of active records for a payee
*
* @param payeeNumber
* @return the number of active records for a payee
*/
@Query("select count(pcp) from PBFClinicPayee pcp"
+ " where pcp.payeeNumber = :payeeNumber"
+ " and pcp.archived = false"
+ " and pcp.effectiveDate <= CURRENT_DATE"
+ " and (pcp.cancelDate IS NULL OR pcp.cancelDate >= CURRENT_DATE)")
public long countActivePayeeEntries(String payeeNumber);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package ca.bc.gov.hlth.hnweb.service;

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.persistence.repository.pbf.PBFClinicPayeeRepository;

/**
* Service for processing PBF clinic payee requests
*
*/
@Service
public class PBFClinicPayeeService extends BaseService {

private static final Logger logger = LoggerFactory.getLogger(PBFClinicPayeeService.class);

@Autowired
private PBFClinicPayeeRepository pbfClinicPayeeRepository;

/**
* Determines the status of the payee by checking if an active record exists in PBFClinicPayee table
*
* @param payeeNumber
* @return returns true if an active record is found otherwise returns false
*/
public boolean getPayeeActiveStatus(String payeeNumber) {
long activeCount = pbfClinicPayeeRepository.countActivePayeeEntries(payeeNumber);

if (activeCount > 1) {
logger.warn("{} active records found for Payee {}.", activeCount, payeeNumber);
}

return activeCount > 0;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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;
Expand All @@ -24,7 +25,7 @@
*/
@SpringBootTest
@Transactional
@Sql({ "classpath:scripts/bcsc_payee_mapping.sql" })
@Sql({ "classpath:scripts/bcsc_payee_mapping.sql", "classpath:scripts/pbf_clinic_payee.sql" })
public class BcscPayeeMappingControllerTest {

@Autowired
Expand Down Expand Up @@ -98,20 +99,51 @@ public void testAddBcscPayeeMapping_fail_bcsc_already_exists() {
.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<BcscPayeeMappingResponse> 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() {
public void testGetBcscPayeeMapping_success_archived_payee() {

String bcscGuid = "a9c3b536-4598-411a-bda2-4068d6b5cc20";
String payeeNumber = "00053";
final String payeeNumber = "00053";

ResponseEntity<BcscPayeeMappingResponse> response = bcscPayeeMappingController.getBcscPayeeMapping(bcscGuid);
assertEquals(HttpStatus.OK, response.getStatusCode());
BcscPayeeMappingResponse bcscPayeeMappingResponse = response.getBody();
assertNotNull(bcscPayeeMappingResponse);
assertEquals(bcscGuid, bcscPayeeMappingResponse.getBcscGuid());
assertEquals(payeeNumber, bcscPayeeMappingResponse.getPayeeNumber());
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<BcscPayeeMappingResponse> 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() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.springframework.http.HttpHeaders.CONTENT_TYPE;

Expand Down Expand Up @@ -287,6 +286,25 @@ public void testRegistrationHistory_failure_incorrect_payee_mapping_found() thro
.withMessage("400 BAD_REQUEST \"400 BAD_REQUEST \"Payee field value T0053 does not match the Payee Number mapped to this user\"\"; nested exception is org.springframework.web.server.ResponseStatusException: 400 BAD_REQUEST \"Payee field value T0053 does not match the Payee Number mapped to this user\"");
}

@Test
public void testRegistrationHistory_failure_inactive_cancelled() throws Exception {
createPBFClinicPayee();
createPatientRegister();

//Note, don't enqueue a response as it is never requested and so will remain queued for next test when they are run together.

//Override the base setup of the user to ensure we return the User with the User ID mapped to the this Payee Number
mockStatic.when(SecurityUtil::loadUserInfo).thenReturn(new UserInfo("unittest", "a9c3b536-4598-411a-bda2-4068d6b5cc20", "00000010", "Ministry of Health", "hnweb-user", UUID.randomUUID().toString()));

PatientRegistrationRequest viewPatientRegisterRequest = new PatientRegistrationRequest();
viewPatientRegisterRequest.setPhn("9879869673");
viewPatientRegisterRequest.setPayee("00053");

assertThatExceptionOfType(ResponseStatusException.class)
.isThrownBy(() -> patientRegistrationController.getPatientRegistration(viewPatientRegisterRequest, createHttpServletRequest()))
.withMessage("400 BAD_REQUEST \"400 BAD_REQUEST \"Payee 00053 is not active\"\"; nested exception is org.springframework.web.server.ResponseStatusException: 400 BAD_REQUEST \"Payee 00053 is not active\"");
}

@Test
public void testRegistrationHistory_archived() throws Exception {
createPBFClinicPayee();
Expand Down Expand Up @@ -456,10 +474,20 @@ private void createPBFClinicPayee() {
payee3.setEffectiveDate(effectiveDate3);
payee3.setReportGroup("28579");

PBFClinicPayee payee4 = new PBFClinicPayee();
payee4.setArchived(Boolean.FALSE);
Date cancelDate4 = new GregorianCalendar(2023, 01, 01).getTime();
payee4.setCancelDate(cancelDate4);
payee4.setPayeeNumber("00053");
Date effectiveDate4 = new GregorianCalendar(2021, 7, 5).getTime();
payee4.setEffectiveDate(effectiveDate4);
payee4.setReportGroup("28579");

pbfClinicPayeeRepository.save(payee);
pbfClinicPayeeRepository.save(payee1);
pbfClinicPayeeRepository.save(payee2);
pbfClinicPayeeRepository.save(payee3);
pbfClinicPayeeRepository.save(payee4);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package ca.bc.gov.hlth.hnweb.service;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.transaction.annotation.Transactional;

@SpringBootTest
@Transactional
@Sql({ "classpath:scripts/bcsc_payee_mapping.sql", "classpath:scripts/pbf_clinic_payee.sql" })
public class PBFClinicPayeeServiceTest {

@Autowired
private PBFClinicPayeeService pbfClinicPayeeService;

@Test
public void testfindActiveStatusByPayeeNumber_payee_not_found() {

boolean isActive = pbfClinicPayeeService.getPayeeActiveStatus("1234");
assertFalse(isActive);
}

@Test
public void testfindActiveStatusByPayeeNumber_payee_archived() {

boolean isActive = pbfClinicPayeeService.getPayeeActiveStatus("00053");
assertFalse(isActive);
}

@Test
public void testfindActiveStatusByPayeeNumber_payee_is_active_no_cancel_date() {

boolean isActive = pbfClinicPayeeService.getPayeeActiveStatus("00023");
assertTrue(isActive);
}

@Test
public void testfindActiveStatusByPayeeNumber_payee_is_active_future_cancel_date() {

boolean isActive = pbfClinicPayeeService.getPayeeActiveStatus("00033");
assertTrue(isActive);
}

@Test
public void testfindActiveStatusByPayeeNumber_payee_is_active_effective_today() {

boolean isActive = pbfClinicPayeeService.getPayeeActiveStatus("00043");
assertTrue(isActive);
}

@Test
public void testfindActiveStatusByPayeeNumber_payee_not_yet_active_effective_tomorrow() {

boolean isActive = pbfClinicPayeeService.getPayeeActiveStatus("T0055");
assertFalse(isActive);
}

@Test
public void testfindActiveStatusByPayeeNumber_payee_is_active_cancelled_today() {

boolean isActive = pbfClinicPayeeService.getPayeeActiveStatus("T0053");
assertTrue(isActive);
}

@Test
public void testfindActiveStatusByPayeeNumber_payee_not_active_cancelled_yesterday() {

boolean isActive = pbfClinicPayeeService.getPayeeActiveStatus("X0053");
assertFalse(isActive);
}

}
3 changes: 2 additions & 1 deletion backend/src/test/resources/scripts/bcsc_payee_mapping.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ insert into mspdirect.bcsc_payee_mapping values
('eb2d707f-7860-477b-bf7e-191995d2fb8f', '00043'),
('3c0fc3b5-45f8-4745-afa9-b7b04978023d', 'T0055'),
('e4414a89-8974-4cff-9677-d9d2df6f9cfb', 'T0053'),
('924917e3-970a-482d-88b5-244be4c19d70', 'X0053');
('924917e3-970a-482d-88b5-244be4c19d70', 'X0053'),
('f33c9e07-6f49-46c2-90c2-6e0013729c9d', 'X0054');
Loading

0 comments on commit 3069fbb

Please sign in to comment.