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;
}
}
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;
}
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);
}
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);
}
Aggregations