Search in sources :

Example 1 with Appointment

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());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HttpResponse(org.apache.http.HttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint)

Example 2 with Appointment

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);
}
Also used : AppointmentParticipantComponent(org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent) Reference(org.hl7.fhir.dstu3.model.Reference)

Example 3 with Appointment

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);
}
Also used : Appointment(org.hl7.fhir.dstu3.model.Appointment) Account(org.sagebionetworks.bridge.models.accounts.Account) HealthDataSubmission(org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) SignIn(org.sagebionetworks.bridge.models.accounts.SignIn) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Example 4 with Appointment

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());
}
Also used : Appointment(org.hl7.fhir.dstu3.model.Appointment) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) Test(org.testng.annotations.Test)

Example 5 with Appointment

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());
    }
}
Also used : Appointment(org.hl7.fhir.r4.model.Appointment) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Appointment (org.hl7.fhir.dstu3.model.Appointment)12 ArrayList (java.util.ArrayList)8 Test (org.junit.jupiter.api.Test)8 AppointmentParticipantComponent (org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent)6 Test (org.testng.annotations.Test)6 DateRangeResourceList (org.sagebionetworks.bridge.models.DateRangeResourceList)5 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)5 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)4 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)4 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)4 IdDt (ca.uhn.fhir.model.primitive.IdDt)3 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)3 Date (java.util.Date)3 Reference (org.hl7.fhir.dstu3.model.Reference)3 Turtle (org.hl7.fhir.dstu3.utils.formats.Turtle)3 Appointment (org.hl7.fhir.r4.model.Appointment)3 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)3 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)3 AppointmentDetail (uk.gov.hscic.model.appointment.AppointmentDetail)3 SlotDetail (uk.gov.hscic.model.appointment.SlotDetail)3