Search in sources :

Example 96 with Quantity

use of org.hl7.fhir.r4b.model.Quantity in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method parseQuantityString.

public Quantity parseQuantityString(String s) {
    if (s == null) {
        return null;
    }
    s = s.trim();
    if (s.contains(" ")) {
        String v = s.substring(0, s.indexOf(" ")).trim();
        s = s.substring(s.indexOf(" ")).trim();
        if (!Utilities.isDecimal(v, false)) {
            return null;
        }
        if (s.startsWith("'") && s.endsWith("'")) {
            return Quantity.fromUcum(v, s.substring(1, s.length() - 1));
        }
        if (s.equals("year") || s.equals("years")) {
            return Quantity.fromUcum(v, "a");
        } else if (s.equals("month") || s.equals("months")) {
            return Quantity.fromUcum(v, "mo_s");
        } else if (s.equals("week") || s.equals("weeks")) {
            return Quantity.fromUcum(v, "wk");
        } else if (s.equals("day") || s.equals("days")) {
            return Quantity.fromUcum(v, "d");
        } else if (s.equals("hour") || s.equals("hours")) {
            return Quantity.fromUcum(v, "h");
        } else if (s.equals("minute") || s.equals("minutes")) {
            return Quantity.fromUcum(v, "min");
        } else if (s.equals("second") || s.equals("seconds")) {
            return Quantity.fromUcum(v, "s");
        } else if (s.equals("millisecond") || s.equals("milliseconds")) {
            return Quantity.fromUcum(v, "ms");
        } else {
            return null;
        }
    } else {
        if (Utilities.isDecimal(s, true)) {
            return new Quantity().setValue(new BigDecimal(s)).setSystem("http://unitsofmeasure.org").setCode("1");
        } else {
            return null;
        }
    }
}
Also used : Quantity(org.hl7.fhir.r5.model.Quantity) BigDecimal(java.math.BigDecimal)

Example 97 with Quantity

use of org.hl7.fhir.r4b.model.Quantity in project org.hl7.fhir.core by hapifhir.

the class FHIRToolingClientTest method generateObservation.

private Observation generateObservation() {
    // Create an observation object
    Observation observation = new Observation();
    observation.getCode().addCoding().setSystem("http://loinc.org").setCode("789-8").setDisplay("Erythrocytes [#/volume] in Blood by Automated count");
    observation.setValue(new Quantity().setValue(4.12).setUnit("10 trillion/L").setSystem("http://unitsofmeasure.org").setCode("10*12/L"));
    return observation;
}
Also used : Observation(org.hl7.fhir.r5.model.Observation) Quantity(org.hl7.fhir.r5.model.Quantity)

Example 98 with Quantity

use of org.hl7.fhir.r4b.model.Quantity in project org.hl7.fhir.core by hapifhir.

the class NarrativeGenerator method displayQuantity.

private String displayQuantity(Quantity q) {
    StringBuilder s = new StringBuilder();
    s.append("(system = '").append(describeSystem(q.getSystem())).append("' code ").append(q.getCode()).append(" = '").append(lookupCode(q.getSystem(), q.getCode())).append("')");
    return s.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 99 with Quantity

use of org.hl7.fhir.r4b.model.Quantity in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeSupplyDeliverySupplyDeliverySuppliedItemComponent.

protected void composeSupplyDeliverySupplyDeliverySuppliedItemComponent(Complex parent, String parentType, String name, SupplyDelivery.SupplyDeliverySuppliedItemComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "suppliedItem", name, element, index);
    if (element.hasQuantity())
        composeQuantity(t, "SupplyDelivery", "quantity", element.getQuantity(), -1);
    if (element.hasItem())
        composeType(t, "SupplyDelivery", "item", element.getItem(), -1);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Example 100 with Quantity

use of org.hl7.fhir.r4b.model.Quantity in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeExplanationOfBenefitAddedItemDetailComponent.

protected void composeExplanationOfBenefitAddedItemDetailComponent(Complex parent, String parentType, String name, ExplanationOfBenefit.AddedItemDetailComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeBackboneElement(t, "detail", name, element, index);
    if (element.hasProductOrService())
        composeCodeableConcept(t, "ExplanationOfBenefit", "productOrService", element.getProductOrService(), -1);
    for (int i = 0; i < element.getModifier().size(); i++) composeCodeableConcept(t, "ExplanationOfBenefit", "modifier", element.getModifier().get(i), i);
    if (element.hasQuantity())
        composeQuantity(t, "ExplanationOfBenefit", "quantity", element.getQuantity(), -1);
    if (element.hasUnitPrice())
        composeMoney(t, "ExplanationOfBenefit", "unitPrice", element.getUnitPrice(), -1);
    if (element.hasFactorElement())
        composeDecimal(t, "ExplanationOfBenefit", "factor", element.getFactorElement(), -1);
    if (element.hasNet())
        composeMoney(t, "ExplanationOfBenefit", "net", element.getNet(), -1);
    for (int i = 0; i < element.getNoteNumber().size(); i++) composePositiveInt(t, "ExplanationOfBenefit", "noteNumber", element.getNoteNumber().get(i), i);
    for (int i = 0; i < element.getAdjudication().size(); i++) composeExplanationOfBenefitAdjudicationComponent(t, "ExplanationOfBenefit", "adjudication", element.getAdjudication().get(i), i);
    for (int i = 0; i < element.getSubDetail().size(); i++) composeExplanationOfBenefitAddedItemDetailSubDetailComponent(t, "ExplanationOfBenefit", "subDetail", element.getSubDetail().get(i), i);
}
Also used : Complex(org.hl7.fhir.r4.utils.formats.Turtle.Complex)

Aggregations

Quantity (org.hl7.fhir.r4.model.Quantity)58 ArrayList (java.util.ArrayList)47 Test (org.junit.jupiter.api.Test)40 BigDecimal (java.math.BigDecimal)39 Quantity (org.hl7.fhir.dstu3.model.Quantity)39 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)37 Test (org.junit.Test)25 List (java.util.List)24 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)23 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)23 NotImplementedException (org.apache.commons.lang3.NotImplementedException)19 FHIRException (org.hl7.fhir.exceptions.FHIRException)18 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)18 Observation (org.hl7.fhir.r4.model.Observation)18 UcumException (org.fhir.ucum.UcumException)16 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)16 Resource (org.hl7.fhir.r4.model.Resource)16 Quantity (org.hl7.fhir.r5.model.Quantity)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 Coding (org.hl7.fhir.r4.model.Coding)13