use of org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus.BOOKED in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postAppointmentFailsWhenLocationCallFails.
@Test
public void postAppointmentFailsWhenLocationCallFails() throws Exception {
when(mockRequest.getHeader(AUTHORIZATION)).thenReturn(AUTHORIZATION_HEADER_VALUE);
when(mockAccountService.authenticate(any(), any())).thenReturn(account);
when(mockAccountService.getAccount(ACCOUNT_ID)).thenReturn(Optional.of(account));
// mockGetGeocoding();
DateRangeResourceList<? extends ReportData> results = new DateRangeResourceList<>(ImmutableList.of());
doReturn(results).when(mockReportService).getParticipantReport(APP_ID, TEST_USER_ID, APPOINTMENT_REPORT, HEALTH_CODE, JAN1, JAN2);
Appointment appointment = new Appointment();
appointment.setStatus(BOOKED);
// add a wrong participant to verify we go through them all and look for ours
addAppointmentParticipantComponent(appointment, "Location/foo");
addAppointmentSageId(appointment, TEST_USER_ID);
String json = FHIR_CONTEXT.newJsonParser().encodeResourceToString(appointment);
mockRequestBody(mockRequest, json);
HttpResponse mockResponse = mock(HttpResponse.class);
doReturn(mockResponse).when(controller).post(any(), any(), any());
StatusLine mockStatusLine = mock(StatusLine.class);
when(mockResponse.getStatusLine()).thenReturn(mockStatusLine);
when(mockStatusLine.getStatusCode()).thenReturn(400);
HttpEntity mockEntity = mock(HttpEntity.class);
when(mockResponse.getEntity()).thenReturn(mockEntity);
when(mockEntity.getContent()).thenReturn(IOUtils.toInputStream("This was an error.", UTF_8));
ResponseEntity<StatusMessage> retValue = controller.postAppointment();
assertEquals(retValue.getBody().getMessage(), "Appointment created (status = booked).");
assertEquals(retValue.getStatusCodeValue(), 201);
verify(mockAppender).doAppend(loggingEventCaptor.capture());
final LoggingEvent loggingEvent = loggingEventCaptor.getValue();
assertEquals(loggingEvent.getLevel(), Level.WARN);
assertEquals(loggingEvent.getFormattedMessage(), "Error retrieving location, id = foo, status = 400, response body = This was an error.");
}
use of org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus.BOOKED in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postAppointmentUpdated.
@Test
public void postAppointmentUpdated() throws Exception {
when(mockRequest.getHeader(AUTHORIZATION)).thenReturn(AUTHORIZATION_HEADER_VALUE);
when(mockAccountService.authenticate(any(), any())).thenReturn(account);
when(mockAccountService.getAccount(ACCOUNT_ID)).thenReturn(Optional.of(account));
mockGetLocation(LOCATION_JSON);
// mockGetGeocoding();
DateRangeResourceList<? extends ReportData> results = new DateRangeResourceList<>(ImmutableList.of(ReportData.create()));
doReturn(results).when(mockReportService).getParticipantReport(APP_ID, TEST_USER_ID, APPOINTMENT_REPORT, HEALTH_CODE, JAN1, JAN2);
Appointment appointment = new Appointment();
appointment.setStatus(BOOKED);
// add a wrong participant to verify we go through them all and look for ours
addAppointmentParticipantComponent(appointment, LOCATION_NS + "foo");
addAppointmentSageId(appointment, TEST_USER_ID);
String json = FHIR_CONTEXT.newJsonParser().encodeResourceToString(appointment);
mockRequestBody(mockRequest, json);
ResponseEntity<StatusMessage> retValue = controller.postAppointment();
assertEquals(retValue.getBody().getMessage(), "Appointment updated (status = booked).");
assertEquals(retValue.getStatusCodeValue(), 200);
assertTrue(account.getDataGroups().contains("tests_scheduled"));
verify(controller).addLocation(any(), eq(account), eq("foo"));
verify(controller).post("http://testServer/location/_search", account, "id=\"foo\"");
verify(mockHealthDataService).submitHealthData(eq(APP_ID), participantCaptor.capture(), dataCaptor.capture());
HealthDataSubmission healthData = dataCaptor.getValue();
assertEquals(healthData.getAppVersion(), "v1");
assertEquals(healthData.getCreatedOn(), TIMESTAMP);
assertEquals(healthData.getMetadata().toString(), "{\"type\":\"" + APPOINTMENT_REPORT + "\"}");
assertEquals(healthData.getData().toString(), APPOINTMENT_JSON_FULLY_RESOLVED);
}
use of org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus.BOOKED in project BridgeServer2 by Sage-Bionetworks.
the class CRCController method postAppointment.
@PutMapping("/v1/cuimc/appointments")
public ResponseEntity<StatusMessage> postAppointment() {
App app = httpBasicAuthentication();
IParser parser = FHIR_CONTEXT.newJsonParser();
JsonNode data = parseJson(JsonNode.class);
Appointment appointment = parser.parseResource(Appointment.class, data.toString());
String userId = findUserId(appointment);
// They send appointment when it is booked, cancelled, or (rarely) enteredinerror.
AccountStates state = TESTS_SCHEDULED;
String apptStatus = data.get("status").asText();
if ("entered-in-error".equals(apptStatus)) {
deleteReportAndUpdateState(app, userId);
return ResponseEntity.ok(new StatusMessage("Appointment deleted."));
} else if ("cancelled".equals(apptStatus)) {
state = TESTS_CANCELLED;
}
// Columbia wants us to call back to them to get information about the location.
// And UI team wants geocoding of location to render a map.
String locationString = findLocation(appointment);
if (locationString != null) {
AccountId accountId = parseAccountId(app.getIdentifier(), userId);
Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
addLocation(data, account, locationString);
}
int status = writeReportAndUpdateState(app, userId, data, APPOINTMENT_REPORT, state, true);
if (status == 200) {
return ResponseEntity.ok(new StatusMessage("Appointment updated (status = " + apptStatus + ")."));
}
return ResponseEntity.created(URI.create("/v1/cuimc/appointments/" + userId)).body(new StatusMessage("Appointment created (status = " + apptStatus + ")."));
}
use of org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus.BOOKED in project integration-adaptor-111 by nhsconnect.
the class AppointmentMapper method mapAppointment.
public Optional<Appointment> mapAppointment(POCDMT000002UK01Entry entry, POCDMT000002UK01Section matchingSection, Reference patient) {
POCDMT000002UK01Encounter itkEncounter = entry.getEncounter();
Appointment appointment = new Appointment().setStatus(BOOKED);
appointment.setIdElement(resourceUtil.newRandomUuid());
if (matchingSection != null) {
appointment.setDescription(nodeUtil.getNodeValueString(matchingSection.getTitle())).setComment(nodeUtil.getNodeValueString(matchingSection.getText().getContentArray(0)));
}
appointment.addParticipant(new AppointmentParticipantComponent().setActor(patient).setActorTarget((Patient) patient.getResource()).setRequired(REQUIRED).setStatus(ACCEPTED));
getAppointmentParticipantComponents(itkEncounter).forEach(appointment::addParticipant);
appointment.addReason(getReason(entry));
return Optional.of(appointment);
}
use of org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus.BOOKED in project integration-adaptor-111 by nhsconnect.
the class AppointmentMapperTest method shouldMapAppointment.
@Test
public void shouldMapAppointment() {
POCDMT000002UK01Entry entry = mockEntry();
POCDMT000002UK01Section section = mockSection();
Reference patient = mock(Reference.class);
when(locationMapper.mapRoleToLocation(any())).thenReturn(location);
when(resourceUtil.newRandomUuid()).thenReturn(new IdType(RANDOM_UUID));
Optional<Appointment> appointment = appointmentMapper.mapAppointment(entry, section, patient);
assertThat(appointment.isPresent());
assertThat(appointment.get().getIdElement().getValue()).isEqualTo(RANDOM_UUID);
assertThat(appointment.get().getStatus()).isEqualTo(BOOKED);
assertThat(appointment.get().getStart()).isNull();
assertThat(appointment.get().getEnd()).isNull();
assertThat(appointment.get().getMinutesDuration()).isEqualTo(0);
assertThat(appointment.get().getDescription()).isEqualTo(TITLE);
assertThat(appointment.get().getComment()).isEqualTo(COMMENT);
assertThat(appointment.get().getParticipantFirstRep().getActor()).isEqualTo(patient);
assertThat(appointment.get().getParticipantFirstRep().getRequired()).isEqualTo(REQUIRED);
assertThat(appointment.get().getParticipantFirstRep().getStatus()).isEqualTo(ACCEPTED);
assertThat(appointment.get().getReasonFirstRep().getText()).isEqualTo(REASON);
}
Aggregations