use of org.mitre.synthea.world.concepts.HealthRecord.Observation in project synthea by synthetichealth.
the class FhirR4 method convertToFHIR.
/**
* Convert the given Person into a FHIR Bundle of the Patient and the
* associated entries from their health record.
*
* @param person Person to generate the FHIR JSON for
* @param stopTime Time the simulation ended
* @return FHIR Bundle containing the Person's health record
*/
public static Bundle convertToFHIR(Person person, long stopTime) {
Bundle bundle = new Bundle();
if (TRANSACTION_BUNDLE) {
bundle.setType(BundleType.TRANSACTION);
} else {
bundle.setType(BundleType.COLLECTION);
}
BundleEntryComponent personEntry = basicInfo(person, bundle, stopTime);
for (Encounter encounter : person.record.encounters) {
BundleEntryComponent encounterEntry = encounter(person, personEntry, bundle, encounter);
for (HealthRecord.Entry condition : encounter.conditions) {
condition(person, personEntry, bundle, encounterEntry, condition);
}
for (HealthRecord.Allergy allergy : encounter.allergies) {
allergy(person, personEntry, bundle, encounterEntry, allergy);
}
for (Observation observation : encounter.observations) {
// Observation resources in v4 don't support Attachments
if (observation.value instanceof Attachment) {
media(person, personEntry, bundle, encounterEntry, observation);
} else {
observation(person, personEntry, bundle, encounterEntry, observation);
}
}
for (Procedure procedure : encounter.procedures) {
procedure(person, personEntry, bundle, encounterEntry, procedure);
}
for (HealthRecord.Device device : encounter.devices) {
device(person, personEntry, bundle, device);
}
for (HealthRecord.Supply supply : encounter.supplies) {
supplyDelivery(person, personEntry, bundle, supply, encounter);
}
for (Medication medication : encounter.medications) {
medicationRequest(person, personEntry, bundle, encounterEntry, medication);
}
for (HealthRecord.Entry immunization : encounter.immunizations) {
immunization(person, personEntry, bundle, encounterEntry, immunization);
}
for (Report report : encounter.reports) {
report(person, personEntry, bundle, encounterEntry, report);
}
for (CarePlan careplan : encounter.careplans) {
BundleEntryComponent careTeamEntry = careTeam(person, personEntry, bundle, encounterEntry, careplan);
carePlan(person, personEntry, bundle, encounterEntry, encounter.provider, careTeamEntry, careplan);
}
for (ImagingStudy imagingStudy : encounter.imagingStudies) {
imagingStudy(person, personEntry, bundle, encounterEntry, imagingStudy);
}
if (USE_US_CORE_IG) {
String clinicalNoteText = ClinicalNoteExporter.export(person, encounter);
boolean lastNote = (encounter == person.record.encounters.get(person.record.encounters.size() - 1));
clinicalNote(person, personEntry, bundle, encounterEntry, clinicalNoteText, lastNote);
}
// one claim per encounter
BundleEntryComponent encounterClaim = encounterClaim(person, personEntry, bundle, encounterEntry, encounter.claim);
explanationOfBenefit(personEntry, bundle, encounterEntry, person, encounterClaim, encounter);
}
if (USE_US_CORE_IG) {
// Add Provenance to the Bundle
provenance(bundle, person, stopTime);
}
return bundle;
}
use of org.mitre.synthea.world.concepts.HealthRecord.Observation in project synthea by synthetichealth.
the class FhirR4 method report.
/**
* Map the given Report to a FHIR DiagnosticReport resource, and add it to the given Bundle.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Entry for the Person
* @param bundle Bundle to add the Report to
* @param encounterEntry Current Encounter entry
* @param report The Report
* @return The added Entry
*/
private static BundleEntryComponent report(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Report report) {
DiagnosticReport reportResource = new DiagnosticReport();
if (USE_US_CORE_IG) {
Meta meta = new Meta();
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-diagnosticreport-lab");
reportResource.setMeta(meta);
org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
reportResource.addPerformer(encounterResource.getServiceProvider());
}
reportResource.setStatus(DiagnosticReportStatus.FINAL);
reportResource.addCategory(new CodeableConcept(new Coding("http://terminology.hl7.org/CodeSystem/v2-0074", "LAB", "Laboratory")));
reportResource.setCode(mapCodeToCodeableConcept(report.codes.get(0), LOINC_URI));
reportResource.setSubject(new Reference(personEntry.getFullUrl()));
reportResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
reportResource.setEffective(convertFhirDateTime(report.start, true));
reportResource.setIssued(new Date(report.start));
for (Observation observation : report.observations) {
Reference reference = new Reference(observation.fullUrl);
reference.setDisplay(observation.codes.get(0).display);
reportResource.addResult(reference);
}
return newEntry(rand, bundle, reportResource);
}
use of org.mitre.synthea.world.concepts.HealthRecord.Observation in project synthea by synthetichealth.
the class FhirR4 method observation.
/**
* Map the given Observation into a FHIR Observation resource, and add it to the given Bundle.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Person Entry
* @param bundle The Bundle to add to
* @param encounterEntry The current Encounter entry
* @param observation The Observation
* @return The added Entry
*/
private static BundleEntryComponent observation(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Observation observation) {
org.hl7.fhir.r4.model.Observation observationResource = new org.hl7.fhir.r4.model.Observation();
observationResource.setSubject(new Reference(personEntry.getFullUrl()));
observationResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
observationResource.setStatus(ObservationStatus.FINAL);
Code code = observation.codes.get(0);
observationResource.setCode(mapCodeToCodeableConcept(code, LOINC_URI));
// add extra codes, if there are any...
if (observation.codes.size() > 1) {
for (int i = 1; i < observation.codes.size(); i++) {
code = observation.codes.get(i);
Coding coding = new Coding();
coding.setCode(code.code);
coding.setDisplay(code.display);
coding.setSystem(LOINC_URI);
observationResource.getCode().addCoding(coding);
}
}
observationResource.addCategory().addCoding().setCode(observation.category).setSystem("http://terminology.hl7.org/CodeSystem/observation-category").setDisplay(observation.category);
if (observation.value != null) {
Type value = mapValueToFHIRType(observation.value, observation.unit);
observationResource.setValue(value);
} else if (observation.observations != null && !observation.observations.isEmpty()) {
// multi-observation (ex blood pressure)
for (Observation subObs : observation.observations) {
ObservationComponentComponent comp = new ObservationComponentComponent();
comp.setCode(mapCodeToCodeableConcept(subObs.codes.get(0), LOINC_URI));
Type value = mapValueToFHIRType(subObs.value, subObs.unit);
comp.setValue(value);
observationResource.addComponent(comp);
}
}
observationResource.setEffective(convertFhirDateTime(observation.start, true));
observationResource.setIssued(new Date(observation.start));
if (USE_US_CORE_IG) {
Meta meta = new Meta();
// add the specific profile based on code
String codeMappingUri = US_CORE_MAPPING.get(LOINC_URI, code.code);
if (codeMappingUri != null) {
meta.addProfile(codeMappingUri);
if (!codeMappingUri.contains("/us/core/") && observation.category.equals("vital-signs")) {
meta.addProfile("http://hl7.org/fhir/StructureDefinition/vitalsigns");
}
} else if (observation.report != null && observation.category.equals("laboratory")) {
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-observation-lab");
}
if (meta.hasProfile()) {
observationResource.setMeta(meta);
}
} else if (USE_SHR_EXTENSIONS) {
Meta meta = new Meta();
// all Observations are Observations
meta.addProfile(SHR_EXT + "shr-finding-Observation");
if ("vital-signs".equals(observation.category)) {
meta.addProfile(SHR_EXT + "shr-vital-VitalSign");
}
// add the specific profile based on code
String codeMappingUri = SHR_MAPPING.get(LOINC_URI, code.code);
if (codeMappingUri != null) {
meta.addProfile(codeMappingUri);
}
observationResource.setMeta(meta);
}
BundleEntryComponent entry = newEntry(rand, bundle, observationResource);
observation.fullUrl = entry.getFullUrl();
return entry;
}
use of org.mitre.synthea.world.concepts.HealthRecord.Observation in project synthea by synthetichealth.
the class FhirDstu2 method convertToFHIR.
/**
* Convert the given Person into a FHIR Bundle with the Patient and the
* associated entries from their health record.
*
* @param person Person to generate the FHIR Bundle
* @param stopTime Time the simulation ended
* @return String containing a FHIR Bundle containing the Person's health record
*/
public static Bundle convertToFHIR(Person person, long stopTime) {
Bundle bundle = new Bundle();
if (TRANSACTION_BUNDLE) {
bundle.setType(BundleTypeEnum.TRANSACTION);
} else {
bundle.setType(BundleTypeEnum.COLLECTION);
}
Entry personEntry = basicInfo(person, bundle, stopTime);
for (Encounter encounter : person.record.encounters) {
Entry encounterEntry = encounter(person, personEntry, bundle, encounter);
for (HealthRecord.Entry condition : encounter.conditions) {
condition(person, personEntry, bundle, encounterEntry, condition);
}
for (HealthRecord.Entry allergy : encounter.allergies) {
allergy(person, personEntry, bundle, encounterEntry, allergy);
}
for (Observation observation : encounter.observations) {
// Observation resources in stu3 don't support Attachments
if (observation.value instanceof Attachment) {
media(person, personEntry, bundle, encounterEntry, observation);
} else {
observation(person, personEntry, bundle, encounterEntry, observation);
}
}
for (Procedure procedure : encounter.procedures) {
procedure(person, personEntry, bundle, encounterEntry, procedure);
}
for (Medication medication : encounter.medications) {
medication(person, personEntry, bundle, encounterEntry, medication);
}
for (HealthRecord.Entry immunization : encounter.immunizations) {
immunization(person, personEntry, bundle, encounterEntry, immunization);
}
for (Report report : encounter.reports) {
report(person, personEntry, bundle, encounterEntry, report);
}
for (CarePlan careplan : encounter.careplans) {
careplan(person, personEntry, bundle, encounterEntry, careplan);
}
for (ImagingStudy imagingStudy : encounter.imagingStudies) {
imagingStudy(person, personEntry, bundle, encounterEntry, imagingStudy);
}
for (HealthRecord.Device device : encounter.devices) {
device(person, personEntry, bundle, device);
}
for (HealthRecord.Supply supply : encounter.supplies) {
supplyDelivery(person, personEntry, bundle, supply, encounter);
}
// one claim per encounter
encounterClaim(person, personEntry, bundle, encounterEntry, encounter.claim);
}
return bundle;
}
use of org.mitre.synthea.world.concepts.HealthRecord.Observation in project synthea by synthetichealth.
the class FhirDstu2 method report.
/**
* Map the given Report to a FHIR DiagnosticReport resource, and add it to the given Bundle.
*
* @param rand
* Source of randomness to use when generating ids etc
* @param personEntry
* The Entry for the Person
* @param bundle
* Bundle to add the Report to
* @param encounterEntry
* Current Encounter entry
* @param report
* The Report
* @return The added Entry
*/
private static Entry report(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Report report) {
DiagnosticReport reportResource = new DiagnosticReport();
reportResource.setStatus(DiagnosticReportStatusEnum.FINAL);
/*
* Technically, the CodeableConcept system should be "http://hl7.org/fhir/v2/0074"
* But the official Argonauts profiles incorrectly list the category pattern as
* the ValueSet (which contains the above system) as
* "http://hl7.org/fhir/ValueSet/diagnostic-service-sections", so we repeat the
* error here.
*/
CodeableConceptDt category = new CodeableConceptDt("http://hl7.org/fhir/ValueSet/diagnostic-service-sections", "LAB");
reportResource.setCategory(category);
reportResource.setCode(mapCodeToCodeableConcept(report.codes.get(0), LOINC_URI));
reportResource.setSubject(new ResourceReferenceDt(personEntry.getFullUrl()));
reportResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
reportResource.setEffective(convertFhirDateTime(report.start, true));
reportResource.setIssued(new InstantDt(new Date(report.start)));
ca.uhn.fhir.model.dstu2.resource.Encounter encounter = (ca.uhn.fhir.model.dstu2.resource.Encounter) encounterEntry.getResource();
reportResource.setPerformer(encounter.getServiceProvider());
for (Observation observation : report.observations) {
ResourceReferenceDt reference = new ResourceReferenceDt(observation.fullUrl);
reference.setDisplay(observation.codes.get(0).display);
List<ResourceReferenceDt> result = new ArrayList<ResourceReferenceDt>();
result.add(reference);
reportResource.setResult(result);
}
return newEntry(rand, bundle, reportResource);
}
Aggregations