use of org.mitre.synthea.world.concepts.HealthRecord.Encounter 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);
}
use of org.mitre.synthea.world.concepts.HealthRecord.Encounter in project synthea by synthetichealth.
the class FhirDstu2 method encounter.
/**
* Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
*
* @param person
* Patient at the encounter.
* @param personEntry
* Entry for the Person
* @param bundle
* The Bundle to add to
* @param encounter
* The current Encounter
* @return The added Entry
*/
private static Entry encounter(Person person, Entry personEntry, Bundle bundle, Encounter encounter) {
ca.uhn.fhir.model.dstu2.resource.Encounter encounterResource = new ca.uhn.fhir.model.dstu2.resource.Encounter();
encounterResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
encounterResource.setStatus(EncounterStateEnum.FINISHED);
if (encounter.codes.isEmpty()) {
// wellness encounter
encounterResource.addType().addCoding().setCode("185349003").setDisplay("Encounter for check up").setSystem(SNOMED_URI);
} else {
Code code = encounter.codes.get(0);
encounterResource.addType(mapCodeToCodeableConcept(code, SNOMED_URI));
}
EncounterClassEnum encounterClass = EncounterClassEnum.forCode(encounter.type);
if (encounterClass == null) {
encounterClass = EncounterClassEnum.AMBULATORY;
}
encounterResource.setClassElement(encounterClass);
encounterResource.setPeriod(new PeriodDt().setStart(new DateTimeDt(new Date(encounter.start))).setEnd(new DateTimeDt(new Date(encounter.stop))));
if (encounter.reason != null) {
encounterResource.addReason().addCoding().setCode(encounter.reason.code).setDisplay(encounter.reason.display).setSystem(SNOMED_URI);
}
Provider provider = encounter.provider;
if (provider == null) {
// no associated provider, patient goes to wellness provider
provider = person.getProvider(EncounterType.WELLNESS, encounter.start);
}
if (TRANSACTION_BUNDLE) {
encounterResource.setServiceProvider(new ResourceReferenceDt(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
} else {
String providerFullUrl = findProviderUrl(provider, bundle);
if (providerFullUrl != null) {
encounterResource.setServiceProvider(new ResourceReferenceDt(providerFullUrl));
} else {
Entry providerOrganization = provider(bundle, provider);
encounterResource.setServiceProvider(new ResourceReferenceDt(providerOrganization.getFullUrl()));
}
}
encounterResource.getServiceProvider().setDisplay(provider.name);
if (encounter.clinician != null) {
if (TRANSACTION_BUNDLE) {
encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
} else {
String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
if (practitionerFullUrl != null) {
encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(practitionerFullUrl));
} else {
Entry practitioner = practitioner(bundle, encounter.clinician);
encounterResource.addParticipant().setIndividual(new ResourceReferenceDt(practitioner.getFullUrl()));
}
}
encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
}
if (encounter.discharge != null) {
Hospitalization hospitalization = new Hospitalization();
Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
encounterResource.setHospitalization(hospitalization);
}
return newEntry(person, bundle, encounterResource);
}
use of org.mitre.synthea.world.concepts.HealthRecord.Encounter in project synthea by synthetichealth.
the class CPCDSExporter method export.
/**
* Add a single Person's health record info to the CSV records.
*
* @param person Person to write record data for
* @param time Time the simulation ended
* @throws IOException if any IO error occurs
*/
public void export(Person person, long time) throws IOException {
String personID = patient(person, time);
String payerId = "";
String payerName = "";
String type = COVERAGE_TYPES[(int) randomLongWithBounds(0, COVERAGE_TYPES.length - 1)];
int groupSelect = (int) randomLongWithBounds(0, GROUPIDS.length - 1);
UUID groupId = GROUPIDS[groupSelect];
String groupName = GROUP_NAMES[groupSelect];
int planSelect = (int) randomLongWithBounds(0, PLAN_NAMES.length - 1);
String planName = PLAN_NAMES[planSelect];
String planId = PLAN_IDS[planSelect];
long start = 999999999999999999L;
long end = 0;
for (Encounter encounter : person.record.encounters) {
String encounterID = person.randUUID().toString();
UUID medRecordNumber = person.randUUID();
CPCDSAttributes encounterAttributes = new CPCDSAttributes(encounter);
if (Config.getAsBoolean("exporter.cpcds.single_payer")) {
payerId = "b1c428d6-4f07-31e0-90f0-68ffa6ff8c76";
payerName = clean(Config.get("single_payer.name"));
} else {
payerId = encounter.claim.payer.uuid.toString();
payerName = encounter.claim.payer.getName();
}
for (CarePlan careplan : encounter.careplans) {
if (careplan.start < start) {
start = careplan.start;
}
if (careplan.stop > end) {
end = careplan.stop;
}
}
if (start == 999999999999999999L) {
start = end;
}
String coverageID = coverage(person, personID, start, end, payerId, type, groupId, groupName, planName, planId);
claim(person, encounter, personID, encounterID, medRecordNumber, encounterAttributes, payerId, coverageID);
hospital(encounter, encounterAttributes, payerName);
}
patients.flush();
coverages.flush();
claims.flush();
practitioners.flush();
hospitals.flush();
}
use of org.mitre.synthea.world.concepts.HealthRecord.Encounter 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);
}
use of org.mitre.synthea.world.concepts.HealthRecord.Encounter in project synthea by synthetichealth.
the class CodeResolveAndExportTest method resolveAndExportEncounterCodes.
@Test
public void resolveAndExportEncounterCodes() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException {
Encounter encounter = person.encounterStart(time, EncounterType.EMERGENCY);
String reasonCode = "417981005";
String reasonDisplay = "Exposure to blood and/or body fluid";
encounter.reason = new Code(SNOMED_URI, reasonCode, reasonDisplay);
encounter.reason.valueSet = SNOMED_URI + "?fhir_vs=ecl/<418307001";
encounter.codes.add(encounter.reason);
String observationDisplay = OBSERVATION_DISPLAY;
Code observationType = new Code(LOINC_URI, OBSERVATION_CODE, observationDisplay);
String observationValueCode = "LA14088-1";
String observationValueDisplay = "Sports or recreational area";
Code observationValue = new Code(LOINC_URI, observationValueCode, observationValueDisplay);
observationValue.valueSet = "http://loinc.org/vs/LL1051-3";
encounter.addObservation(time, observationType.code, observationValue, observationDisplay);
Exporter.export(person, time);
verifyEncounterCodeStu3();
verifyEncounterCodeR4();
verifyEncounterCodeDstu2();
verifyEncounterCodeCcda();
}
Aggregations