org.hl7.fhir.r4.model.Quantity Java Examples
The following examples show how to use
org.hl7.fhir.r4.model.Quantity.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QuestionnaireBuilder.java From org.hl7.fhir.core with Apache License 2.0 | 6 votes |
private boolean instanceOf(TypeRefComponent t, Element obj) { if (t.getWorkingCode().equals("Reference")) { if (!(obj instanceof Reference)) { return false; } else { String url = ((Reference) obj).getReference(); // there are several problems here around profile matching. This process is degenerative, and there's probably nothing we can do to solve it if (url.startsWith("http:") || url.startsWith("https:")) return true; else if (t.hasProfile() && t.getProfile().get(0).getValue().startsWith("http://hl7.org/fhir/StructureDefinition/")) return url.startsWith(t.getProfile().get(0).getValue().substring(40)+'/'); else return true; } } else if (t.getWorkingCode().equals("Quantity")) { return obj instanceof Quantity; } else throw new NotImplementedException("Not Done Yet"); }
Example #2
Source File: FhirEncodersTest.java From bunsen with Apache License 2.0 | 6 votes |
@Test public void bigDecimal() { BigDecimal originalDecimal = ((Quantity) observation.getValue()).getValue(); // Use compareTo since equals checks scale as well. Assert.assertTrue(originalDecimal.compareTo( (BigDecimal) observationsDataset.select("valueQuantity.value") .head() .get(0)) == 0); Assert.assertEquals(originalDecimal.compareTo( ((Quantity) decodedObservation .getValue()) .getValue()), 0); }
Example #3
Source File: TestData.java From bunsen with Apache License 2.0 | 6 votes |
/** * Returns a FHIR Observation for testing purposes. */ public static Observation newObservation() { // Observation based on https://www.hl7.org/FHIR/observation-example-bloodpressure.json.html Observation observation = new Observation(); observation.setId("blood-pressure"); Identifier identifier = observation.addIdentifier(); identifier.setSystem("urn:ietf:rfc:3986"); identifier.setValue("urn:uuid:187e0c12-8dd2-67e2-99b2-bf273c878281"); observation.setStatus(Observation.ObservationStatus.FINAL); Quantity quantity = new Quantity(); quantity.setValue(new java.math.BigDecimal("123.45")); quantity.setUnit("mm[Hg]"); observation.setValue(quantity); return observation; }
Example #4
Source File: FhirR4.java From synthea with Apache License 2.0 | 6 votes |
static Type mapValueToFHIRType(Object value, String unit) { if (value == null) { return null; } else if (value instanceof Condition) { Code conditionCode = ((HealthRecord.Entry) value).codes.get(0); return mapCodeToCodeableConcept(conditionCode, SNOMED_URI); } else if (value instanceof Code) { return mapCodeToCodeableConcept((Code) value, SNOMED_URI); } else if (value instanceof String) { return new StringType((String) value); } else if (value instanceof Number) { double dblVal = ((Number) value).doubleValue(); PlainBigDecimal bigVal = new PlainBigDecimal(dblVal); return new Quantity().setValue(bigVal) .setCode(unit).setSystem(UNITSOFMEASURE_URI) .setUnit(unit); } else if (value instanceof Components.SampledData) { return mapValueToSampledData((Components.SampledData) value, unit); } else { throw new IllegalArgumentException("unexpected observation value class: " + value.getClass().toString() + "; " + value); } }
Example #5
Source File: FhirR4.java From synthea with Apache License 2.0 | 6 votes |
/** * Map the JsonObject for a Supply into a FHIR SupplyDelivery and add it to the Bundle. * * @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 BundleEntryComponent supplyDelivery(BundleEntryComponent personEntry, Bundle bundle, HealthRecord.Supply supply, Encounter encounter) { SupplyDelivery supplyResource = new SupplyDelivery(); supplyResource.setStatus(SupplyDeliveryStatus.COMPLETED); supplyResource.setPatient(new Reference(personEntry.getFullUrl())); CodeableConcept type = new CodeableConcept(); type.addCoding() .setCode("device") .setDisplay("Device") .setSystem("http://terminology.hl7.org/CodeSystem/supply-item-type"); supplyResource.setType(type); SupplyDeliverySuppliedItemComponent suppliedItem = new SupplyDeliverySuppliedItemComponent(); suppliedItem.setItem(mapCodeToCodeableConcept(supply.codes.get(0), SNOMED_URI)); suppliedItem.setQuantity(new Quantity(supply.quantity)); supplyResource.setSuppliedItem(suppliedItem); supplyResource.setOccurrence(convertFhirDateTime(supply.start, true)); return newEntry(bundle, supplyResource); }
Example #6
Source File: FhirR4.java From synthea with Apache License 2.0 | 5 votes |
/** * 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 org.hl7.fhir.r4.model.SampledData mapValueToSampledData( Components.SampledData value, String unit) { org.hl7.fhir.r4.model.SampledData recordData = new org.hl7.fhir.r4.model.SampledData(); recordData.setOrigin(new Quantity().setValue(value.originValue) .setCode(unit).setSystem(UNITSOFMEASURE_URI) .setUnit(unit)); // 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; }
Example #7
Source File: FhirR4.java From synthea with Apache License 2.0 | 4 votes |
/** * Add a MedicationAdministration if needed for the given medication. * * @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( 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("completed"); if (medication.prescriptionDetails != null) { JsonObject rxInfo = medication.prescriptionDetails; MedicationAdministrationDosageComponent dosage = new MedicationAdministrationDosageComponent(); // as_needed is false 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()); } } } if (rxInfo.has("refills")) { SimpleQuantity rate = new SimpleQuantity(); rate.setValue(rxInfo.get("refills").getAsLong()); dosage.setRate(rate); } 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(bundle, medicationResource); return medicationAdminEntry; }