use of org.hl7.fhir.r4.model.Appointment in project BridgeServer2 by Sage-Bionetworks.
the class CRCController method addLocation.
/**
* This is a nice-to-have addition of address information for the location given by an
* ID in the appointment record. Do not fail the request if this fails, but log enough
* to troubleshoot if the issue is on our side.
*/
void addLocation(JsonNode node, Account account, String locationId) {
String cuimcEnv = (account.getDataGroups().contains(TEST_USER_GROUP)) ? "test" : "prod";
String cuimcUrl = "cuimc." + cuimcEnv + ".location.url";
String url = bridgeConfig.get(cuimcUrl);
String reqBody = "id=\"" + locationId + "\"";
try {
HttpResponse response = post(url, account, reqBody);
String resBody = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8.name());
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200 && statusCode != 201) {
logWarningMessage(locationId, statusCode, resBody);
return;
}
JsonNode bundleJson = BridgeObjectMapper.get().readTree(resBody);
if (!bundleJson.has("entry") || ((ArrayNode) bundleJson.get("entry")).size() == 0) {
logWarningMessage(locationId, statusCode, resBody);
return;
}
JsonNode resJson = bundleJson.get("entry").get(0).get("resource");
if (resJson == null) {
logWarningMessage(locationId, statusCode, resBody);
return;
}
JsonNode telecom = resJson.get("telecom");
JsonNode address = resJson.get("address");
ArrayNode participants = (ArrayNode) node.get("participant");
if (participants != null) {
for (int i = 0; i < participants.size(); i++) {
JsonNode child = participants.get(i);
ObjectNode actor = (ObjectNode) child.get("actor");
if (actor != null && actor.has("reference")) {
String ref = actor.get("reference").textValue();
if (ref.startsWith("Location")) {
if (telecom != null) {
actor.set("telecom", telecom);
}
if (address != null) {
actor.set("address", address);
// addGeocodingInformation(actor);
}
break;
}
}
}
}
} catch (IOException e) {
LOG.warn("Error retrieving location, id = " + locationId, e);
return;
}
LOG.info("Location added to appointment record for user " + account.getId());
}
use of org.hl7.fhir.r4.model.Appointment in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method addAppointmentParticipantComponent.
private void addAppointmentParticipantComponent(Appointment appointment, String value) {
AppointmentParticipantComponent comp = new AppointmentParticipantComponent();
comp.setActor(new Reference(value));
appointment.addParticipant(comp);
}
use of org.hl7.fhir.r4.model.Appointment in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postAppointmentCreated.
@Test
public void postAppointmentCreated() 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());
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);
ResponseEntity<StatusMessage> retValue = controller.postAppointment();
assertEquals(retValue.getBody().getMessage(), "Appointment created (status = booked).");
assertEquals(retValue.getStatusCodeValue(), 201);
verify(mockAccountService).authenticate(eq(app), signInCaptor.capture());
SignIn capturedSignIn = signInCaptor.getValue();
assertEquals(capturedSignIn.getAppId(), APP_ID);
assertEquals(capturedSignIn.getExternalId(), CUIMC_USERNAME);
assertEquals(capturedSignIn.getPassword(), "dummy-password");
verify(mockReportService).saveParticipantReport(eq(APP_ID), eq(TEST_USER_ID), eq(APPOINTMENT_REPORT), eq(HEALTH_CODE), reportCaptor.capture());
ReportData capturedReport = reportCaptor.getValue();
assertEquals(capturedReport.getDate(), "1970-01-01");
verifyParticipant(capturedReport.getData());
assertEquals(capturedReport.getStudyIds(), USER_STUDY_IDS);
verify(mockAccountService).updateAccount(accountCaptor.capture());
Account capturedAcct = accountCaptor.getValue();
assertEquals(capturedAcct.getDataGroups(), makeSetOf(CRCController.AccountStates.TESTS_SCHEDULED, "group1"));
assertEquals(capturedAcct.getAttributes().get(TIMESTAMP_FIELD), TIMESTAMP.toString());
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.r4.model.Appointment in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postAppointmentSkipsLocationIfNotPresent.
@Test
public void postAppointmentSkipsLocationIfNotPresent() 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));
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);
addAppointmentSageId(appointment, TEST_USER_ID);
String json = FHIR_CONTEXT.newJsonParser().encodeResourceToString(appointment);
mockRequestBody(mockRequest, json);
controller.postAppointment();
verify(controller, never()).post(any(), any(), any());
verify(mockHealthDataService).submitHealthData(any(), any(), any());
}
use of org.hl7.fhir.r4.model.Appointment in project elexis-server by elexis.
the class AppointmentTest method testSearchByDateParamsAndSlot.
// FIX ME
@Ignore
@Test
public void testSearchByDateParamsAndSlot() {
// http://localhost:8380/fhir/Schedule/5495888f8aae05023409b5cf853bbbce Praxis
Bundle results = client.search().forResource(Appointment.class).where(Appointment.DATE.afterOrEquals().day("2016-12-01")).and(Appointment.DATE.before().day("2016-12-30")).and(Appointment.ACTOR.hasId("Schedule/68a891b86923dd1740345627dbb92c9f")).returnBundle(Bundle.class).execute();
assertEquals(2, results.getEntry().size());
for (BundleEntryComponent entry : results.getEntry()) {
Appointment appointment = (Appointment) entry.getResource();
assertTrue(appointment.getParticipant().get(0).getActor().getReference().startsWith("Patient/"));
assertNull(appointment.getParticipant().get(0).getActorTarget());
}
}
Aggregations