Search in sources :

Example 91 with Encounter

use of org.hl7.fhir.r4.model.Encounter in project elexis-server by elexis.

the class FamilyMemberHistoryTest method testFamilyMemberHistory.

@Test
public void testFamilyMemberHistory() {
    // search for encounter
    Bundle results = client.search().forResource(FamilyMemberHistory.class).where(FamilyMemberHistory.PATIENT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    List<BundleEntryComponent> entries = results.getEntry();
    assertFalse(entries.isEmpty());
}
Also used : FamilyMemberHistory(org.hl7.fhir.r4.model.FamilyMemberHistory) IFamilyMemberHistory(ch.elexis.core.findings.IFamilyMemberHistory) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Test(org.junit.Test)

Example 92 with Encounter

use of org.hl7.fhir.r4.model.Encounter in project elexis-server by elexis.

the class ServiceRequestTest method createServiceRequest.

@Test
public void createServiceRequest() {
    Condition problem = new Condition();
    problem.setCode(new CodeableConcept().addCoding(new Coding("http://hl7.org/fhir/sid/icpc-2", "A04", "Müdigkeit")));
    problem.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    problem.addCategory().addCoding(new Coding(ConditionCategory.PROBLEMLISTITEM.getSystem(), ConditionCategory.PROBLEMLISTITEM.toCode(), ConditionCategory.PROBLEMLISTITEM.getDisplay()));
    MethodOutcome problemOutcome = client.create().resource(problem).execute();
    Encounter encounter = new Encounter();
    EncounterParticipantComponent participant = new EncounterParticipantComponent();
    participant.setIndividual(new Reference("Practitioner/" + TestDatabaseInitializer.getMandant().getId()));
    encounter.addParticipant(participant);
    encounter.setPeriod(new Period().setStart(AllTests.getDate(LocalDate.of(2016, Month.DECEMBER, 1).atStartOfDay())).setEnd(AllTests.getDate(LocalDate.of(2016, Month.DECEMBER, 1).atTime(23, 59, 59))));
    encounter.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    encounter.addDiagnosis().setCondition(new Reference(new IdType(problem.getResourceType().name(), problemOutcome.getId().getIdPart())));
    encounter.addType(new CodeableConcept().addCoding(new Coding("www.elexis.info/encounter/type", "struct", "structured enconter")));
    MethodOutcome encounterOutcome = client.create().resource(encounter).execute();
    assertNotNull(encounterOutcome);
    assertTrue(encounterOutcome.getCreated());
    assertNotNull(encounterOutcome.getId());
    // add subjective to the encounter
    Observation subjective = new Observation();
    Narrative narrative = new Narrative();
    String divEncodedText = "Subjective\nTest".replaceAll("(\r\n|\r|\n)", "<br />");
    narrative.setDivAsString(divEncodedText);
    subjective.setText(narrative);
    subjective.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    subjective.addCategory().addCoding(new Coding(IdentifierSystem.ELEXIS_SOAP.getSystem(), ObservationCategory.SOAP_SUBJECTIVE.getCode(), ObservationCategory.SOAP_SUBJECTIVE.getLocalized()));
    subjective.setEncounter(new Reference(new IdType(encounter.getResourceType().name(), encounterOutcome.getId().getIdPart())));
    MethodOutcome subjectiveOutcome = client.create().resource(subjective).execute();
    assertTrue(subjectiveOutcome.getCreated());
    // add procedure request to encounter
    ServiceRequest serviceRequest = new ServiceRequest();
    narrative = new Narrative();
    divEncodedText = "Procedure\nTest".replaceAll("(\r\n|\r|\n)", "<br />");
    narrative.setDivAsString(divEncodedText);
    serviceRequest.setText(narrative);
    serviceRequest.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    serviceRequest.setEncounter(new Reference(new IdType(encounter.getResourceType().name(), encounterOutcome.getId().getIdPart())));
    MethodOutcome outcome = client.create().resource(serviceRequest).execute();
    assertNotNull(outcome);
    assertTrue(outcome.getCreated());
    assertNotNull(outcome.getId());
    ServiceRequest readServiceRequest = client.read().resource(ServiceRequest.class).withId(outcome.getId()).execute();
    assertNotNull(readServiceRequest);
    assertEquals(outcome.getId().getIdPart(), readServiceRequest.getIdElement().getIdPart());
    assertEquals(serviceRequest.getSubject().getReferenceElement().getIdPart(), readServiceRequest.getSubject().getReferenceElement().getIdPart());
    assertEquals(serviceRequest.getEncounter().getReferenceElement().getIdPart(), readServiceRequest.getEncounter().getReferenceElement().getIdPart());
    assertTrue(readServiceRequest.getText().getDivAsString().contains("Test"));
    // check if the consultation text has been updated
    // search by patient and date
    Bundle results = client.search().forResource(Encounter.class).where(Encounter.PATIENT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Encounter.DATE.exactly().day(AllTests.getDate(LocalDate.of(2016, Month.DECEMBER, 1).atStartOfDay()))).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    List<BundleEntryComponent> entries = results.getEntry();
    assertFalse(entries.isEmpty());
    Encounter readEncounter = (Encounter) entries.get(0).getResource();
    assertNotNull(readEncounter);
    assertEquals(readEncounter.getIdElement().getIdPart(), encounterOutcome.getId().getIdPart());
    List<Identifier> identifier = readEncounter.getIdentifier();
    String consultationId = null;
    for (Identifier id : identifier) {
        if (id.getSystem().equals(IdentifierSystem.ELEXIS_CONSID.getSystem())) {
            consultationId = id.getValue();
        }
    }
    assertNotNull(consultationId);
    Optional<IEncounter> behandlung = AllTests.getModelService().load(consultationId, IEncounter.class);
    assertTrue(behandlung.isPresent());
    assertTrue(behandlung.get().getVersionedEntry().getHead().contains("Procedure"));
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) Bundle(org.hl7.fhir.r4.model.Bundle) Period(org.hl7.fhir.r4.model.Period) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) IdType(org.hl7.fhir.r4.model.IdType) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) IEncounter(ch.elexis.core.model.IEncounter) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.r4.model.Identifier) Coding(org.hl7.fhir.r4.model.Coding) Narrative(org.hl7.fhir.r4.model.Narrative) Observation(org.hl7.fhir.r4.model.Observation) Encounter(org.hl7.fhir.r4.model.Encounter) IEncounter(ch.elexis.core.model.IEncounter) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 93 with Encounter

