Search in sources :

Example 86 with Encounter

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

the class EncounterTranslatorImplTest method toFhirResource_shouldTranslateToEncounterClassFhirType.

@Test
public void toFhirResource_shouldTranslateToEncounterClassFhirType() {
    when(encounterClassMap.getFhirClass(LOCATION_UUID)).thenReturn(TEST_FHIR_CLASS);
    omrsEncounter.setLocation(location);
    Encounter result = encounterTranslator.toFhirResource(omrsEncounter);
    assertThat(result, notNullValue());
    assertThat(result.getClass_(), notNullValue());
    assertThat(result.getClass_().getSystem(), is(FhirConstants.ENCOUNTER_CLASS_VALUE_SET_URI));
    assertThat(result.getClass_().getCode(), is(TEST_FHIR_CLASS));
}
Also used : Encounter(org.hl7.fhir.r4.model.Encounter) Test(org.junit.Test)

Example 87 with Encounter

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

the class EncounterTranslatorImplTest method toFhirResource_shouldTranslateToPartOf.

@Test
public void toFhirResource_shouldTranslateToPartOf() {
    Visit visit = new Visit();
    visit.setUuid(VISIT_UUID);
    org.openmrs.Encounter encounter = new org.openmrs.Encounter();
    encounter.setUuid(ENCOUNTER_UUID);
    encounter.setVisit(visit);
    Reference reference = new Reference();
    reference.setReference(VISIT_URI);
    when(visitReferenceTranslator.toFhirResource(visit)).thenReturn(reference);
    Encounter result = encounterTranslator.toFhirResource(encounter);
    assertThat(result, notNullValue());
    assertThat(result.getPartOf(), notNullValue());
    assertThat(result.getPartOf(), equalTo(reference));
}
Also used : Visit(org.openmrs.Visit) Reference(org.hl7.fhir.r4.model.Reference) Encounter(org.hl7.fhir.r4.model.Encounter) Test(org.junit.Test)

Example 88 with Encounter

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

the class EncounterResourceProvider method searchReqIdentifier.

/**
 * Search for an Encounter with a matching Elexis consultation id.
 *
 * @param identifier
 * @return
 */
@Search
public List<Encounter> searchReqIdentifier(@RequiredParam(name = Encounter.SP_IDENTIFIER) TokenParam identifier) {
    if (identifier != null && !identifier.isEmpty() && identifier.getValue() != null && !identifier.getValue().isEmpty()) {
        migratorService.migrateConsultationsFindings(identifier.getValue(), IEncounter.class);
        List<IEncounter> findings = findingsService.getConsultationsFindings(identifier.getValue(), IEncounter.class);
        if (findings != null && !findings.isEmpty()) {
            List<Encounter> ret = new ArrayList<Encounter>();
            for (IFinding iFinding : findings) {
                Optional<Encounter> fhirEncounter = getTransformer().getFhirObject((IEncounter) iFinding);
                fhirEncounter.ifPresent(fe -> ret.add(fe));
            }
            return ret;
        }
    }
    return null;
}
Also used : IEncounter(ch.elexis.core.findings.IEncounter) IFinding(ch.elexis.core.findings.IFinding) ArrayList(java.util.ArrayList) Encounter(org.hl7.fhir.r4.model.Encounter) IEncounter(ch.elexis.core.findings.IEncounter) Search(ca.uhn.fhir.rest.annotation.Search)

Example 89 with Encounter

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

the class EncounterTest method createEncounter.

@Test
public void createEncounter() {
    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.now().atStartOfDay())).setEnd(AllTests.getDate(LocalDate.now().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 outcome = client.create().resource(encounter).execute();
    assertNotNull(outcome);
    assertTrue(outcome.getCreated());
    assertNotNull(outcome.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(), encounter.getId())));
    MethodOutcome subjectiveOutcome = client.create().resource(subjective).execute();
    assertTrue(subjectiveOutcome.getCreated());
    Encounter readEncounter = client.read().resource(Encounter.class).withId(outcome.getId()).execute();
    assertNotNull(readEncounter);
    assertEquals(outcome.getId().getIdPart(), readEncounter.getIdElement().getIdPart());
    assertEquals(encounter.getPeriod().getStart(), readEncounter.getPeriod().getStart());
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) Coding(org.hl7.fhir.r4.model.Coding) Narrative(org.hl7.fhir.r4.model.Narrative) Reference(org.hl7.fhir.r4.model.Reference) Observation(org.hl7.fhir.r4.model.Observation) Encounter(org.hl7.fhir.r4.model.Encounter) Period(org.hl7.fhir.r4.model.Period) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 90 with Encounter

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

the class EncounterTest method getEncounter.

@Test
public void getEncounter() {
    Patient readPatient = client.read().resource(Patient.class).withId(AllTests.getTestDatabaseInitializer().getPatient().getId()).execute();
    // search by patient
    Bundle results = client.search().forResource(Encounter.class).where(Encounter.PATIENT.hasId(readPatient.getId())).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    List<BundleEntryComponent> entries = results.getEntry();
    assertFalse(entries.isEmpty());
    Encounter encounter = (Encounter) entries.get(0).getResource();
    System.out.println("LOOK " + TestDatabaseInitializer.getBehandlung().getId());
    // search by elexis behandlung id
    results = client.search().forResource(Encounter.class).where(Encounter.IDENTIFIER.exactly().systemAndIdentifier("www.elexis.info/consultationid", TestDatabaseInitializer.getBehandlung().getId())).returnBundle(Bundle.class).execute();
    entries = results.getEntry();
    assertFalse(entries.isEmpty());
    // read with by id
    Encounter readEncounter = client.read().resource(Encounter.class).withId(encounter.getId()).execute();
    assertNotNull(readEncounter);
    assertEquals(encounter.getId(), readEncounter.getId());
    // search by patient and date
    results = client.search().forResource(Encounter.class).where(Encounter.PATIENT.hasId(readPatient.getId())).and(Encounter.DATE.afterOrEquals().day("2016-09-01")).and(Encounter.DATE.beforeOrEquals().day("2016-10-01")).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    entries = results.getEntry();
    assertFalse(entries.isEmpty());
    // search by patient and date not found
    results = client.search().forResource(Encounter.class).where(Encounter.PATIENT.hasId(readPatient.getId())).and(Encounter.DATE.afterOrEquals().day("2016-10-01")).and(Encounter.DATE.beforeOrEquals().day("2016-11-01")).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    entries = results.getEntry();
    assertTrue(entries.isEmpty());
}
Also used : BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) Patient(org.hl7.fhir.r4.model.Patient) Encounter(org.hl7.fhir.r4.model.Encounter) 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