use of org.mitre.synthea.world.concepts.HealthRecord.Encounter in project synthea by synthetichealth.
the class FhirR4 method media.
/**
* Map the given Observation with attachment element to a FHIR Media 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 Media to
* @param encounterEntry Current Encounter entry
* @param obs The Observation to map to FHIR and add to the bundle
* @return The added Entry
*/
private static BundleEntryComponent media(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Observation obs) {
org.hl7.fhir.r4.model.Media mediaResource = new org.hl7.fhir.r4.model.Media();
// Hard code as Image since we don't anticipate using video or audio any time soon
Code mediaType = new Code("http://terminology.hl7.org/CodeSystem/media-type", "image", "Image");
if (obs.codes != null && obs.codes.size() > 0) {
List<CodeableConcept> reasonList = obs.codes.stream().map(code -> mapCodeToCodeableConcept(code, SNOMED_URI)).collect(Collectors.toList());
mediaResource.setReasonCode(reasonList);
}
mediaResource.setType(mapCodeToCodeableConcept(mediaType, MEDIA_TYPE_URI));
mediaResource.setStatus(MediaStatus.COMPLETED);
mediaResource.setSubject(new Reference(personEntry.getFullUrl()));
mediaResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
Attachment content = (Attachment) obs.value;
org.hl7.fhir.r4.model.Attachment contentResource = new org.hl7.fhir.r4.model.Attachment();
contentResource.setContentType(content.contentType);
contentResource.setLanguage(content.language);
if (content.data != null) {
contentResource.setDataElement(new org.hl7.fhir.r4.model.Base64BinaryType(content.data));
} else {
contentResource.setSize(content.size);
}
contentResource.setUrl(content.url);
contentResource.setTitle(content.title);
if (content.hash != null) {
contentResource.setHashElement(new org.hl7.fhir.r4.model.Base64BinaryType(content.hash));
}
mediaResource.setWidth(content.width);
mediaResource.setHeight(content.height);
mediaResource.setContent(contentResource);
return newEntry(rand, bundle, mediaResource);
}
use of org.mitre.synthea.world.concepts.HealthRecord.Encounter in project synthea by synthetichealth.
the class FhirR4 method clinicalNote.
/**
* Add a clinical note to the Bundle, which adds both a DocumentReference and a
* DiagnosticReport.
*
* @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 clinicalNoteText The plain text contents of the note.
* @param currentNote If this is the most current note.
* @return The entry for the DocumentReference.
*/
private static BundleEntryComponent clinicalNote(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, String clinicalNoteText, boolean currentNote) {
// We'll need the encounter...
org.hl7.fhir.r4.model.Encounter encounter = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
// Add a DiagnosticReport
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-note");
reportResource.setMeta(meta);
}
reportResource.setStatus(DiagnosticReportStatus.FINAL);
reportResource.addCategory(new CodeableConcept(new Coding(LOINC_URI, "34117-2", "History and physical note")));
reportResource.getCategoryFirstRep().addCoding(new Coding(LOINC_URI, "51847-2", "Evaluation+Plan note"));
reportResource.setCode(reportResource.getCategoryFirstRep());
reportResource.setSubject(new Reference(personEntry.getFullUrl()));
reportResource.setEncounter(new Reference(encounterEntry.getFullUrl()));
reportResource.setEffective(encounter.getPeriod().getStartElement());
reportResource.setIssued(encounter.getPeriod().getStart());
if (encounter.hasParticipant()) {
reportResource.addPerformer(encounter.getParticipantFirstRep().getIndividual());
} else {
reportResource.addPerformer(encounter.getServiceProvider());
}
reportResource.addPresentedForm().setContentType("text/plain; charset=utf-8").setData(clinicalNoteText.getBytes(java.nio.charset.StandardCharsets.UTF_8));
newEntry(rand, bundle, reportResource);
// Add a DocumentReference
DocumentReference documentReference = new DocumentReference();
if (USE_US_CORE_IG) {
Meta meta = new Meta();
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-documentreference");
documentReference.setMeta(meta);
}
if (currentNote) {
documentReference.setStatus(DocumentReferenceStatus.CURRENT);
} else {
documentReference.setStatus(DocumentReferenceStatus.SUPERSEDED);
}
documentReference.addIdentifier().setSystem("urn:ietf:rfc:3986").setValue("urn:uuid:" + reportResource.getId());
documentReference.setType(reportResource.getCategoryFirstRep());
documentReference.addCategory(new CodeableConcept(new Coding("http://hl7.org/fhir/us/core/CodeSystem/us-core-documentreference-category", "clinical-note", "Clinical Note")));
documentReference.setSubject(new Reference(personEntry.getFullUrl()));
documentReference.setDate(encounter.getPeriod().getStart());
documentReference.addAuthor(reportResource.getPerformerFirstRep());
documentReference.setCustodian(encounter.getServiceProvider());
documentReference.addContent().setAttachment(reportResource.getPresentedFormFirstRep()).setFormat(new Coding("http://ihe.net/fhir/ValueSet/IHE.FormatCode.codesystem", "urn:ihe:iti:xds:2017:mimeTypeSufficient", "mimeType Sufficient"));
documentReference.setContext(new DocumentReferenceContextComponent().addEncounter(reportResource.getEncounter()).setPeriod(encounter.getPeriod()));
return newEntry(rand, bundle, documentReference);
}
use of org.mitre.synthea.world.concepts.HealthRecord.Encounter in project synthea by synthetichealth.
the class FhirStu3 method encounter.
/**
* Map the given Encounter into a FHIR Encounter resource, and add it to the given Bundle.
*
* @param personEntry Entry for the Person
* @param bundle The Bundle to add to
* @param encounter The current Encounter
* @return The added Entry
*/
private static BundleEntryComponent encounter(Person person, BundleEntryComponent personEntry, Bundle bundle, Encounter encounter) {
org.hl7.fhir.dstu3.model.Encounter encounterResource = new org.hl7.fhir.dstu3.model.Encounter();
encounterResource.setSubject(new Reference(personEntry.getFullUrl()));
encounterResource.setStatus(EncounterStatus.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));
}
Coding classCode = new Coding();
classCode.setCode(EncounterType.fromString(encounter.type).code());
classCode.setSystem("http://terminology.hl7.org/CodeSystem/v3-ActCode");
encounterResource.setClass_(classCode);
encounterResource.setPeriod(new Period().setStart(new Date(encounter.start)).setEnd(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 Reference(ExportHelper.buildFhirSearchUrl("Organization", provider.getResourceID())));
} else {
String providerFullUrl = findProviderUrl(provider, bundle);
if (providerFullUrl != null) {
encounterResource.setServiceProvider(new Reference(providerFullUrl));
} else {
BundleEntryComponent providerOrganization = provider(bundle, provider);
encounterResource.setServiceProvider(new Reference(providerOrganization.getFullUrl()));
}
}
encounterResource.getServiceProvider().setDisplay(provider.name);
if (encounter.clinician != null) {
if (TRANSACTION_BUNDLE) {
encounterResource.addParticipant().setIndividual(new Reference(ExportHelper.buildFhirNpiSearchUrl(encounter.clinician)));
} else {
String practitionerFullUrl = findPractitioner(encounter.clinician, bundle);
if (practitionerFullUrl != null) {
encounterResource.addParticipant().setIndividual(new Reference(practitionerFullUrl));
} else {
BundleEntryComponent practitioner = practitioner(bundle, encounter.clinician);
encounterResource.addParticipant().setIndividual(new Reference(practitioner.getFullUrl()));
}
}
encounterResource.getParticipantFirstRep().getIndividual().setDisplay(encounter.clinician.getFullname());
}
if (encounter.discharge != null) {
EncounterHospitalizationComponent hospitalization = new EncounterHospitalizationComponent();
Code dischargeDisposition = new Code(DISCHARGE_URI, encounter.discharge.code, encounter.discharge.display);
hospitalization.setDischargeDisposition(mapCodeToCodeableConcept(dischargeDisposition, DISCHARGE_URI));
encounterResource.setHospitalization(hospitalization);
}
if (USE_SHR_EXTENSIONS) {
encounterResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-encounter-EncounterPerformed"));
// required fields for this profile are status & action-PerformedContext-extension
Extension performedContext = new Extension();
performedContext.setUrl(SHR_EXT + "shr-action-PerformedContext-extension");
performedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("finished"));
encounterResource.addExtension(performedContext);
}
return newEntry(person, bundle, encounterResource);
}
use of org.mitre.synthea.world.concepts.HealthRecord.Encounter in project synthea by synthetichealth.
the class FhirStu3 method medication.
/**
* Map the given Medication to a FHIR MedicationRequest 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 Medication to
* @param encounterEntry Current Encounter entry
* @param medication The Medication
* @return The added Entry
*/
private static BundleEntryComponent medication(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Medication medication) {
MedicationRequest medicationResource = new MedicationRequest();
medicationResource.setSubject(new Reference(personEntry.getFullUrl()));
medicationResource.setContext(new Reference(encounterEntry.getFullUrl()));
Code code = medication.codes.get(0);
String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;
medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
medicationResource.setAuthoredOn(new Date(medication.start));
medicationResource.setIntent(MedicationRequestIntent.ORDER);
org.hl7.fhir.dstu3.model.Encounter encounter = (org.hl7.fhir.dstu3.model.Encounter) encounterEntry.getResource();
MedicationRequestRequesterComponent requester = new MedicationRequestRequesterComponent();
requester.setAgent(encounter.getParticipantFirstRep().getIndividual());
requester.setOnBehalfOf(encounter.getServiceProvider());
medicationResource.setRequester(requester);
if (medication.stop != 0L) {
medicationResource.setStatus(MedicationRequestStatus.STOPPED);
} else {
medicationResource.setStatus(MedicationRequestStatus.ACTIVE);
}
if (!medication.reasons.isEmpty()) {
// Only one element in list
Code reason = medication.reasons.get(0);
for (BundleEntryComponent entry : bundle.getEntry()) {
if (entry.getResource().fhirType().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
Coding coding = condition.getCode().getCoding().get(0);
if (reason.code.equals(coding.getCode())) {
medicationResource.addReasonReference().setReference(entry.getFullUrl());
}
}
}
}
if (medication.prescriptionDetails != null) {
JsonObject rxInfo = medication.prescriptionDetails;
Dosage dosage = new Dosage();
dosage.setSequence(1);
// as_needed is true if present
dosage.setAsNeeded(new BooleanType(rxInfo.has("as_needed")));
// as_needed is true if present
if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
Timing timing = new Timing();
TimingRepeatComponent timingRepeatComponent = new TimingRepeatComponent();
timingRepeatComponent.setFrequency(rxInfo.get("dosage").getAsJsonObject().get("frequency").getAsInt());
timingRepeatComponent.setPeriod(rxInfo.get("dosage").getAsJsonObject().get("period").getAsDouble());
timingRepeatComponent.setPeriodUnit(convertUcumCode(rxInfo.get("dosage").getAsJsonObject().get("unit").getAsString()));
timing.setRepeat(timingRepeatComponent);
dosage.setTiming(timing);
Quantity dose = new SimpleQuantity().setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
dosage.setDose(dose);
if (rxInfo.has("instructions")) {
for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
JsonObject instruction = instructionElement.getAsJsonObject();
Code instructionCode = new Code(SNOMED_URI, instruction.get("code").getAsString(), instruction.get("display").getAsString());
dosage.addAdditionalInstruction(mapCodeToCodeableConcept(instructionCode, SNOMED_URI));
}
}
}
List<Dosage> dosageInstruction = new ArrayList<Dosage>();
dosageInstruction.add(dosage);
medicationResource.setDosageInstruction(dosageInstruction);
}
if (USE_SHR_EXTENSIONS) {
medicationResource.addExtension().setUrl(SHR_EXT + "shr-base-ActionCode-extension").setValue(PRESCRIPTION_OF_DRUG_CC);
medicationResource.setMeta(new Meta().addProfile(SHR_EXT + "shr-medication-MedicationRequested"));
// required fields for this profile are status, action-RequestedContext-extension,
// medication[x]subject, authoredOn, requester
Extension requestedContext = new Extension();
requestedContext.setUrl(SHR_EXT + "shr-action-RequestedContext-extension");
requestedContext.addExtension(SHR_EXT + "shr-action-Status-extension", new CodeType("completed"));
requestedContext.addExtension(SHR_EXT + "shr-action-RequestIntent-extension", new CodeType("original-order"));
medicationResource.addExtension(requestedContext);
}
BundleEntryComponent medicationEntry = newEntry(rand, bundle, medicationResource);
// create new claim for medication
medicationClaim(rand, personEntry, bundle, encounterEntry, medication.claim, medicationEntry);
// Create new administration for medication, if needed
if (medication.administration) {
medicationAdministration(rand, personEntry, bundle, encounterEntry, medication, medicationResource);
}
return medicationEntry;
}
use of org.mitre.synthea.world.concepts.HealthRecord.Encounter in project synthea by synthetichealth.
the class FhirStu3 method media.
/**
* Map the given Media element to a FHIR Media 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 Media to
* @param encounterEntry Current Encounter entry
* @param obs The Observation to map to FHIR and add to the bundle
* @return The added Entry
*/
private static BundleEntryComponent media(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Observation obs) {
org.hl7.fhir.dstu3.model.Media mediaResource = new org.hl7.fhir.dstu3.model.Media();
if (obs.codes != null && obs.codes.size() > 0) {
List<CodeableConcept> reasonList = obs.codes.stream().map(code -> mapCodeToCodeableConcept(code, SNOMED_URI)).collect(Collectors.toList());
mediaResource.setReasonCode(reasonList);
}
// Hard code as an image
mediaResource.setType(DigitalMediaType.PHOTO);
mediaResource.setSubject(new Reference(personEntry.getFullUrl()));
Attachment content = (Attachment) obs.value;
org.hl7.fhir.dstu3.model.Attachment contentResource = new org.hl7.fhir.dstu3.model.Attachment();
contentResource.setContentType(content.contentType);
contentResource.setLanguage(content.language);
if (content.data != null) {
contentResource.setDataElement(new org.hl7.fhir.dstu3.model.Base64BinaryType(content.data));
}
contentResource.setUrl(content.url);
contentResource.setSize(content.size);
contentResource.setTitle(content.title);
if (content.hash != null) {
contentResource.setHashElement(new org.hl7.fhir.dstu3.model.Base64BinaryType(content.hash));
}
mediaResource.setWidth(content.width);
mediaResource.setHeight(content.height);
mediaResource.setContent(contentResource);
return newEntry(rand, bundle, mediaResource);
}
Aggregations