use of org.hl7.fhir.r4.model.Encounter in project openmrs-module-fhir2 by openmrs.

the class EncounterFhirResourceProviderTest method updateEncounter_shouldThrowMethodNotAllowedIfDoesNotExist.

@Test(expected = MethodNotAllowedException.class)
public void updateEncounter_shouldThrowMethodNotAllowedIfDoesNotExist() {
    Encounter wrongEncounter = new Encounter();
    wrongEncounter.setId(WRONG_ENCOUNTER_UUID);
    when(encounterService.update(WRONG_ENCOUNTER_UUID, wrongEncounter)).thenThrow(MethodNotAllowedException.class);
    resourceProvider.updateEncounter(new IdType().setValue(WRONG_ENCOUNTER_UUID), wrongEncounter);
}
Also used : Encounter(org.hl7.fhir.r4.model.Encounter) IdType(org.hl7.fhir.r4.model.IdType) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Example 94 with Encounter

use of org.hl7.fhir.r4.model.Encounter in project openmrs-module-fhir2 by openmrs.

the class EncounterFhirResourceProviderTest method initEncounter.

@Before
public void initEncounter() {
    encounter = new Encounter();
    encounter.setId(ENCOUNTER_UUID);
    encounter.setStatus(Encounter.EncounterStatus.UNKNOWN);
    setProvenanceResources(encounter);
}
Also used : Encounter(org.hl7.fhir.r4.model.Encounter) Before(org.junit.Before)

Example 95 with Encounter

use of org.hl7.fhir.r4.model.Encounter in project openmrs-module-fhir2 by openmrs.

the class EncounterFhirResourceProviderTest method getEncounterWithWrongUuid_shouldThrowResourceNotFoundException.

@Test(expected = ResourceNotFoundException.class)
public void getEncounterWithWrongUuid_shouldThrowResourceNotFoundException() {
    IdType id = new IdType();
    id.setValue(WRONG_ENCOUNTER_UUID);
    Encounter result = resourceProvider.getEncounterByUuid(id);
    assertThat(result, nullValue());
}
Also used : Encounter(org.hl7.fhir.r4.model.Encounter) IdType(org.hl7.fhir.r4.model.IdType) BaseFhirProvenanceResourceTest(org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)238 Encounter (org.hl7.fhir.r4.model.Encounter)166 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)100 Test (org.junit.jupiter.api.Test)93 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)87 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)79 Reference (org.hl7.fhir.r4.model.Reference)71 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)66 ArrayList (java.util.ArrayList)64 Resource (org.hl7.fhir.r4.model.Resource)61 Bundle (org.hl7.fhir.r4.model.Bundle)60 Date (java.util.Date)57 Encounter (org.hl7.fhir.dstu3.model.Encounter)55 Coding (org.hl7.fhir.r4.model.Coding)51 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)49 Reference (org.hl7.fhir.dstu3.model.Reference)48 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)43 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)41 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)38 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)37