Search in sources :

Example 1 with NameSearchResponse

use of ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchResponse in project moh-hnweb by bcgov.

the class EnrollmentController method getNameSearch.

@PostMapping("/name-search")
public ResponseEntity<NameSearchResponse> getNameSearch(@Valid @RequestBody NameSearchRequest nameSearchRequest, HttpServletRequest request) {
    logger.info("Name Search request: {} ", nameSearchRequest.getGivenName());
    Transaction transaction = transactionStart(request, TransactionType.NAME_SEARCH);
    try {
        FindCandidatesConverter converter = new FindCandidatesConverter();
        FindCandidatesRequest findCandidatesRequest = converter.convertRequest(nameSearchRequest);
        FindCandidatesResponse findCandidatesResponse = enrollmentService.findCandidates(findCandidatesRequest, transaction);
        NameSearchResponse nameSearchResponse = converter.convertResponse(findCandidatesResponse);
        ResponseEntity<NameSearchResponse> responseEntity = ResponseEntity.ok(nameSearchResponse);
        auditGetNameSearchComplete(transaction, nameSearchResponse);
        return responseEntity;
    } catch (Exception e) {
        handleException(transaction, e);
        return null;
    }
}
Also used : Transaction(ca.bc.gov.hlth.hnweb.persistence.entity.Transaction) NameSearchResponse(ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchResponse) FindCandidatesRequest(ca.bc.gov.hlth.hnweb.model.v3.FindCandidatesRequest) FindCandidatesResponse(ca.bc.gov.hlth.hnweb.model.v3.FindCandidatesResponse) FindCandidatesConverter(ca.bc.gov.hlth.hnweb.converter.hl7v3.FindCandidatesConverter) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with NameSearchResponse

use of ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchResponse in project moh-hnweb by bcgov.

the class FindCandidatesConverter method convertResponse.

public NameSearchResponse convertResponse(FindCandidatesResponse findCandidatesResponse) throws IOException {
    logger.debug("Find Candidates response : {} ", findCandidatesResponse.toString());
    NameSearchResponse nameSearchResponse = new NameSearchResponse();
    String messageDetails = findCandidatesResponse.getMessage().getDetails();
    String[] messageText = messageDetails.split("\\|");
    String message = "";
    if (messageText.length > 1) {
        message = messageText[1];
    }
    nameSearchResponse.setMessage(message);
    nameSearchResponse.setStatus(StatusEnum.SUCCESS);
    if (findCandidatesResponse.getResultCount() > 0) {
        List<NameSearchResult> results = buildNameSearch(findCandidatesResponse);
        nameSearchResponse.setCandidates(results);
        logger.debug("Converted Name Search Response : {} ", nameSearchResponse);
    }
    return nameSearchResponse;
}
Also used : NameSearchResult(ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchResult) NameSearchResponse(ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchResponse)

Example 3 with NameSearchResponse

use of ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchResponse in project moh-hnweb by bcgov.

the class EnrollmentControllerTest method testGetNameSearch_MultiRecords.

@Test
void testGetNameSearch_MultiRecords() throws Exception {
    mockBackEnd.enqueue(new MockResponse().setBody(TestUtil.convertXMLFileToString("src/test/resources/FindCandidatesResponse_Multiples.xml")).addHeader(CONTENT_TYPE, MediaType.TEXT_XML_VALUE.toString()));
    NameSearchRequest nameSearchRequest = new NameSearchRequest();
    nameSearchRequest.setGivenName("TestGiven");
    nameSearchRequest.setSurname("TestSurname");
    nameSearchRequest.setGender("M");
    nameSearchRequest.setDateOfBirth(LocalDate.of(1973, 8, 11));
    ResponseEntity<NameSearchResponse> response = enrollmentController.getNameSearch(nameSearchRequest, createHttpServletRequest());
    NameSearchResponse nameSearchResponse = response.getBody();
    assertEquals(3, nameSearchResponse.getCandidates().size());
    assertEquals(new BigDecimal(31), nameSearchResponse.getCandidates().get(0).getScore());
    assertEquals(new BigDecimal(-53), nameSearchResponse.getCandidates().get(1).getScore());
    assertEquals(new BigDecimal(-56), nameSearchResponse.getCandidates().get(2).getScore());
    // Check the client request is sent as expected
    RecordedRequest recordedRequest = mockBackEnd.takeRequest();
    assertEquals(HttpMethod.POST.name(), recordedRequest.getMethod());
    assertEquals(MediaType.TEXT_XML.toString(), recordedRequest.getHeader(CONTENT_TYPE));
    assertEquals("/", recordedRequest.getPath());
    assertTransactionCreated(TransactionType.NAME_SEARCH);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) NameSearchRequest(ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchRequest) NameSearchResponse(ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchResponse) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test) BaseControllerTest(ca.bc.gov.hlth.hnweb.BaseControllerTest)

Example 4 with NameSearchResponse

use of ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchResponse in project moh-hnweb by bcgov.

the class EnrollmentControllerTest method testGetNameSearch_NoRecords.

@Test
void testGetNameSearch_NoRecords() throws Exception {
    mockBackEnd.enqueue(new MockResponse().setBody(TestUtil.convertXMLFileToString("src/test/resources/FindCandidatesResponse_NoMatches.xml")).addHeader(CONTENT_TYPE, MediaType.TEXT_XML_VALUE.toString()));
    NameSearchRequest nameSearchRequest = new NameSearchRequest();
    nameSearchRequest.setGivenName("TestGiven");
    nameSearchRequest.setSurname("TestSurname");
    nameSearchRequest.setGender("M");
    nameSearchRequest.setDateOfBirth(LocalDate.of(1973, 8, 11));
    ResponseEntity<NameSearchResponse> response = enrollmentController.getNameSearch(nameSearchRequest, createHttpServletRequest());
    NameSearchResponse nameSearchResponse = response.getBody();
    assertEquals(NO_RECORD_MESSAGE, nameSearchResponse.getMessage());
    // Check the client request is sent as expected
    RecordedRequest recordedRequest = mockBackEnd.takeRequest();
    assertEquals(HttpMethod.POST.name(), recordedRequest.getMethod());
    assertEquals(MediaType.TEXT_XML.toString(), recordedRequest.getHeader(CONTENT_TYPE));
    assertEquals("/", recordedRequest.getPath());
    assertTransactionCreated(TransactionType.NAME_SEARCH);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) NameSearchRequest(ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchRequest) NameSearchResponse(ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchResponse) Test(org.junit.jupiter.api.Test) BaseControllerTest(ca.bc.gov.hlth.hnweb.BaseControllerTest)

Aggregations

NameSearchResponse (ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchResponse)4 BaseControllerTest (ca.bc.gov.hlth.hnweb.BaseControllerTest)2 NameSearchRequest (ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchRequest)2 MockResponse (okhttp3.mockwebserver.MockResponse)2 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)2 Test (org.junit.jupiter.api.Test)2 FindCandidatesConverter (ca.bc.gov.hlth.hnweb.converter.hl7v3.FindCandidatesConverter)1 NameSearchResult (ca.bc.gov.hlth.hnweb.model.rest.enrollment.NameSearchResult)1 FindCandidatesRequest (ca.bc.gov.hlth.hnweb.model.v3.FindCandidatesRequest)1 FindCandidatesResponse (ca.bc.gov.hlth.hnweb.model.v3.FindCandidatesResponse)1 Transaction (ca.bc.gov.hlth.hnweb.persistence.entity.Transaction)1 BigDecimal (java.math.BigDecimal)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1