use of org.hl7.fhir.r4.model.MedicationAdministration in project synthea by synthetichealth.
the class FhirStu3 method medicationAdministration.
/**
* Add a MedicationAdministration if needed for the given medication.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Entry for the Person
* @param bundle Bundle to add the MedicationAdministration to
* @param encounterEntry Current Encounter entry
* @param medication The Medication
* @param medicationRequest The related medicationRequest
* @return The added Entry
*/
private static BundleEntryComponent medicationAdministration(RandomNumberGenerator rand, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Medication medication, MedicationRequest medicationRequest) {
MedicationAdministration medicationResource = new MedicationAdministration();
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.setEffective(new DateTimeType(new Date(medication.start)));
medicationResource.setStatus(MedicationAdministrationStatus.fromCode("completed"));
if (medication.prescriptionDetails != null) {
JsonObject rxInfo = medication.prescriptionDetails;
MedicationAdministrationDosageComponent dosage = new MedicationAdministrationDosageComponent();
// as_needed is true if present
if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
Quantity dose = new SimpleQuantity().setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
dosage.setDose((SimpleQuantity) dose);
if (rxInfo.has("instructions")) {
for (JsonElement instructionElement : rxInfo.get("instructions").getAsJsonArray()) {
JsonObject instruction = instructionElement.getAsJsonObject();
dosage.setText(instruction.get("display").getAsString());
}
}
}
medicationResource.setDosage(dosage);
}
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());
}
}
}
}
BundleEntryComponent medicationAdminEntry = newEntry(rand, bundle, medicationResource);
return medicationAdminEntry;
}
use of org.hl7.fhir.r4.model.MedicationAdministration 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.hl7.fhir.r4.model.MedicationAdministration in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeMedicationAdministration.
protected void composeMedicationAdministration(Complex parent, String parentType, String name, MedicationAdministration element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeDomainResource(t, "MedicationAdministration", name, element, index);
for (int i = 0; i < element.getIdentifier().size(); i++) composeIdentifier(t, "MedicationAdministration", "identifier", element.getIdentifier().get(i), i);
for (int i = 0; i < element.getDefinition().size(); i++) composeReference(t, "MedicationAdministration", "definition", element.getDefinition().get(i), i);
for (int i = 0; i < element.getPartOf().size(); i++) composeReference(t, "MedicationAdministration", "partOf", element.getPartOf().get(i), i);
if (element.hasStatusElement())
composeEnum(t, "MedicationAdministration", "status", element.getStatusElement(), -1);
if (element.hasCategory())
composeCodeableConcept(t, "MedicationAdministration", "category", element.getCategory(), -1);
if (element.hasMedication())
composeType(t, "MedicationAdministration", "medication", element.getMedication(), -1);
if (element.hasSubject())
composeReference(t, "MedicationAdministration", "subject", element.getSubject(), -1);
if (element.hasContext())
composeReference(t, "MedicationAdministration", "context", element.getContext(), -1);
for (int i = 0; i < element.getSupportingInformation().size(); i++) composeReference(t, "MedicationAdministration", "supportingInformation", element.getSupportingInformation().get(i), i);
if (element.hasEffective())
composeType(t, "MedicationAdministration", "effective", element.getEffective(), -1);
for (int i = 0; i < element.getPerformer().size(); i++) composeMedicationAdministrationMedicationAdministrationPerformerComponent(t, "MedicationAdministration", "performer", element.getPerformer().get(i), i);
if (element.hasNotGivenElement())
composeBoolean(t, "MedicationAdministration", "notGiven", element.getNotGivenElement(), -1);
for (int i = 0; i < element.getReasonNotGiven().size(); i++) composeCodeableConcept(t, "MedicationAdministration", "reasonNotGiven", element.getReasonNotGiven().get(i), i);
for (int i = 0; i < element.getReasonCode().size(); i++) composeCodeableConcept(t, "MedicationAdministration", "reasonCode", element.getReasonCode().get(i), i);
for (int i = 0; i < element.getReasonReference().size(); i++) composeReference(t, "MedicationAdministration", "reasonReference", element.getReasonReference().get(i), i);
if (element.hasPrescription())
composeReference(t, "MedicationAdministration", "prescription", element.getPrescription(), -1);
for (int i = 0; i < element.getDevice().size(); i++) composeReference(t, "MedicationAdministration", "device", element.getDevice().get(i), i);
for (int i = 0; i < element.getNote().size(); i++) composeAnnotation(t, "MedicationAdministration", "note", element.getNote().get(i), i);
if (element.hasDosage())
composeMedicationAdministrationMedicationAdministrationDosageComponent(t, "MedicationAdministration", "dosage", element.getDosage(), -1);
for (int i = 0; i < element.getEventHistory().size(); i++) composeReference(t, "MedicationAdministration", "eventHistory", element.getEventHistory().get(i), i);
}
use of org.hl7.fhir.r4.model.MedicationAdministration in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeMedicationAdministrationMedicationAdministrationDosageComponent.
protected void composeMedicationAdministrationMedicationAdministrationDosageComponent(Complex parent, String parentType, String name, MedicationAdministration.MedicationAdministrationDosageComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "dosage", name, element, index);
if (element.hasTextElement())
composeString(t, "MedicationAdministration", "text", element.getTextElement(), -1);
if (element.hasSite())
composeCodeableConcept(t, "MedicationAdministration", "site", element.getSite(), -1);
if (element.hasRoute())
composeCodeableConcept(t, "MedicationAdministration", "route", element.getRoute(), -1);
if (element.hasMethod())
composeCodeableConcept(t, "MedicationAdministration", "method", element.getMethod(), -1);
if (element.hasDose())
composeQuantity(t, "MedicationAdministration", "dose", element.getDose(), -1);
if (element.hasRate())
composeType(t, "MedicationAdministration", "rate", element.getRate(), -1);
}
use of org.hl7.fhir.r4.model.MedicationAdministration in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilitiesTests method execute.
public void execute(String[] args) throws FileNotFoundException, IOException, FHIRException {
System.out.println("loading context");
context = SimpleWorkerContext.fromPack(Utilities.path(root, "validation.zip"));
comp = new ProfileComparer(context);
compare("patient-daf-dafpatient.profile.xml", "patient-qicore-qicore-patient.profile.xml");
compare("encounter-daf-dafencounter.profile.xml", "encounter-qicore-qicore-encounter.profile.xml");
compare("substance-daf-dafsubstance.profile.xml", "substance-qicore-qicore-substance.profile.xml");
compare("medication-daf-dafmedication.profile.xml", "medication-qicore-qicore-medication.profile.xml");
compare("procedure-daf-dafprocedure.profile.xml", "procedure-qicore-qicore-procedure.profile.xml");
compare("familymemberhistory-daf-daffamilymemberhistory.profile.xml", "familymemberhistory-qicore-qicore-familymemberhistory.profile.xml");
compare("immunization-daf-dafimmunization.profile.xml", "immunization-qicore-qicore-immunization.profile.xml");
compare("condition-daf-dafcondition.profile.xml", "condition-qicore-qicore-condition.profile.xml");
compare("allergyintolerance-daf-dafallergyintolerance.profile.xml", "allergyintolerance-qicore-qicore-allergyintolerance.profile.xml");
compare("medicationadministration-daf-dafmedicationadministration.profile.xml", "medicationadministration-qicore-qicore-medicationadministration.profile.xml");
compare("medicationdispense-daf-dafmedicationdispense.profile.xml", "medicationdispense-qicore-qicore-medicationdispense.profile.xml");
compare("medicationprescription-daf-dafmedicationprescription.profile.xml", "medicationprescription-qicore-qicore-medicationprescription.profile.xml");
compare("medicationstatement-daf-dafmedicationstatement.profile.xml", "medicationstatement-qicore-qicore-medicationstatement.profile.xml");
compare("observation-daf-smokingstatus-dafsmokingstatus.profile.xml", "observation-qicore-qicore-observation.profile.xml");
compare("observation-daf-vitalsigns-dafvitalsigns.profile.xml", "observation-qicore-qicore-observation.profile.xml");
// compare("observation-daf-results-dafresultobs.profile.xml", "observation-qicore-qicore-observation.profile.xml");
// compare("diagnosticorder-daf-dafdiagnosticorder.profile.xml", "diagnosticorder-qicore-qicore-diagnosticorder.profile.xml");
// compare("diagnosticreport-daf-dafdiagnosticreport.profile.xml", "diagnosticreport-qicore-qicore-diagnosticreport.profile.xml");
System.out.println("processing output");
for (ProfileComparison outcome : comp.getComparisons()) {
if (outcome.getSubset() != null)
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "intersection-" + outcome.getId() + ".xml")), outcome.getSubset());
if (outcome.getSuperset() != null)
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "union-" + outcome.getId() + ".xml")), outcome.getSuperset());
System.out.println("\r\n" + outcome.getId() + ": Comparison of " + outcome.getLeft().getUrl() + " and " + outcome.getRight().getUrl());
for (ValidationMessage vm : outcome.getMessages()) if (vm.getLevel() == IssueSeverity.INFORMATION)
System.out.println(vm.summary());
for (ValidationMessage vm : outcome.getMessages()) if (vm.getLevel() == IssueSeverity.WARNING)
System.out.println(vm.summary());
for (ValidationMessage vm : outcome.getMessages()) if (vm.getLevel() == IssueSeverity.ERROR)
System.out.println(vm.summary());
for (ValidationMessage vm : outcome.getMessages()) if (vm.getLevel() == IssueSeverity.FATAL)
System.out.println(vm.summary());
System.out.println("done. " + Integer.toString(outcome.getMessages().size()) + " messages");
System.out.println("=================================================================");
}
}
Aggregations