use of org.hl7.fhir.r5.model.Observation in project openmrs-module-fhir2 by openmrs.
the class DiagnosticReportTranslatorImplTest method toFhirResource_shouldConvertResult.
@Test
public void toFhirResource_shouldConvertResult() {
DiagnosticReport result = translator.toFhirResource(fhirDiagnosticReport);
assertThat(result, notNullValue());
assertThat(result.getId(), equalTo(PARENT_UUID));
assertThat(result.getResult(), notNullValue());
assertThat(result.getResult().size(), equalTo(1));
assertThat(result.getResult(), contains(hasProperty("reference", equalTo("Observation/" + CHILD_UUID))));
}
use of org.hl7.fhir.r5.model.Observation in project elexis-server by elexis.
the class ObservationResourceProvider method createObservation.
@Create
public MethodOutcome createObservation(@ResourceParam Observation observation) {
MethodOutcome outcome = new MethodOutcome();
Optional<IObservation> exists = getTransformer().getLocalObject(observation);
if (exists.isPresent()) {
outcome.setCreated(false);
outcome.setId(new IdType(observation.getId()));
} else {
Optional<IObservation> created = getTransformer().createLocalObject(observation);
if (created.isPresent()) {
outcome.setCreated(true);
outcome.setId(new IdType(created.get().getId()));
} else {
throw new InternalErrorException("Creation failed");
}
}
return outcome;
}
use of org.hl7.fhir.r5.model.Observation in project elexis-server by elexis.
the class ObservationResourceProvider method filterCode.
private List<Observation> filterCode(List<Observation> observations, CodeType code) {
ArrayList<Observation> ret = new ArrayList<>();
String systemString = CodeTypeUtil.getSystem(code).orElse("");
String codeString = CodeTypeUtil.getCode(code).orElse("");
for (Observation observation : observations) {
if (systemString.equals(CodingSystem.ELEXIS_LOCAL_LABORATORY_VITOLABKEY.getSystem())) {
if (CodeTypeUtil.isVitoLabkey(modelService, observation, codeString)) {
ret.add(observation);
}
} else if (CodeTypeUtil.isCodeInConcept(observation.getCode(), systemString, codeString)) {
ret.add(observation);
}
}
return ret;
}
use of org.hl7.fhir.r5.model.Observation 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.r5.model.Observation in project elexis-server by elexis.
the class ObservationTest method laboratoryObservations.
@Test
public void laboratoryObservations() throws FHIRException {
// search by patient and category
Bundle results = client.search().forResource(Observation.class).where(Observation.SUBJECT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Condition.CATEGORY.exactly().code("laboratory")).returnBundle(Bundle.class).execute();
assertNotNull(results);
assertFalse(results.getEntry().isEmpty());
@SuppressWarnings("unchecked") List<Observation> observations = (List<Observation>) ((List<?>) results.getEntry().parallelStream().map(be -> be.getResource()).collect(Collectors.toList()));
for (Observation observation : observations) {
assertTrue(observation.hasEffectiveDateTimeType());
assertTrue(observation.hasValue());
assertNotNull(observation.getCode());
List<Coding> coding = observation.getCode().getCoding();
assertFalse(coding.isEmpty());
for (Coding code : coding) {
if (code.getCode().contains("NUMERIC")) {
if (observation.hasValueQuantity()) {
Quantity quantityValue = observation.getValueQuantity();
assertNotNull(quantityValue);
} else if (observation.hasValueStringType()) {
StringType stringValue = observation.getValueStringType();
assertNotNull(stringValue);
assertTrue(Character.isDigit(stringValue.toString().charAt(0)));
} else {
fail("Unexpected vaue type" + observation.getValue());
}
List<ObservationReferenceRangeComponent> refs = observation.getReferenceRange();
assertFalse(refs.isEmpty());
} else if (code.getCode().contains("TEXT")) {
StringType stringValue = observation.getValueStringType();
assertNotNull(stringValue);
}
}
}
}
Aggregations