Search in sources :

Example 6 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project quality-measure-and-cohort-service by Alvearie.

the class R4ParameterDefinitionWithDefaultToCohortParameterConverterTest method testInteger__shouldReturnIntegerParameter.

@Test
public void testInteger__shouldReturnIntegerParameter() {
    ParameterDefinition parameterDefinition = getBaseParameterDefinition("integer");
    int expectedValue = 10;
    IntegerType fhirValue = new IntegerType(expectedValue);
    parameterDefinition.addExtension(CDMConstants.PARAMETER_DEFAULT_URL, fhirValue);
    assertEquals(new IntegerParameter(expectedValue), R4ParameterDefinitionWithDefaultToCohortParameterConverter.toCohortParameter(parameterDefinition));
}
Also used : IntegerType(org.hl7.fhir.r4.model.IntegerType) IntegerParameter(com.ibm.cohort.cql.evaluation.parameters.IntegerParameter) ParameterDefinition(org.hl7.fhir.r4.model.ParameterDefinition) Test(org.junit.Test)

Example 7 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project quality-measure-and-cohort-service by Alvearie.

the class MeasureSupplementalDataEvaluation method processAccumulators.

public static MeasureReport processAccumulators(MeasureReport report, Map<String, Map<String, Integer>> sdeAccumulators, boolean isSingle, List<Patient> patients) {
    List<Reference> newRefList = new ArrayList<>();
    sdeAccumulators.forEach((sdeKey, sdeAccumulator) -> {
        sdeAccumulator.forEach((sdeAccumulatorKey, sdeAccumulatorValue) -> {
            Observation obs = new Observation();
            obs.setStatus(Observation.ObservationStatus.FINAL);
            obs.setId(UUID.randomUUID().toString());
            Coding valueCoding = new Coding();
            if (sdeKey.equalsIgnoreCase(SDE_SEX)) {
                valueCoding.setCode(sdeAccumulatorKey);
            } else {
                String coreCategory = sdeKey.substring(sdeKey.lastIndexOf('-'));
                patients.forEach((pt) -> {
                    pt.getExtension().forEach((ptExt) -> {
                        if (ptExt.getUrl().contains(coreCategory)) {
                            String code = ((Coding) ptExt.getExtension().get(0).getValue()).getCode();
                            if (code.equalsIgnoreCase(sdeAccumulatorKey)) {
                                valueCoding.setSystem(((Coding) ptExt.getExtension().get(0).getValue()).getSystem());
                                valueCoding.setCode(code);
                                valueCoding.setDisplay(((Coding) ptExt.getExtension().get(0).getValue()).getDisplay());
                            }
                        }
                    });
                });
            }
            CodeableConcept obsCodeableConcept = new CodeableConcept();
            Extension obsExtension = new Extension().setUrl(CQF_MEASUREINFO_URL);
            Extension extExtMeasure = new Extension().setUrl(MEASURE).setValue(new CanonicalType(CQFMEASURES_URL + report.getMeasure()));
            obsExtension.addExtension(extExtMeasure);
            Extension extExtPop = new Extension().setUrl(POPULATION_ID).setValue(new StringType(sdeKey));
            obsExtension.addExtension(extExtPop);
            obs.addExtension(obsExtension);
            obs.setValue(new IntegerType(sdeAccumulatorValue));
            if (!isSingle) {
                valueCoding.setCode(sdeAccumulatorKey);
                obsCodeableConcept.setCoding(Collections.singletonList(valueCoding));
                obs.setCode(obsCodeableConcept);
            } else {
                obs.setCode(new CodeableConcept().setText(sdeKey));
                obsCodeableConcept.setCoding(Collections.singletonList(valueCoding));
                obs.setValue(obsCodeableConcept);
            }
            newRefList.add(new Reference("#" + obs.getId()));
            report.addContained(obs);
        });
    });
    newRefList.addAll(report.getEvaluatedResource());
    report.setEvaluatedResource(newRefList);
    return report;
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) IntegerType(org.hl7.fhir.r4.model.IntegerType) Coding(org.hl7.fhir.r4.model.Coding) StringType(org.hl7.fhir.r4.model.StringType) Reference(org.hl7.fhir.r4.model.Reference) ArrayList(java.util.ArrayList) Observation(org.hl7.fhir.r4.model.Observation) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 8 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project openmrs-module-fhir2 by openmrs.

the class ObservationValueTranslatorImplTest method toOpenmrsType_shouldConvertIntegerToNumericValue.

@Test
public void toOpenmrsType_shouldConvertIntegerToNumericValue() {
    IntegerType integerType = new IntegerType();
    integerType.setValue(130);
    Obs result = obsValueTranslator.toOpenmrsType(obs, integerType);
    assertThat(result, notNullValue());
    assertThat(result.getValueNumeric(), equalTo(130d));
}
Also used : IntegerType(org.hl7.fhir.r4.model.IntegerType) Obs(org.openmrs.Obs) Test(org.junit.Test) PrepareOnlyThisForTest(org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)

Example 9 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opPlus.

