use of org.hl7.fhir.r4b.model.Timing.TimingRepeatComponent in project org.hl7.fhir.core by hapifhir.
the class DataRenderer method displayTiming.
private String displayTiming(Timing s) throws FHIRException {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
if (s.hasCode())
b.append("Code: " + displayCodeableConcept(s.getCode()));
if (s.getEvent().size() > 0) {
CommaSeparatedStringBuilder c = new CommaSeparatedStringBuilder();
for (DateTimeType p : s.getEvent()) {
if (p.hasValue()) {
c.append(displayDateTime(p));
} else if (!renderExpression(c, p)) {
c.append("??");
}
}
b.append("Events: " + c.toString());
}
if (s.hasRepeat()) {
TimingRepeatComponent rep = s.getRepeat();
if (rep.hasBoundsPeriod() && rep.getBoundsPeriod().hasStart())
b.append("Starting " + displayDateTime(rep.getBoundsPeriod().getStartElement()));
if (rep.hasCount())
b.append("Count " + Integer.toString(rep.getCount()) + " times");
if (rep.hasDuration())
b.append("Duration " + rep.getDuration().toPlainString() + displayTimeUnits(rep.getPeriodUnit()));
if (rep.hasWhen()) {
String st = "";
if (rep.hasOffset()) {
st = Integer.toString(rep.getOffset()) + "min ";
}
b.append("Do " + st);
for (Enumeration<EventTiming> wh : rep.getWhen()) b.append(displayEventCode(wh.getValue()));
} else {
String st = "";
if (!rep.hasFrequency() || (!rep.hasFrequencyMax() && rep.getFrequency() == 1))
st = "Once";
else {
st = Integer.toString(rep.getFrequency());
if (rep.hasFrequencyMax())
st = st + "-" + Integer.toString(rep.getFrequency());
}
if (rep.hasPeriod()) {
st = st + " per " + rep.getPeriod().toPlainString();
if (rep.hasPeriodMax())
st = st + "-" + rep.getPeriodMax().toPlainString();
st = st + " " + displayTimeUnits(rep.getPeriodUnit());
}
b.append("Do " + st);
}
if (rep.hasBoundsPeriod() && rep.getBoundsPeriod().hasEnd())
b.append("Until " + displayDateTime(rep.getBoundsPeriod().getEndElement()));
}
return b.toString();
}
use of org.hl7.fhir.r4b.model.Timing.TimingRepeatComponent in project bunsen by cerner.
the class TestData method newMedicationRequest.
/**
* Returns a new MedicationRequest for testing.
*
* @return a FHIR MedicationRequest for testing.
*/
public static MedicationRequest newMedicationRequest() {
MedicationRequest medicationRequest = new MedicationRequest();
medicationRequest.setId("test-medication-request");
CodeableConcept itemCodeableConcept = new CodeableConcept();
itemCodeableConcept.addCoding().setSystem("http://www.nlm.nih.gov/research/umls/rxnorm").setCode("103109").setDisplay("Vitamin E 3 MG Oral Tablet [Ephynal]").setUserSelected(true);
medicationRequest.setMedication(itemCodeableConcept);
medicationRequest.setSubject(new Reference("Patient/12345").setDisplay("Here is a display for you."));
medicationRequest.setDosageInstruction(ImmutableList.of(new Dosage().setTiming(new Timing().setRepeat(new TimingRepeatComponent().setCount(10)))));
medicationRequest.setSubstitution(new MedicationRequestSubstitutionComponent().setAllowed(true));
return medicationRequest;
}
use of org.hl7.fhir.r4b.model.Timing.TimingRepeatComponent 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.r4b.model.Timing.TimingRepeatComponent 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.r4b.model.Timing.TimingRepeatComponent in project org.hl7.fhir.core by hapifhir.
the class NarrativeGenerator method displayTiming.
private String displayTiming(Timing s) throws FHIRException {
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
if (s.hasCode())
b.append("Code: " + displayCodeableConcept(s.getCode()));
if (s.getEvent().size() > 0) {
CommaSeparatedStringBuilder c = new CommaSeparatedStringBuilder();
for (DateTimeType p : s.getEvent()) {
c.append(p.toHumanDisplay());
}
b.append("Events: " + c.toString());
}
if (s.hasRepeat()) {
TimingRepeatComponent rep = s.getRepeat();
if (rep.hasBoundsPeriod() && rep.getBoundsPeriod().hasStart())
b.append("Starting " + rep.getBoundsPeriod().getStartElement().toHumanDisplay());
if (rep.hasCount())
b.append("Count " + Integer.toString(rep.getCount()) + " times");
if (rep.hasDuration())
b.append("Duration " + rep.getDuration().toPlainString() + displayTimeUnits(rep.getPeriodUnits()));
if (rep.hasWhen()) {
String st = "";
if (rep.hasPeriod()) {
st = rep.getPeriod().toPlainString();
if (rep.hasPeriodMax())
st = st + "-" + rep.getPeriodMax().toPlainString();
st = st + displayTimeUnits(rep.getPeriodUnits());
}
b.append("Do " + st + displayEventCode(rep.getWhen()));
} else {
String st = "";
if (!rep.hasFrequency() || (!rep.hasFrequencyMax() && rep.getFrequency() == 1))
st = "Once";
else {
st = Integer.toString(rep.getFrequency());
if (rep.hasFrequencyMax())
st = st + "-" + Integer.toString(rep.getFrequency());
}
if (rep.hasPeriod()) {
st = st + " per " + rep.getPeriod().toPlainString();
if (rep.hasPeriodMax())
st = st + "-" + rep.getPeriodMax().toPlainString();
st = st + " " + displayTimeUnits(rep.getPeriodUnits());
}
b.append("Do " + st);
}
if (rep.hasBoundsPeriod() && rep.getBoundsPeriod().hasEnd())
b.append("Until " + rep.getBoundsPeriod().getEndElement().toHumanDisplay());
}
return b.toString();
}
Aggregations