use of ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt in project synthea by synthetichealth.
the class FhirDstu2 method mapValueToSampledData.
/**
* Maps a Synthea internal SampledData object to the FHIR standard SampledData
* representation.
*
* @param value Synthea internal SampledData instance
* @param unit Observation unit value
* @return
*/
static SampledDataDt mapValueToSampledData(Components.SampledData value, String unit) {
SampledDataDt recordData = new SampledDataDt();
SimpleQuantityDt origin = new SimpleQuantityDt();
origin.setValue(new BigDecimal(value.originValue)).setCode(unit).setSystem(UNITSOFMEASURE_URI).setUnit(unit);
recordData.setOrigin(origin);
// Use the period from the first series. They should all be the same.
// FHIR output is milliseconds so we need to convert from TimeSeriesData seconds.
recordData.setPeriod(value.series.get(0).getPeriod() * 1000);
// Set optional fields if they were provided
if (value.factor != null) {
recordData.setFactor(value.factor);
}
if (value.lowerLimit != null) {
recordData.setLowerLimit(value.lowerLimit);
}
if (value.upperLimit != null) {
recordData.setUpperLimit(value.upperLimit);
}
recordData.setDimensions(value.series.size());
recordData.setData(ExportHelper.sampledDataToValueString(value));
return recordData;
}
use of ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt in project synthea by synthetichealth.
the class FhirDstu2 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
* @return The added Entry
*/
private static Entry medicationAdministration(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Medication medication) {
MedicationAdministration medicationResource = new MedicationAdministration();
medicationResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
medicationResource.setEncounter(new ResourceReferenceDt(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.setEffectiveTime(new DateTimeDt(new Date(medication.start)));
medicationResource.setStatus(MedicationAdministrationStatusEnum.COMPLETED);
if (medication.prescriptionDetails != null) {
JsonObject rxInfo = medication.prescriptionDetails;
MedicationAdministration.Dosage dosage = new MedicationAdministration.Dosage();
// as_needed is true if present
if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
SimpleQuantityDt dose = new SimpleQuantityDt();
dose.setValue(rxInfo.get("dosage").getAsJsonObject().get("amount").getAsDouble());
dosage.setQuantity(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 (Entry entry : bundle.getEntry()) {
if (entry.getResource().getResourceName().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
CodeableConceptDt coding = condition.getCode();
if (reason.code.equals(coding.getCodingFirstRep().getCode())) {
medicationResource.addReasonGiven(coding);
}
}
}
}
Entry medicationAdminEntry = newEntry(rand, bundle, medicationResource);
return medicationAdminEntry;
}
use of ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt in project synthea by synthetichealth.
the class FhirDstu2 method supplyDelivery.
/**
* Map the JsonObject for a Supply into a FHIR SupplyDelivery and add it to the Bundle.
*
* @param rand Source of randomness to use when generating ids etc
* @param personEntry The Person entry.
* @param bundle Bundle to add to.
* @param supply The supplied object to add.
* @param encounter The encounter during which the supplies were delivered
* @return The added Entry.
*/
private static Entry supplyDelivery(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, HealthRecord.Supply supply, Encounter encounter) {
SupplyDelivery supplyResource = new SupplyDelivery();
supplyResource.setStatus(SupplyDeliveryStatusEnum.DELIVERED);
supplyResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
CodeableConceptDt type = new CodeableConceptDt();
type.addCoding().setCode("device").setDisplay("Device").setSystem("http://hl7.org/fhir/supply-item-type");
supplyResource.setType(type);
// super hackish -- there's no "code" field available here, just a reference to a Device
// so for now just put some text in the reference
ResourceReferenceDt suppliedItem = new ResourceReferenceDt();
Code code = supply.codes.get(0);
suppliedItem.setDisplay("SNOMED[" + code.code + "]: " + code.display);
supplyResource.setSuppliedItem(suppliedItem);
supplyResource.setQuantity(new SimpleQuantityDt(supply.quantity));
supplyResource.setTime((DateTimeDt) convertFhirDateTime(supply.start, true));
return newEntry(rand, bundle, supplyResource);
}
use of ca.uhn.fhir.model.dstu2.composite.SimpleQuantityDt in project synthea by synthetichealth.
the class FhirDstu2 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 Entry medication(RandomNumberGenerator rand, Entry personEntry, Bundle bundle, Entry encounterEntry, Medication medication) {
MedicationOrder medicationResource = new MedicationOrder();
medicationResource.setPatient(new ResourceReferenceDt(personEntry.getFullUrl()));
medicationResource.setEncounter(new ResourceReferenceDt(encounterEntry.getFullUrl()));
ca.uhn.fhir.model.dstu2.resource.Encounter encounter = (ca.uhn.fhir.model.dstu2.resource.Encounter) encounterEntry.getResource();
medicationResource.setPrescriber(encounter.getParticipantFirstRep().getIndividual());
Code code = medication.codes.get(0);
String system = code.system.equals("SNOMED-CT") ? SNOMED_URI : RXNORM_URI;
medicationResource.setMedication(mapCodeToCodeableConcept(code, system));
medicationResource.setDateWritten(new DateTimeDt(new Date(medication.start)));
if (medication.stop != 0L) {
medicationResource.setStatus(MedicationOrderStatusEnum.STOPPED);
} else {
medicationResource.setStatus(MedicationOrderStatusEnum.ACTIVE);
}
if (!medication.reasons.isEmpty()) {
// Only one element in list
Code reason = medication.reasons.get(0);
for (Entry entry : bundle.getEntry()) {
if (entry.getResource().getResourceName().equals("Condition")) {
Condition condition = (Condition) entry.getResource();
// Only one element in list
CodingDt coding = condition.getCode().getCoding().get(0);
if (reason.code.equals(coding.getCode())) {
medicationResource.setReason(new ResourceReferenceDt(entry.getFullUrl()));
}
}
}
}
if (medication.prescriptionDetails != null) {
JsonObject rxInfo = medication.prescriptionDetails;
DosageInstruction dosage = new DosageInstruction();
// as_needed is true if present
dosage.setAsNeeded(new BooleanDt(rxInfo.has("as_needed")));
// as_needed is true if present
if ((rxInfo.has("dosage")) && (!rxInfo.has("as_needed"))) {
TimingDt timing = new TimingDt();
Repeat timingRepeatComponent = new Repeat();
timingRepeatComponent.setFrequency(rxInfo.get("dosage").getAsJsonObject().get("frequency").getAsInt());
timingRepeatComponent.setPeriod(rxInfo.get("dosage").getAsJsonObject().get("period").getAsDouble());
timingRepeatComponent.setPeriodUnits(convertUcumCode(rxInfo.get("dosage").getAsJsonObject().get("unit").getAsString()));
timing.setRepeat(timingRepeatComponent);
dosage.setTiming(timing);
QuantityDt dose = new SimpleQuantityDt().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.setAdditionalInstructions(mapCodeToCodeableConcept(instructionCode, SNOMED_URI));
}
}
}
List<DosageInstruction> dosageInstruction = new ArrayList<DosageInstruction>();
dosageInstruction.add(dosage);
medicationResource.setDosageInstruction(dosageInstruction);
}
Entry 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);
}
return medicationEntry;
}
Aggregations