private List<Base> opPlus(List<Base> left, List<Base> right) throws PathEngineException {
    if (left.size() == 0)
        throw new PathEngineException("Error performing +: left operand has no value");
    if (left.size() > 1)
        throw new PathEngineException("Error performing +: left operand has more than one value");
    if (!left.get(0).isPrimitive())
        throw new PathEngineException(String.format("Error performing +: left operand has the wrong type (%s)", left.get(0).fhirType()));
    if (right.size() == 0)
        throw new PathEngineException("Error performing +: right operand has no value");
    if (right.size() > 1)
        throw new PathEngineException("Error performing +: right operand has more than one value");
    if (!right.get(0).isPrimitive())
        throw new PathEngineException(String.format("Error performing +: right operand has the wrong type (%s)", right.get(0).fhirType()));
    List<Base> result = new ArrayList<Base>();
    Base l = left.get(0);
    Base r = right.get(0);
    if (l.hasType("string", "id", "code", "uri") && r.hasType("string", "id", "code", "uri"))
        result.add(new StringType(l.primitiveValue() + r.primitiveValue()));
    else if (l.hasType("integer") && r.hasType("integer"))
        result.add(new IntegerType(Integer.parseInt(l.primitiveValue()) + Integer.parseInt(r.primitiveValue())));
    else if (l.hasType("decimal", "integer") && r.hasType("decimal", "integer"))
        result.add(new DecimalType(new BigDecimal(l.primitiveValue()).add(new BigDecimal(r.primitiveValue()))));
    else
        throw new PathEngineException(String.format("Error performing +: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType()));
    return result;
}
Also used : IntegerType(org.hl7.fhir.dstu2.model.IntegerType) StringType(org.hl7.fhir.dstu2.model.StringType) ArrayList(java.util.ArrayList) DecimalType(org.hl7.fhir.dstu2.model.DecimalType) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) Base(org.hl7.fhir.dstu2.model.Base) BigDecimal(java.math.BigDecimal)

Example 10 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method opDiv.

private List<Base> opDiv(List<Base> left, List<Base> right) throws PathEngineException {
    if (left.size() == 0)
        throw new PathEngineException("Error performing div: left operand has no value");
    if (left.size() > 1)
        throw new PathEngineException("Error performing div: left operand has more than one value");
    if (!left.get(0).isPrimitive())
        throw new PathEngineException(String.format("Error performing div: left operand has the wrong type (%s)", left.get(0).fhirType()));
    if (right.size() == 0)
        throw new PathEngineException("Error performing div: right operand has no value");
    if (right.size() > 1)
        throw new PathEngineException("Error performing div: right operand has more than one value");
    if (!right.get(0).isPrimitive())
        throw new PathEngineException(String.format("Error performing div: right operand has the wrong type (%s)", right.get(0).fhirType()));
    List<Base> result = new ArrayList<Base>();
    Base l = left.get(0);
    Base r = right.get(0);
    if (l.hasType("integer") && r.hasType("integer"))
        result.add(new IntegerType(Integer.parseInt(l.primitiveValue()) / Integer.parseInt(r.primitiveValue())));
    else if (l.hasType("decimal", "integer") && r.hasType("decimal", "integer")) {
        Decimal d1;
        try {
            d1 = new Decimal(l.primitiveValue());
            Decimal d2 = new Decimal(r.primitiveValue());
            result.add(new IntegerType(d1.divInt(d2).asDecimal()));
        } catch (UcumException e) {
            throw new PathEngineException(e);
        }
    } else
        throw new PathEngineException(String.format("Error performing div: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType()));
    return result;
}
Also used : IntegerType(org.hl7.fhir.dstu2.model.IntegerType) BigDecimal(java.math.BigDecimal) Decimal(org.fhir.ucum.Decimal) ArrayList(java.util.ArrayList) UcumException(org.fhir.ucum.UcumException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) Base(org.hl7.fhir.dstu2.model.Base)

Aggregations

ArrayList (java.util.ArrayList)51 BigDecimal (java.math.BigDecimal)34 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)28 IntegerType (org.hl7.fhir.r5.model.IntegerType)26 IntegerType (org.hl7.fhir.r4.model.IntegerType)23 IntegerType (org.hl7.fhir.r4b.model.IntegerType)23 UcumException (org.fhir.ucum.UcumException)19 Test (org.junit.jupiter.api.Test)13 Decimal (org.fhir.ucum.Decimal)12 FHIRException (org.hl7.fhir.exceptions.FHIRException)12 Base (org.hl7.fhir.r4b.model.Base)11 Base (org.hl7.fhir.r5.model.Base)11 IntegerType (org.hl7.fhir.dstu2.model.IntegerType)10 IntegerType (org.hl7.fhir.dstu2016may.model.IntegerType)10 StringType (org.hl7.fhir.r4.model.StringType)10 Patient (org.hl7.fhir.r4.model.Patient)9 Map (java.util.Map)7 ParserBase (org.hl7.fhir.dstu2016may.metamodel.ParserBase)7 DecimalType (org.hl7.fhir.r5.model.DecimalType)7 List (java.util.List)6