use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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));
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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));
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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;
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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());
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.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());
}
Aggregations