use of org.hl7.fhir.r5.model.Dosage in project synthea by synthetichealth.
the class FhirR4 method medicationRequest.
/**
* Map the given Medication to a FHIR MedicationRequest resource, and add it to the given Bundle.
*
* @param person The person being prescribed medication
* @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 medicationRequest(Person person, BundleEntryComponent personEntry, Bundle bundle, BundleEntryComponent encounterEntry, Medication medication) {
MedicationRequest medicationResource = new MedicationRequest();
if (USE_US_CORE_IG) {
Meta meta = new Meta();
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-medicationrequest");
medicationResource.setMeta(meta);
} else 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"));
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);
}
medicationResource.setSubject(new Reference(personEntry.getFullUrl()));
medicationResource.setEncounter(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));
if (USE_US_CORE_IG && medication.administration) {
// Occasionally, rather than use medication codes, we want to use a Medication
// Resource. We only want to do this when we use US Core, to make sure we
// sometimes produce a resource for the us-core-medication profile, and the
// 'administration' flag is an arbitrary way to decide without flipping a coin.
org.hl7.fhir.r4.model.Medication drugResource = new org.hl7.fhir.r4.model.Medication();
Meta meta = new Meta();
meta.addProfile("http://hl7.org/fhir/us/core/StructureDefinition/us-core-medication");
drugResource.setMeta(meta);
drugResource.setCode(mapCodeToCodeableConcept(code, system));
drugResource.setStatus(MedicationStatus.ACTIVE);
BundleEntryComponent drugEntry = newEntry(person, bundle, drugResource);
medicationResource.setMedication(new Reference(drugEntry.getFullUrl()));
}
medicationResource.setAuthoredOn(new Date(medication.start));
medicationResource.setIntent(MedicationRequestIntent.ORDER);
org.hl7.fhir.r4.model.Encounter encounter = (org.hl7.fhir.r4.model.Encounter) encounterEntry.getResource();
medicationResource.setRequester(encounter.getParticipantFirstRep().getIndividual());
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")));
if (rxInfo.has("as_needed")) {
dosage.setText("Take as needed.");
}
// as_needed is false
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());
DosageDoseAndRateComponent dosageDetails = new DosageDoseAndRateComponent();
dosageDetails.setType(new CodeableConcept().addCoding(new Coding().setCode(DoseRateType.ORDERED.toCode()).setSystem(DoseRateType.ORDERED.getSystem()).setDisplay(DoseRateType.ORDERED.getDisplay())));
dosageDetails.setDose(dose);
List<DosageDoseAndRateComponent> details = new ArrayList<DosageDoseAndRateComponent>();
details.add(dosageDetails);
dosage.setDoseAndRate(details);
if (rxInfo.has("instructions")) {
String text = "";
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());
text += instructionCode.display + "\n";
dosage.addAdditionalInstruction(mapCodeToCodeableConcept(instructionCode, SNOMED_URI));
}
dosage.setText(text);
}
}
List<Dosage> dosageInstruction = new ArrayList<Dosage>();
dosageInstruction.add(dosage);
medicationResource.setDosageInstruction(dosageInstruction);
}
BundleEntryComponent medicationEntry = newEntry(person, bundle, medicationResource);
// create new claim for medication
medicationClaim(person, personEntry, bundle, encounterEntry, medication.claim, medicationEntry);
// Create new administration for medication, if needed
if (medication.administration) {
medicationAdministration(person, personEntry, bundle, encounterEntry, medication, medicationResource);
}
return medicationEntry;
}
use of org.hl7.fhir.r5.model.Dosage 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.r5.model.Dosage 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.r5.model.Dosage in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveProcedureRequest.
private ProcedureRequest resolveProcedureRequest(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId) throws ActivityDefinitionApplyException {
// status, intent, code, and subject are required
ProcedureRequest procedureRequest = new ProcedureRequest();
procedureRequest.setStatus(ProcedureRequest.ProcedureRequestStatus.DRAFT);
procedureRequest.setIntent(ProcedureRequest.ProcedureRequestIntent.PROPOSAL);
String patientReferenceString = patientId;
URI patientIdAsUri = URI.create(patientReferenceString);
if (!patientIdAsUri.isAbsolute() && patientIdAsUri.getFragment() == null && !patientReferenceString.startsWith("Patient/")) {
patientReferenceString = "Patient/" + patientId;
}
procedureRequest.setSubject(new Reference(patientReferenceString));
if (practitionerId != null) {
procedureRequest.setRequester(new ProcedureRequest.ProcedureRequestRequesterComponent().setAgent(new Reference(practitionerId)));
} else if (organizationId != null) {
procedureRequest.setRequester(new ProcedureRequest.ProcedureRequestRequesterComponent().setAgent(new Reference(organizationId)));
}
if (activityDefinition.hasExtension()) {
procedureRequest.setExtension(activityDefinition.getExtension());
}
if (activityDefinition.hasCode()) {
procedureRequest.setCode(activityDefinition.getCode());
} else // code can be set as a dynamicValue
if (!activityDefinition.hasCode() && !activityDefinition.hasDynamicValue()) {
throw new ActivityDefinitionApplyException("Missing required code property");
}
if (activityDefinition.hasBodySite()) {
procedureRequest.setBodySite(activityDefinition.getBodySite());
}
if (activityDefinition.hasProduct()) {
throw new ActivityDefinitionApplyException("Product does not map to " + activityDefinition.getKind());
}
if (activityDefinition.hasDosage()) {
throw new ActivityDefinitionApplyException("Dosage does not map to " + activityDefinition.getKind());
}
return procedureRequest;
}
use of org.hl7.fhir.r5.model.Dosage in project hl7v2-fhir-converter by LinuxForHealth.
the class FHIRConverterTest method test_dosage_output.
@Test
void test_dosage_output() throws IOException {
String hl7message = "MSH|^~\\&|MyEMR|DE-000001| |CAIRLO|20160701123030-0700||VXU^V04^VXU_V04|CA0001|P|2.6|||ER|AL|||||Z22^CDCPHINVS|DE-000001\r" + "PID|1||PA123456^^^MYEMR^MR||JONES^GEORGE^M^JR^^^L|MILLER^MARTHA^G^^^^M|20140227|M||2106-3^WHITE^CDCREC|1234 W FIRST ST^^BEVERLY HILLS^CA^90210^^H||^PRN^PH^^^555^5555555||ENG^English^HL70296|||||||2186-5^ not Hispanic or Latino^CDCREC||Y|2\r" + "ORC|RE||197023^CMC|||||||^Clark^Dave||1234567890^Smith^Janet^^^^^^NPPES^L^^^NPI^^^^^^^^MD\r" + "RXA|0|1|20140730||08^HEPB-PEDIATRIC/ADOLESCENT^CVX|.5|mL^mL^UCUM||00^NEW IMMUNIZATION RECORD^NIP001|1234567890^Smith^Janet^^^^^^NPPES^^^^NPI^^^^^^^^MD |^^^DE-000001||||0039F|20200531|MSD^MERCK^MVX|||CP|A";
String json = ftv.convert(hl7message, OPTIONS);
FHIRContext context = new FHIRContext();
IBaseResource bundleResource = context.getParser().parseResource(json);
assertThat(bundleResource).isNotNull();
Bundle b = (Bundle) bundleResource;
List<BundleEntryComponent> e = b.getEntry();
List<Resource> immunization = e.stream().filter(v -> ResourceType.Immunization == v.getResource().getResourceType()).map(BundleEntryComponent::getResource).collect(Collectors.toList());
assertThat(immunization).hasSize(1);
String s = context.getParser().encodeResourceToString(immunization.get(0));
Class<? extends IBaseResource> klass = Immunization.class;
Immunization expectDoseQuantity = (Immunization) context.getParser().parseResource(klass, s);
assertThat(expectDoseQuantity.hasDoseQuantity()).isTrue();
Quantity dosage = expectDoseQuantity.getDoseQuantity();
BigDecimal value = dosage.getValue();
String unit = dosage.getUnit();
assertThat(value).isEqualTo(BigDecimal.valueOf(.5));
assertThat(unit).isEqualTo("mL");
}
Aggregations