use of org.mitre.synthea.world.concepts.HealthRecord.Report in project synthea by synthetichealth.
the class HealthRecordTest method testReportAllObs.
@Test
public void testReportAllObs() {
Person person = new Person(0L);
person.coverage.setPayerAtTime(time, noInsurance);
HealthRecord record = new HealthRecord(person);
Encounter encounter = record.encounterStart(time, EncounterType.WELLNESS);
record.observation(time, "A", "A");
record.observation(time, "B", "B");
record.observation(time, "C", "C");
Report report = record.report(time, "R", 3);
Assert.assertEquals(3, encounter.observations.size());
Assert.assertEquals(3, report.observations.size());
Assert.assertEquals("A", report.observations.get(0).value);
Assert.assertEquals("B", report.observations.get(1).value);
Assert.assertEquals("C", report.observations.get(2).value);
}
use of org.mitre.synthea.world.concepts.HealthRecord.Report 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.Report 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.Report in project synthea by synthetichealth.
the class Exporter method filterForExport.
/**
* Filter the health record to only the last __ years
* but also include relevant history from before that. Exclude
* any history that occurs after the specified end_time -- typically
* this is the current time/System.currentTimeMillis().
*
* @param record The record to filter.
* @param yearsToKeep The last __ years to keep.
* @param endTime The time the history ends.
* @return Modified record with history expunged.
*/
private static HealthRecord filterForExport(HealthRecord record, int yearsToKeep, long endTime) {
long cutoffDate = endTime - Utilities.convertTime("years", yearsToKeep);
Predicate<HealthRecord.Entry> notFutureDated = e -> e.start <= endTime;
for (Encounter encounter : record.encounters) {
List<Claim.ClaimEntry> claimItems = encounter.claim.items;
// keep conditions if still active, regardless of start date
Predicate<HealthRecord.Entry> conditionActive = c -> record.conditionActive(c.type);
// or if the condition was active at any point since the cutoff date
Predicate<HealthRecord.Entry> activeWithinCutoff = c -> c.stop != 0L && c.stop > cutoffDate;
Predicate<HealthRecord.Entry> keepCondition = conditionActive.or(activeWithinCutoff);
filterEntries(encounter.conditions, claimItems, cutoffDate, endTime, keepCondition);
// allergies are essentially the same as conditions
// But we need to redefine all of the predicates, because we are talking about Allergies as
// opposed to Entries... You would think that it would work... but generics are hard
Predicate<HealthRecord.Allergy> allergyActive = c -> record.allergyActive(c.type);
// or if the condition was active at any point since the cutoff date
Predicate<HealthRecord.Allergy> allergyActiveWithinCutoff = c -> c.stop != 0L && c.stop > cutoffDate;
Predicate<HealthRecord.Allergy> keepAllergy = allergyActive.or(allergyActiveWithinCutoff);
filterEntries(encounter.allergies, claimItems, cutoffDate, endTime, keepAllergy);
// some of the "future death" logic could potentially add a future-dated death certificate
Predicate<Observation> isCauseOfDeath = o -> DeathModule.CAUSE_OF_DEATH_CODE.code.equals(o.type);
// keep cause of death unless it's future dated
Predicate<Observation> keepObservation = isCauseOfDeath.and(notFutureDated);
filterEntries(encounter.observations, claimItems, cutoffDate, endTime, keepObservation);
// keep all death certificates, unless they are future-dated
Predicate<Report> isDeathCertificate = r -> DeathModule.DEATH_CERTIFICATE.code.equals(r.type);
Predicate<Report> keepReport = isDeathCertificate.and(notFutureDated);
filterEntries(encounter.reports, claimItems, cutoffDate, endTime, keepReport);
filterEntries(encounter.procedures, claimItems, cutoffDate, endTime, null);
// keep medications if still active, regardless of start date
filterEntries(encounter.medications, claimItems, cutoffDate, endTime, med -> record.medicationActive(med.type));
filterEntries(encounter.immunizations, claimItems, cutoffDate, endTime, null);
// keep careplans if they are still active, regardless of start date
filterEntries(encounter.careplans, claimItems, cutoffDate, endTime, cp -> record.careplanActive(cp.type));
}
// if ANY of these are not empty, the encounter is not empty
Predicate<Encounter> encounterNotEmpty = e -> !e.conditions.isEmpty() || !e.allergies.isEmpty() || !e.observations.isEmpty() || !e.reports.isEmpty() || !e.procedures.isEmpty() || !e.medications.isEmpty() || !e.immunizations.isEmpty() || !e.careplans.isEmpty();
Predicate<Encounter> isDeathCertification = e -> !e.codes.isEmpty() && DeathModule.DEATH_CERTIFICATION.equals(e.codes.get(0));
Predicate<Encounter> keepEncounter = encounterNotEmpty.or(isDeathCertification.and(notFutureDated));
// finally filter out any empty encounters
filterEntries(record.encounters, Collections.emptyList(), cutoffDate, endTime, keepEncounter);
return record;
}
use of org.mitre.synthea.world.concepts.HealthRecord.Report in project synthea by synthetichealth.
the class DeathModuleTest method testDeathCertificate.
@Test
public void testDeathCertificate() {
/*
* death_certificate: { description: 'U.S. standard certificate of death - 2003 revision', code:
* '69409-1' }, cause_of_death: { description: 'Cause of Death [US Standard Certificate of
* Death]', code: '69453-9', value_type: 'condition' },
*
* death_certification: {description: 'Death Certification', codes: {'SNOMED-CT' =>
* ['308646001']}, class: 'ambulatory'}
*/
Code causeOfDeath = new Code("SNOMED-CT", "12345", "Some disease");
person.recordDeath(time, causeOfDeath);
DeathModule.process(person, time);
Encounter enc = person.record.encounters.get(0);
assertEquals(EncounterType.WELLNESS.toString(), enc.type);
assertEquals(time, enc.start);
Code code = enc.codes.get(0);
assertEquals("308646001", code.code);
assertEquals("Death Certification", code.display);
Report report = enc.reports.get(0);
assertEquals("69409-1", report.type);
assertEquals(time, report.start);
code = report.codes.get(0);
assertEquals("69409-1", code.code);
assertEquals("U.S. standard certificate of death - 2003 revision", code.display);
Observation obs = report.observations.get(0);
assertEquals("69453-9", obs.type);
assertEquals(time, obs.start);
code = (Code) obs.value;
assertEquals(causeOfDeath.code, code.code);
assertEquals(causeOfDeath.display, code.display);
code = obs.codes.get(0);
assertEquals("69453-9", code.code);
assertEquals("Cause of Death [US Standard Certificate of Death]", code.display);
}
Aggregations