Search in sources :

Example 6 with BOOKED

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.");
}
Also used : Appointment(org.hl7.fhir.dstu3.model.Appointment) StatusLine(org.apache.http.StatusLine) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Example 7 with BOOKED

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

Example 8 with BOOKED

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 + ")."));
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) Appointment(org.hl7.fhir.dstu3.model.Appointment) Account(org.sagebionetworks.bridge.models.accounts.Account) BridgeUtils.parseAccountId(org.sagebionetworks.bridge.BridgeUtils.parseAccountId) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) JsonNode(com.fasterxml.jackson.databind.JsonNode) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) IParser(ca.uhn.fhir.parser.IParser) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 9 with BOOKED

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);
}
Also used : Appointment(org.hl7.fhir.dstu3.model.Appointment) AppointmentParticipantComponent(org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent) Patient(org.hl7.fhir.dstu3.model.Patient) POCDMT000002UK01Encounter(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Encounter)

Example 10 with BOOKED

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);
}
Also used : Appointment(org.hl7.fhir.dstu3.model.Appointment) POCDMT000002UK01Section(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Section) POCDMT000002UK01Entry(uk.nhs.connect.iucds.cda.ucr.POCDMT000002UK01Entry) Reference(org.hl7.fhir.dstu3.model.Reference) IdType(org.hl7.fhir.dstu3.model.IdType) Test(org.junit.jupiter.api.Test)

Aggregations

Appointment (org.hl7.fhir.dstu3.model.Appointment)7 DateRangeResourceList (org.sagebionetworks.bridge.models.DateRangeResourceList)4 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)4 Test (org.testng.annotations.Test)4 AppointmentParticipantComponent (org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent)3 ScheduleDetail (uk.gov.hscic.model.appointment.ScheduleDetail)3 SlotDetail (uk.gov.hscic.model.appointment.SlotDetail)3 IdDt (ca.uhn.fhir.model.primitive.IdDt)2 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)2 Account (org.sagebionetworks.bridge.models.accounts.Account)2 HealthDataSubmission (org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission)2 VC (uk.gov.hscic.common.validators.VC)2 AppointmentDetail (uk.gov.hscic.model.appointment.AppointmentDetail)2 IParser (ca.uhn.fhir.parser.IParser)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 LoggingEvent (ch.qos.logback.classic.spi.LoggingEvent)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 HttpEntity (org.apache.http.HttpEntity)1 HttpResponse (org.apache.http.HttpResponse)1 StatusLine (org.apache.http.StatusLine)1