use of org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy in project synthea by synthetichealth.
the class FhirR4 method imagingStudy.
/**
* Map the given ImagingStudy to a FHIR ImagingStudy 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 ImagingStudy to
* @param encounterEntry Current Encounter entry
* @param imagingStudy The ImagingStudy to map to FHIR and add to the bundle
* @return The added Entry
*/
private static BundleEntryComponent imagingStudy(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, ImagingStudy imagingStudy) {
org.hl7.fhir.r4.model.ImagingStudy imagingStudyResource = new org.hl7.fhir.r4.model.ImagingStudy();
imagingStudyResource.addIdentifier(generateIdentifier(imagingStudy.dicomUid));
imagingStudyResource.setStatus(ImagingStudyStatus.AVAILABLE);
imagingStudyResource.setSubject(new Reference(personEntry.getFullUrl()));
imagingStudyResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
if (USE_US_CORE_IG) {
org.hl7.fhir.r4.model.Encounter encounterResource = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
imagingStudyResource.setLocation(encounterResource.getLocationFirstRep().getLocation());
}
if (!imagingStudy.codes.isEmpty()) {
imagingStudyResource.addProcedureCode(mapCodeToCodeableConcept(imagingStudy.codes.get(0), SNOMED_URI));
}
Date startDate = new Date(imagingStudy.start);
imagingStudyResource.setStarted(startDate);
// Convert the series into their FHIR equivalents
int numberOfSeries = imagingStudy.series.size();
imagingStudyResource.setNumberOfSeries(numberOfSeries);
List<ImagingStudySeriesComponent> seriesResourceList = new ArrayList<ImagingStudySeriesComponent>();
int totalNumberOfInstances = 0;
int seriesNo = 1;
for (ImagingStudy.Series series : imagingStudy.series) {
ImagingStudySeriesComponent seriesResource = new ImagingStudySeriesComponent();
seriesResource.setUid(series.dicomUid);
seriesResource.setNumber(seriesNo);
seriesResource.setStarted(startDate);
CodeableConcept modalityConcept = mapCodeToCodeableConcept(series.modality, DICOM_DCM_URI);
seriesResource.setModality(modalityConcept.getCoding().get(0));
CodeableConcept bodySiteConcept = mapCodeToCodeableConcept(series.bodySite, SNOMED_URI);
seriesResource.setBodySite(bodySiteConcept.getCoding().get(0));
// Convert the images in each series into their FHIR equivalents
int numberOfInstances = series.instances.size();
seriesResource.setNumberOfInstances(numberOfInstances);
totalNumberOfInstances += numberOfInstances;
List<ImagingStudySeriesInstanceComponent> instanceResourceList = new ArrayList<ImagingStudySeriesInstanceComponent>();
int instanceNo = 1;
for (ImagingStudy.Instance instance : series.instances) {
ImagingStudySeriesInstanceComponent instanceResource = new ImagingStudySeriesInstanceComponent();
instanceResource.setUid(instance.dicomUid);
instanceResource.setTitle(instance.title);
instanceResource.setSopClass(new Coding().setCode(instance.sopClass.code).setSystem("urn:ietf:rfc:3986"));
instanceResource.setNumber(instanceNo);
instanceResourceList.add(instanceResource);
instanceNo += 1;
}
seriesResource.setInstance(instanceResourceList);
seriesResourceList.add(seriesResource);
seriesNo += 1;
}
imagingStudyResource.setSeries(seriesResourceList);
imagingStudyResource.setNumberOfInstances(totalNumberOfInstances);
return newEntry(rand, bundle, imagingStudyResource);
}
use of org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy 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.ImagingStudy 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.ImagingStudy in project synthea by synthetichealth.
the class FhirStu3 method imagingStudy.
/**
* Map the given ImagingStudy to a FHIR ImagingStudy 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 ImagingStudy to
* @param encounterEntry Current Encounter entry
* @param imagingStudy The ImagingStudy to map to FHIR and add to the bundle
* @return The added Entry
*/
private static BundleEntryComponent imagingStudy(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, ImagingStudy imagingStudy) {
org.hl7.fhir.dstu3.model.ImagingStudy imagingStudyResource = new org.hl7.fhir.dstu3.model.ImagingStudy();
imagingStudyResource.setUid("urn:oid:" + imagingStudy.dicomUid);
imagingStudyResource.setPatient(new Reference(personEntry.getFullUrl()));
imagingStudyResource.setContext(new Reference(encounterEntry.getFullUrl()));
if (!imagingStudy.codes.isEmpty()) {
imagingStudyResource.addProcedureCode(mapCodeToCodeableConcept(imagingStudy.codes.get(0), SNOMED_URI));
}
Date startDate = new Date(imagingStudy.start);
imagingStudyResource.setStarted(startDate);
// Convert the series into their FHIR equivalents
int numberOfSeries = imagingStudy.series.size();
imagingStudyResource.setNumberOfSeries(numberOfSeries);
List<ImagingStudySeriesComponent> seriesResourceList = new ArrayList<ImagingStudySeriesComponent>();
int totalNumberOfInstances = 0;
int seriesNo = 1;
for (ImagingStudy.Series series : imagingStudy.series) {
ImagingStudySeriesComponent seriesResource = new ImagingStudySeriesComponent();
seriesResource.setUid("urn:oid:" + series.dicomUid);
seriesResource.setNumber(seriesNo);
seriesResource.setStarted(startDate);
seriesResource.setAvailability(InstanceAvailability.UNAVAILABLE);
CodeableConcept modalityConcept = mapCodeToCodeableConcept(series.modality, DICOM_DCM_URI);
seriesResource.setModality(modalityConcept.getCoding().get(0));
CodeableConcept bodySiteConcept = mapCodeToCodeableConcept(series.bodySite, SNOMED_URI);
seriesResource.setBodySite(bodySiteConcept.getCoding().get(0));
// Convert the images in each series into their FHIR equivalents
int numberOfInstances = series.instances.size();
seriesResource.setNumberOfInstances(numberOfInstances);
totalNumberOfInstances += numberOfInstances;
List<ImagingStudySeriesInstanceComponent> instanceResourceList = new ArrayList<ImagingStudySeriesInstanceComponent>();
int instanceNo = 1;
for (ImagingStudy.Instance instance : series.instances) {
ImagingStudySeriesInstanceComponent instanceResource = new ImagingStudySeriesInstanceComponent();
instanceResource.setUid("urn:oid:" + instance.dicomUid);
instanceResource.setTitle(instance.title);
instanceResource.setSopClass("urn:oid:" + instance.sopClass.code);
instanceResource.setNumber(instanceNo);
instanceResourceList.add(instanceResource);
instanceNo += 1;
}
seriesResource.setInstance(instanceResourceList);
seriesResourceList.add(seriesResource);
seriesNo += 1;
}
imagingStudyResource.setSeries(seriesResourceList);
imagingStudyResource.setNumberOfInstances(totalNumberOfInstances);
return newEntry(rand, bundle, imagingStudyResource);
}
use of org.mitre.synthea.world.concepts.HealthRecord.ImagingStudy in project synthea by synthetichealth.
the class TextExporter method exportAll.
/**
* Produce and export a person's record in the text format.
*
* @param person Person to export
* @param fileTag Tag to add to the filename
* @param time Time the simulation ended
* @throws IOException if any error occurs writing to the standard export location
*/
public static void exportAll(Person person, String fileTag, long time) throws IOException {
List<Encounter> encounters = person.record.encounters;
List<Entry> conditions = new ArrayList<>();
List<Entry> allergies = new ArrayList<>();
List<Report> reports = new ArrayList<>();
List<Observation> observations = new ArrayList<>();
List<Procedure> procedures = new ArrayList<>();
List<Medication> medications = new ArrayList<>();
List<Entry> immunizations = new ArrayList<>();
List<CarePlan> careplans = new ArrayList<>();
List<ImagingStudy> imagingStudies = new ArrayList<>();
for (Encounter encounter : person.record.encounters) {
conditions.addAll(encounter.conditions);
allergies.addAll(encounter.allergies);
reports.addAll(encounter.reports);
observations.addAll(encounter.observations);
procedures.addAll(encounter.procedures);
medications.addAll(encounter.medications);
immunizations.addAll(encounter.immunizations);
careplans.addAll(encounter.careplans);
imagingStudies.addAll(encounter.imagingStudies);
}
// reverse these items so they are displayed in reverse chrono order
Collections.reverse(encounters);
Collections.reverse(conditions);
Collections.reverse(allergies);
Collections.reverse(reports);
Collections.reverse(observations);
Collections.reverse(procedures);
Collections.reverse(medications);
Collections.reverse(immunizations);
Collections.reverse(careplans);
Collections.reverse(imagingStudies);
// now we finally start writing things
List<String> textRecord = new LinkedList<>();
basicInfo(textRecord, person, time);
breakline(textRecord);
textRecord.add("ALLERGIES:");
if (allergies.isEmpty()) {
textRecord.add("No Known Allergies");
} else {
for (Entry allergy : allergies) {
condition(textRecord, allergy, true);
}
}
breakline(textRecord);
textRecord.add("MEDICATIONS:");
for (Medication medication : medications) {
medication(textRecord, medication, true);
}
breakline(textRecord);
textRecord.add("CONDITIONS:");
for (Entry condition : conditions) {
condition(textRecord, condition, true);
}
breakline(textRecord);
textRecord.add("CARE PLANS:");
for (CarePlan careplan : careplans) {
careplan(textRecord, careplan, true);
}
breakline(textRecord);
textRecord.add("REPORTS:");
for (Report report : reports) {
diagnosticReport(textRecord, report);
}
breakline(textRecord);
textRecord.add("OBSERVATIONS:");
for (Observation observation : observations) {
observation(textRecord, observation);
}
breakline(textRecord);
textRecord.add("PROCEDURES:");
for (Procedure procedure : procedures) {
procedure(textRecord, procedure);
}
breakline(textRecord);
textRecord.add("IMMUNIZATIONS:");
for (Entry immunization : immunizations) {
immunization(textRecord, immunization);
}
breakline(textRecord);
textRecord.add("ENCOUNTERS:");
for (Encounter encounter : encounters) {
encounter(textRecord, encounter);
}
breakline(textRecord);
textRecord.add("IMAGING STUDIES:");
for (ImagingStudy imagingStudy : imagingStudies) {
imagingStudy(textRecord, imagingStudy);
}
breakline(textRecord);
// finally write to the file
File outDirectory = Exporter.getOutputFolder("text", person);
Path outFilePath = outDirectory.toPath().resolve(Exporter.filename(person, fileTag, "txt"));
Files.write(outFilePath, textRecord, StandardOpenOption.CREATE_NEW);
}
Aggregations