use of ca.uhn.fhir.model.dstu2.resource.Encounter in project synthea by synthetichealth.
the class CodeResolveAndExportTest method verifyEncounterCodeStu3.
private void verifyEncounterCodeStu3() throws IOException {
InputStream inputStream = new FileInputStream(stu3OutputPath.toFile().getAbsolutePath());
Bundle bundle = (Bundle) FhirStu3.getContext().newJsonParser().parseResource(inputStream);
// Find encounter reason code.
Optional<BundleEntryComponent> maybeEncounterEntry = bundle.getEntry().stream().filter(entry -> entry.getResource().getResourceType().equals(ResourceType.Encounter)).findFirst();
assertTrue(maybeEncounterEntry.isPresent());
org.hl7.fhir.dstu3.model.Encounter encounterResource = (org.hl7.fhir.dstu3.model.Encounter) maybeEncounterEntry.get().getResource();
assertEquals(encounterResource.getReason().size(), 1);
CodeableConcept encounterReason = encounterResource.getReason().get(0);
assertEquals(encounterReason.getCoding().size(), 1);
Coding reasonCoding = encounterReason.getCoding().get(0);
// Check encounter reason code.
assertEquals(SNOMED_URI, reasonCoding.getSystem());
assertEquals(EXPECTED_REASON_CODE, reasonCoding.getCode());
assertEquals(EXPECTED_REASON_DISPLAY, reasonCoding.getDisplay());
Optional<BundleEntryComponent> maybeObservationEntry = bundle.getEntry().stream().filter(entry -> entry.getResource().getResourceType().equals(ResourceType.Observation)).findFirst();
assertTrue(maybeObservationEntry.isPresent());
// Find observation type code.
org.hl7.fhir.dstu3.model.Observation observationResource = (org.hl7.fhir.dstu3.model.Observation) maybeObservationEntry.get().getResource();
CodeableConcept observationType = observationResource.getCode();
assertNotNull(observationType);
assertEquals(observationType.getCoding().size(), 1);
Coding observationTypeCoding = observationType.getCoding().get(0);
// Check observation type code.
assertEquals(LOINC_URI, observationTypeCoding.getSystem());
assertEquals(OBSERVATION_CODE, observationTypeCoding.getCode());
assertEquals(OBSERVATION_DISPLAY, observationTypeCoding.getDisplay());
// Find observation value code.
CodeableConcept observationValue = observationResource.getValueCodeableConcept();
assertNotNull(observationValue);
assertEquals(observationValue.getCoding().size(), 1);
Coding observationValueCoding = observationValue.getCoding().get(0);
// Check observation value code.
assertEquals(LOINC_URI, observationValueCoding.getSystem());
assertEquals(EXPECTED_VALUE_CODE, observationValueCoding.getCode());
assertEquals(EXPECTED_VALUE_DISPLAY, observationValueCoding.getDisplay());
inputStream.close();
}
use of ca.uhn.fhir.model.dstu2.resource.Encounter in project synthea by synthetichealth.
the class CodeResolveAndExportTest method verifyEncounterCodeR4.
private void verifyEncounterCodeR4() throws IOException {
InputStream inputStream = new FileInputStream(r4OutputPath.toFile().getAbsolutePath());
org.hl7.fhir.r4.model.Bundle bundle = (org.hl7.fhir.r4.model.Bundle) FhirR4.getContext().newJsonParser().parseResource(inputStream);
// Find encounter reason code.
Optional<org.hl7.fhir.r4.model.Bundle.BundleEntryComponent> maybeEncounterEntry = bundle.getEntry().stream().filter(entry -> entry.getResource().getResourceType().equals(org.hl7.fhir.r4.model.ResourceType.Encounter)).findFirst();
assertTrue(maybeEncounterEntry.isPresent());
org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) maybeEncounterEntry.get().getResource();
assertEquals(encounterResource.getReasonCode().size(), 1);
org.hl7.fhir.r4.model.CodeableConcept encounterReason = encounterResource.getReasonCode().get(0);
assertEquals(encounterReason.getCoding().size(), 1);
org.hl7.fhir.r4.model.Coding reasonCoding = encounterReason.getCoding().get(0);
// Check encounter reason code.
assertEquals(SNOMED_URI, reasonCoding.getSystem());
assertEquals(EXPECTED_REASON_CODE, reasonCoding.getCode());
assertEquals(EXPECTED_REASON_DISPLAY, reasonCoding.getDisplay());
Optional<org.hl7.fhir.r4.model.Bundle.BundleEntryComponent> maybeObservationEntry = bundle.getEntry().stream().filter(entry -> entry.getResource().getResourceType().equals(org.hl7.fhir.r4.model.ResourceType.Observation)).findFirst();
assertTrue(maybeObservationEntry.isPresent());
// Find observation type code.
org.hl7.fhir.r4.model.Observation observationResource = (org.hl7.fhir.r4.model.Observation) maybeObservationEntry.get().getResource();
org.hl7.fhir.r4.model.CodeableConcept observationType = observationResource.getCode();
assertNotNull(observationType);
assertEquals(observationType.getCoding().size(), 1);
org.hl7.fhir.r4.model.Coding observationTypeCoding = observationType.getCoding().get(0);
// Check observation type code.
assertEquals(LOINC_URI, observationTypeCoding.getSystem());
assertEquals(OBSERVATION_CODE, observationTypeCoding.getCode());
assertEquals(OBSERVATION_DISPLAY, observationTypeCoding.getDisplay());
// Find observation value code.
org.hl7.fhir.r4.model.CodeableConcept observationValue = observationResource.getValueCodeableConcept();
assertNotNull(observationValue);
assertEquals(observationValue.getCoding().size(), 1);
org.hl7.fhir.r4.model.Coding observationValueCoding = observationValue.getCoding().get(0);
// Check observation value code.
assertEquals(LOINC_URI, observationValueCoding.getSystem());
assertEquals(EXPECTED_VALUE_CODE, observationValueCoding.getCode());
assertEquals(EXPECTED_VALUE_DISPLAY, observationValueCoding.getDisplay());
inputStream.close();
}
use of ca.uhn.fhir.model.dstu2.resource.Encounter in project synthea by synthetichealth.
the class FHIRDSTU2ExporterTest method testSampledDataExport.
@Test
public void testSampledDataExport() throws Exception {
Person person = new Person(0L);
person.attributes.put(Person.GENDER, "F");
person.attributes.put(Person.FIRST_LANGUAGE, "spanish");
person.attributes.put(Person.RACE, "other");
person.attributes.put(Person.ETHNICITY, "hispanic");
person.attributes.put(Person.INCOME, Integer.parseInt(Config.get("generate.demographics.socioeconomic.income.poverty")) * 2);
person.attributes.put(Person.OCCUPATION_LEVEL, 1.0);
person.history = new LinkedList<>();
Provider mock = Mockito.mock(Provider.class);
Mockito.when(mock.getResourceID()).thenReturn("Mock-UUID");
person.setProvider(EncounterType.AMBULATORY, mock);
person.setProvider(EncounterType.WELLNESS, mock);
person.setProvider(EncounterType.EMERGENCY, mock);
person.setProvider(EncounterType.INPATIENT, mock);
Long time = System.currentTimeMillis();
int age = 35;
long birthTime = time - Utilities.convertTime("years", age);
person.attributes.put(Person.BIRTHDATE, birthTime);
Payer.loadNoInsurance();
for (int i = 0; i < age; i++) {
long yearTime = time - Utilities.convertTime("years", i);
person.coverage.setPayerAtTime(yearTime, Payer.noInsurance);
}
Module module = TestHelper.getFixture("observation.json");
State encounter = module.getState("SomeEncounter");
assertTrue(encounter.process(person, time));
person.history.add(encounter);
State physiology = module.getState("Simulate_CVS");
assertTrue(physiology.process(person, time));
person.history.add(physiology);
State sampleObs = module.getState("SampledDataObservation");
assertTrue(sampleObs.process(person, time));
person.history.add(sampleObs);
FhirContext ctx = FhirDstu2.getContext();
IParser parser = ctx.newJsonParser().setPrettyPrint(true);
String fhirJson = FhirDstu2.convertToFHIRJson(person, System.currentTimeMillis());
Bundle bundle = parser.parseResource(Bundle.class, fhirJson);
for (Entry entry : bundle.getEntry()) {
if (entry.getResource() instanceof Observation) {
Observation obs = (Observation) entry.getResource();
assertTrue(obs.getValue() instanceof SampledDataDt);
SampledDataDt data = (SampledDataDt) obs.getValue();
// 0.01s == 10ms
assertEquals(10, data.getPeriod().doubleValue(), 0.001);
assertEquals(3, (int) data.getDimensions());
}
}
}
use of ca.uhn.fhir.model.dstu2.resource.Encounter in project synthea by synthetichealth.
the class CodeResolveAndExportTest method verifyEncounterCodeDstu2.
private void verifyEncounterCodeDstu2() throws IOException {
InputStream inputStream = new FileInputStream(dstu2OutputPath.toFile().getAbsolutePath());
ca.uhn.fhir.model.dstu2.resource.Bundle bundle = (ca.uhn.fhir.model.dstu2.resource.Bundle) FhirDstu2.getContext().newJsonParser().parseResource(inputStream);
// Find encounter reason code.
Optional<Entry> maybeEncounterEntry = bundle.getEntry().stream().filter(entry -> entry.getResource().getResourceName().equals(org.hl7.fhir.dstu2.model.ResourceType.Encounter.name())).findFirst();
assertTrue(maybeEncounterEntry.isPresent());
ca.uhn.fhir.model.dstu2.resource.Encounter encounterResource = (ca.uhn.fhir.model.dstu2.resource.Encounter) maybeEncounterEntry.get().getResource();
assertEquals(encounterResource.getReason().size(), 1);
CodeableConceptDt encounterReason = encounterResource.getReason().get(0);
assertEquals(encounterReason.getCoding().size(), 1);
CodingDt reasonCoding = encounterReason.getCoding().get(0);
// Check encounter reason code.
assertEquals(SNOMED_URI, reasonCoding.getSystem());
assertEquals(EXPECTED_REASON_CODE, reasonCoding.getCode());
assertEquals(EXPECTED_REASON_DISPLAY, reasonCoding.getDisplay());
Optional<Entry> maybeObservationEntry = bundle.getEntry().stream().filter(entry -> entry.getResource().getResourceName().equals(org.hl7.fhir.dstu2.model.ResourceType.Observation.name())).findFirst();
assertTrue(maybeObservationEntry.isPresent());
// Find observation type code.
ca.uhn.fhir.model.dstu2.resource.Observation observationResource = (ca.uhn.fhir.model.dstu2.resource.Observation) maybeObservationEntry.get().getResource();
CodeableConceptDt observationType = observationResource.getCode();
assertNotNull(observationType);
assertEquals(observationType.getCoding().size(), 1);
CodingDt observationTypeCoding = observationType.getCoding().get(0);
// Check observation type code.
assertEquals(LOINC_URI, observationTypeCoding.getSystem());
assertEquals(OBSERVATION_CODE, observationTypeCoding.getCode());
assertEquals(OBSERVATION_DISPLAY, observationTypeCoding.getDisplay());
// Find observation value code.
CodeableConceptDt observationValue = (CodeableConceptDt) observationResource.getValue();
assertNotNull(observationValue);
assertEquals(observationValue.getCoding().size(), 1);
CodingDt observationValueCoding = observationValue.getCoding().get(0);
// Check observation value code.
assertEquals(LOINC_URI, observationValueCoding.getSystem());
assertEquals(EXPECTED_VALUE_CODE, observationValueCoding.getCode());
assertEquals(EXPECTED_VALUE_DISPLAY, observationValueCoding.getDisplay());
inputStream.close();
}
use of ca.uhn.fhir.model.dstu2.resource.Encounter in project synthea by synthetichealth.
the class FHIRDSTU2ExporterTest method testObservationAttachment.
@Test
public void testObservationAttachment() throws Exception {
Person person = new Person(0L);
person.attributes.put(Person.GENDER, "F");
person.attributes.put(Person.FIRST_LANGUAGE, "spanish");
person.attributes.put(Person.RACE, "other");
person.attributes.put(Person.ETHNICITY, "hispanic");
person.attributes.put(Person.INCOME, Integer.parseInt(Config.get("generate.demographics.socioeconomic.income.poverty")) * 2);
person.attributes.put(Person.OCCUPATION_LEVEL, 1.0);
person.attributes.put("Pulmonary Resistance", 0.1552);
person.attributes.put("BMI Multiplier", 0.055);
person.setVitalSign(VitalSign.BMI, 21.0);
person.history = new LinkedList<>();
Provider mock = Mockito.mock(Provider.class);
Mockito.when(mock.getResourceID()).thenReturn("Mock-UUID");
person.setProvider(EncounterType.AMBULATORY, mock);
person.setProvider(EncounterType.WELLNESS, mock);
person.setProvider(EncounterType.EMERGENCY, mock);
person.setProvider(EncounterType.INPATIENT, mock);
Long time = System.currentTimeMillis();
int age = 35;
long birthTime = time - Utilities.convertTime("years", age);
person.attributes.put(Person.BIRTHDATE, birthTime);
Payer.loadNoInsurance();
for (int i = 0; i < age; i++) {
long yearTime = time - Utilities.convertTime("years", i);
person.coverage.setPayerAtTime(yearTime, Payer.noInsurance);
}
Module module = TestHelper.getFixture("observation.json");
State physiology = module.getState("Simulate_CVS");
assertTrue(physiology.process(person, time));
person.history.add(physiology);
State encounter = module.getState("SomeEncounter");
assertTrue(encounter.process(person, time));
person.history.add(encounter);
State chartState = module.getState("ChartObservation");
assertTrue(chartState.process(person, time));
person.history.add(chartState);
State urlState = module.getState("UrlObservation");
assertTrue(urlState.process(person, time));
person.history.add(urlState);
FhirContext ctx = FhirDstu2.getContext();
IParser parser = ctx.newJsonParser().setPrettyPrint(true);
String fhirJson = FhirDstu2.convertToFHIRJson(person, System.currentTimeMillis());
Bundle bundle = parser.parseResource(Bundle.class, fhirJson);
for (Entry entry : bundle.getEntry()) {
if (entry.getResource() instanceof Media) {
Media media = (Media) entry.getResource();
if (media.getContent().getData() != null) {
assertEquals(400, (int) media.getWidth());
assertEquals(200, (int) media.getHeight());
assertTrue(Base64.isBase64(media.getContent().getDataElement().getValueAsString()));
} else if (media.getContent().getUrl() != null) {
assertEquals("https://example.com/image/12498596132", media.getContent().getUrl());
assertEquals("en-US", media.getContent().getLanguage());
assertTrue(media.getContent().getSize() > 0);
} else {
fail("Invalid Media element in output JSON");
}
}
}
}
Aggregations