use of org.hl7.fhir.dstu3.model.Dosage in project cqf-ruler by DBCG.
the class ActivityDefinitionApplyProvider method resolveServiceRequest.
private ServiceRequest resolveServiceRequest(ActivityDefinition activityDefinition, String patientId, String practitionerId, String organizationId) throws ActivityDefinitionApplyException {
// status, intent, code, and subject are required
ServiceRequest serviceRequest = new ServiceRequest();
serviceRequest.setStatus(ServiceRequest.ServiceRequestStatus.DRAFT);
serviceRequest.setIntent(ServiceRequest.ServiceRequestIntent.PROPOSAL);
String patientReferenceString = patientId;
URI patientIdAsUri = URI.create(patientReferenceString);
if (!patientIdAsUri.isAbsolute() && patientIdAsUri.getFragment() == null && !patientReferenceString.startsWith("Patient/")) {
patientReferenceString = "Patient/" + patientId;
}
serviceRequest.setSubject(new Reference(patientReferenceString));
if (practitionerId != null) {
serviceRequest.setRequester(new Reference(practitionerId));
} else if (organizationId != null) {
serviceRequest.setRequester(new Reference(organizationId));
}
if (activityDefinition.hasExtension()) {
serviceRequest.setExtension(activityDefinition.getExtension());
}
if (activityDefinition.hasCode()) {
serviceRequest.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()) {
serviceRequest.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 serviceRequest;
}
use of org.hl7.fhir.dstu3.model.Dosage in project openmrs-module-fhir2 by openmrs.
the class DosageTranslatorImplTest method toFhirResource_shouldTranslateDrugOrderRouteToRoute.
@Test
public void toFhirResource_shouldTranslateDrugOrderRouteToRoute() {
drugOrder.setAsNeeded(true);
Dosage result = dosageTranslator.toFhirResource(drugOrder);
assertThat(result, notNullValue());
assertThat(result.getAsNeededBooleanType().booleanValue(), is(true));
}
use of org.hl7.fhir.dstu3.model.Dosage in project openmrs-module-fhir2 by openmrs.
the class DosageTranslatorImplTest method toFhirResource_shouldTranslateDrugOrderAsNeededToAsNeeded.
@Test
public void toFhirResource_shouldTranslateDrugOrderAsNeededToAsNeeded() {
Concept concept = new Concept();
concept.setUuid(CONCEPT_UUID);
concept.setConceptId(1000);
CodeableConcept codeableConcept = new CodeableConcept();
codeableConcept.addCoding(new Coding().setCode(concept.getConceptId().toString()));
drugOrder.setRoute(concept);
when(conceptTranslator.toFhirResource(concept)).thenReturn(codeableConcept);
Dosage result = dosageTranslator.toFhirResource(drugOrder);
assertThat(result, notNullValue());
assertThat(result.getRoute(), equalTo(codeableConcept));
assertThat(result.getRoute().getCodingFirstRep().getCode(), equalTo("1000"));
}
use of org.hl7.fhir.dstu3.model.Dosage in project openmrs-module-fhir2 by openmrs.
the class DosageTranslatorImplTest method toFhirResource_shouldTranslateDosingInstructionToDosageText.
@Test
public void toFhirResource_shouldTranslateDosingInstructionToDosageText() {
drugOrder.setDosingInstructions(DOSING_INSTRUCTION);
Dosage result = dosageTranslator.toFhirResource(drugOrder);
assertThat(result, notNullValue());
assertThat(result.getText(), equalTo(DOSING_INSTRUCTION));
}
use of org.hl7.fhir.dstu3.model.Dosage in project org.hl7.fhir.core by hapifhir.
the class ArgonautConverter method processMedicationsSection.
private void processMedicationsSection(CDAUtilities cda, Convert convert, Element section, Context context) throws Exception {
scanSection("Medications", section);
ListResource list = new ListResource();
list.setId(context.getBaseId() + "-list-medications");
list.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/list-daf-dafmedicationlist");
list.setSubject(context.getSubjectRef());
list.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(section, "code")), null));
list.setTitle(cda.getChild(section, "title").getTextContent());
list.setStatus(ListStatus.CURRENT);
list.setMode(ListMode.SNAPSHOT);
list.setDateElement(context.getNow());
list.setSource(context.getAuthorRef());
buildNarrative(list, cda.getChild(section, "text"));
int i = 0;
for (Element c : cda.getChildren(section, "entry")) {
// allergy problem act
Element sa = cda.getChild(c, "substanceAdministration");
MedicationStatement ms = new MedicationStatement();
ms.setId(context.getBaseId() + "-medication-" + i);
ms.setUserData("profile", "http://hl7.org/fhir/StructureDefinition/medicationstatement-daf-dafmedicationstatement");
i++;
ms.setSubject(context.getSubjectRef());
boolean found = false;
for (Element e : cda.getChildren(sa, "id")) {
Identifier id = convert.makeIdentifierFromII(e);
ms.getIdentifier().add(id);
}
if (!found) {
ms.setStatus(MedicationStatementStatus.COMPLETED);
list.addEntry().setItem(new Reference().setReference("MedicationStatement/" + ms.getId()));
// allergy observation
Element mm = cda.getChild(cda.getChild(cda.getChild(sa, "consumable"), "manufacturedProduct"), "manufacturedMaterial");
ms.setMedication(new Reference().setReference("#med"));
Medication med = new Medication();
med.setId("med");
med.setCode(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(mm, "code")), null));
ms.getContained().add(med);
Dosage dosage = ms.addDosage();
// allergy observation
Element qty = cda.getChild(sa, "doseQuantity");
try {
if (cda.getChild(qty, "low") != null) {
// todo: this is not correct?
dosage.getExtension().add(new Extension().setUrl("http://healthintersections.com.au/fhir/extensions/medication-statement-range").setValue(convert.makeRangeFromIVLPQ(qty)));
} else {
dosage.setDose(convert.makeQuantityFromPQ(qty));
}
} catch (Exception e) {
System.out.println(" invalid dose quantity '" + qty.getAttribute("value") + " " + qty.getAttribute("unit") + "' (" + e.getClass().getName() + ") in " + context.getBaseId());
}
dosage.setRoute(inspectCode(convert.makeCodeableConceptFromCD(cda.getChild(sa, "routeCode")), null));
Type t = convert.makeSomethingFromGTS(cda.getChildren(sa, "effectiveTime"));
if (t instanceof Timing) {
dosage.setTiming((Timing) t);
if (dosage.getTiming().hasRepeat() && dosage.getTiming().getRepeat().hasBounds())
ms.setEffective(dosage.getTiming().getRepeat().getBounds());
} else if (t instanceof Period)
ms.setEffective(t);
else
throw new Exception("Undecided how to handle " + t.getClass().getName());
for (Element e : cda.getChildren(sa, "author")) {
if (ms.hasInformationSource())
throw new Error("additional author discovered");
Practitioner p = processPerformer(cda, convert, context, e, "assignedAuthor", "assignedPerson");
Reference ref = new Reference().setReference("Practitioner/" + p.getId()).setDisplay(p.getUserString("display"));
ms.setInformationSource(ref);
ms.setDateAssertedElement(convert.makeDateTimeFromTS(cda.getChild(e, "time")));
}
saveResource(ms);
}
}
saveResource(list);
}
Aggregations