Search in sources :

Example 56 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project pathling by aehrc.

the class TestData method newConditionWithExtensions.

public static Condition newConditionWithExtensions() {
    // Condition
    // - extension:
    // - url: uuid:ext1
    // - value: ext1
    // - extension:
    // - url: uuid:ext2
    // - value: 2
    // - extension:
    // - url: uuid:ext4
    // - extension
    // - url: uuid:nested
    // - value: nested
    // - identifier
    // - id: uuid:identifier1
    // - extension:
    // - url: uuid:ext10
    // - value: ext10
    // - extension:
    // - url: uuid:ext11
    // - value: 11
    // - stage
    // - type
    // - extension
    // - url: uuid:ext12
    // - value: ext12
    final Condition conditionWithExtension = new Condition();
    conditionWithExtension.setId("someId");
    final Extension nestedExtension = new Extension("uuid:ext4");
    nestedExtension.addExtension(new Extension("uuid:nested", new StringType("nested")));
    conditionWithExtension.setExtension(Arrays.asList(new Extension("uuid:ext1", new StringType("ext1")), new Extension("uuid:ext2", new IntegerType(2)), nestedExtension));
    conditionWithExtension.setMeta(new Meta().setVersionId("MetVersion"));
    conditionWithExtension.setOnset(new Range());
    conditionWithExtension.setSeverity(new CodeableConcept().addCoding(new Coding("sys", "code", "name")));
    final Identifier identifier = conditionWithExtension.getIdentifierFirstRep();
    identifier.setId("uuid:identifier1");
    identifier.setExtension(Arrays.asList(new Extension("uuid:ext10", new StringType("ext10")), new Extension("uuid:ext11", new IntegerType(11))));
    final ConditionStageComponent stage = conditionWithExtension.getStageFirstRep();
    stage.getType().setExtension(Collections.singletonList(new Extension("uuid:ext12", new StringType("ext12"))));
    return conditionWithExtension;
}
Also used : ConditionStageComponent(org.hl7.fhir.r4.model.Condition.ConditionStageComponent)

Example 57 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project pathling by aehrc.

the class DefaultTerminologyServiceTest method testIntersectFiltersIllegalAndUnknownCodings.

@SuppressWarnings("ConstantConditions")
@Test
void testIntersectFiltersIllegalAndUnknownCodings() {
    final ValueSet responseExpansion = new ValueSet();
    responseExpansion.getExpansion().getContains().addAll(Arrays.asList(fromSimpleCoding(CODING1_VERSION1), fromSimpleCoding(CODING2_VERSION1)));
    when(terminologyClient.expand(any(), any())).thenReturn(responseExpansion);
    // setup SYSTEM1 as known system
    when(terminologyClient.searchCodeSystems(refEq(new UriParam(SYSTEM1)), any())).thenReturn(Collections.singletonList(new CodeSystem()));
    final Set<SimpleCoding> actualExpansion = terminologyService.intersect("uuid:value-set", Arrays.asList(CODING1_VERSION1, CODING2_VERSION1, CODING3_VERSION1, new SimpleCoding(SYSTEM1, null), new SimpleCoding(null, "code1"), new SimpleCoding(null, null), null));
    final Set<SimpleCoding> expectedExpansion = ImmutableSet.of(CODING1_VERSION1, CODING2_VERSION1);
    assertEquals(expectedExpansion, actualExpansion);
    // verify behaviour
    verify(terminologyClient).searchCodeSystems(refEq(new UriParam(SYSTEM1)), any());
    verify(terminologyClient).searchCodeSystems(refEq(new UriParam(SYSTEM2)), any());
    final ValueSet requestValueSet = new ValueSet();
    final List<ConceptSetComponent> includes = requestValueSet.getCompose().getInclude();
    includes.add(new ConceptSetComponent().addValueSet("uuid:value-set").setSystem(SYSTEM1).setVersion("version1").addConcept(new ConceptReferenceComponent().setCode("code1")).addConcept(new ConceptReferenceComponent().setCode("code2")));
    verify(terminologyClient).expand(deepEq(requestValueSet), deepEq(new IntegerType(2)));
    verifyNoMoreInteractions(terminologyClient);
}
Also used : IntegerType(org.hl7.fhir.r4.model.IntegerType) ConceptSetComponent(org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent) SimpleCoding(au.csiro.pathling.fhirpath.encoding.SimpleCoding) ValueSet(org.hl7.fhir.r4.model.ValueSet) UriParam(ca.uhn.fhir.rest.param.UriParam) CodeSystem(org.hl7.fhir.r4.model.CodeSystem) ConceptReferenceComponent(org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 58 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project redmatch by aehrc.

the class FhirExporter method getValue.

/**
 * Resolves a value.
 *
 * @param value The value specified in the transformation rules.
 * @param fhirType The type of the FHIR attribute where this value will be set.
 * @param vertex A vertex with patient data.
 * @param recordId The id of this record. Used to create the references to FHIR ids.
 * @param enumFactory If the type is an enumeration, this is the factory to create an instance.
 * @param fhirPackage The target FHIR package.
 * @return The value or null if the value cannot be determined. This can also be a list.
 */
private Base getValue(Value value, Class<?> fhirType, JsonObject vertex, String recordId, Class<?> enumFactory, VersionedFhirPackage fhirPackage) throws IOException {
    // If this is a field-based value then make sure that there is a value and if not return null
    if (value instanceof FieldBasedValue) {
        FieldBasedValue fbv = (FieldBasedValue) value;
        // Account for field ids of the form xx___y
        String fieldId = fbv.getFieldId();
        String shortFieldId = null;
        String regex = "(?<fieldId>.*)___\\d+$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(fieldId);
        if (matcher.find()) {
            shortFieldId = matcher.group("fieldId");
            log.debug("Transformed fieldId into '" + fieldId + "'");
        }
        boolean hasValue = false;
        JsonElement jsonElement = vertex.get(fieldId);
        if (jsonElement != null) {
            String rawValue = jsonElement.getAsString();
            if (!rawValue.isEmpty()) {
                hasValue = true;
            }
        }
        if (!hasValue && shortFieldId != null) {
            jsonElement = vertex.get(shortFieldId);
            if (jsonElement != null) {
                String rawValue = jsonElement.getAsString();
                if (!rawValue.isEmpty()) {
                    hasValue = true;
                }
            }
        }
        if (!hasValue) {
            return null;
        }
    }
    if (value instanceof BooleanValue) {
        return new BooleanType(((BooleanValue) value).getValue());
    } else if (value instanceof CodeLiteralValue) {
        String code = ((CodeLiteralValue) value).getCode();
        return getCode(code, enumFactory);
    } else if (value instanceof ConceptLiteralValue) {
        ConceptLiteralValue clv = (ConceptLiteralValue) value;
        String system = clv.getSystem();
        String code = clv.getCode();
        String display = clv.getDisplay() != null ? clv.getDisplay() : "";
        return getConcept(system, code, display, fhirType);
    } else if (value instanceof DoubleValue) {
        return new DecimalType(((DoubleValue) value).getValue());
    } else if (value instanceof IntegerValue) {
        return new IntegerType(((IntegerValue) value).getValue());
    } else if (value instanceof ReferenceValue) {
        ReferenceValue rv = (ReferenceValue) value;
        Reference ref = new Reference();
        String resourceType = rv.getResourceType();
        String resourceId = rv.getResourceId();
        boolean unique = uniqueIds.contains(resourceType + "<" + resourceId + ">");
        CodeInfo codeInfo = terminologyService.lookup(fhirPackage, resourceType);
        if (codeInfo.isProfile()) {
            resourceType = StringUtils.getLastPath(codeInfo.getBaseResource());
        }
        if (unique) {
            // This is a reference to a unique resource - no need to append row id
            if (fhirResourceMap.containsKey(resourceId)) {
                ref.setReference("/" + resourceType + "/" + resourceId);
            } else {
                log.debug("Did not find resource " + resourceType + "/" + resourceId);
            }
        } else {
            if (fhirResourceMap.containsKey(resourceId + "-" + recordId)) {
                ref.setReference("/" + resourceType + "/" + resourceId + "-" + recordId);
            } else {
                log.debug("Did not find resource " + resourceType + "/" + resourceId + "-" + recordId);
            }
        }
        return ref;
    } else if (value instanceof StringValue) {
        if (fhirType.equals(StringType.class)) {
            return new StringType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(MarkdownType.class)) {
            return new MarkdownType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(IdType.class)) {
            return new IdType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(UriType.class)) {
            return new UriType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(OidType.class)) {
            return new OidType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(UuidType.class)) {
            return new UuidType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(CanonicalType.class)) {
            return new CanonicalType(((StringValue) value).getStringValue());
        } else if (fhirType.equals(UrlType.class)) {
            return new UrlType(((StringValue) value).getStringValue());
        } else {
            throw new TransformationException("Got StringValue for FHIR type " + fhirType.getName() + ". This should not happen!");
        }
    } else if (value instanceof CodeSelectedValue) {
        CodeSelectedValue csv = (CodeSelectedValue) value;
        String fieldId = csv.getFieldId();
        Mapping m = getSelectedMapping(fieldId, vertex);
        if (m == null) {
            throw new TransformationException("Mapping for field " + fieldId + " is required but was not found.");
        }
        return getTarget(m).getCodeElement();
    } else if (value instanceof ConceptSelectedValue) {
        ConceptSelectedValue csv = (ConceptSelectedValue) value;
        String fieldId = csv.getFieldId();
        Mapping m = getSelectedMapping(fieldId, vertex);
        if (m == null) {
            throw new TransformationException("Mapping for field " + fieldId + " is required but was not found.");
        }
        if (fhirType.isAssignableFrom(Coding.class)) {
            return getTarget(m);
        } else if (fhirType.isAssignableFrom(CodeableConcept.class)) {
            return new CodeableConcept().addCoding(getTarget(m));
        } else {
            throw new TransformationException("FHIR type of field " + fieldId + " (" + fhirType + ") is incompatible with CONCEPT_SELECTED.");
        }
    } else if (value instanceof ConceptValue) {
        // Ontoserver REDCap plugin format: 74400008|Appendicitis|http://snomed.info/sct
        ConceptValue cv = (ConceptValue) value;
        String fieldId = cv.getFieldId();
        Mapping m = getMapping(fieldId);
        if (m != null) {
            if (fhirType.isAssignableFrom(Coding.class)) {
                return getTarget(m);
            } else if (fhirType.isAssignableFrom(CodeableConcept.class)) {
                return new CodeableConcept().addCoding(getTarget(m));
            } else {
                throw new TransformationException("FHIR type of field " + fieldId + " (" + fhirType + ") is incompatible with CONCEPT.");
            }
        } else {
            au.csiro.redmatch.model.Field field = doc.getSchema().getField(fieldId);
            Coding c = field.getCoding(vertex);
            if (c != null) {
                if (fhirType.isAssignableFrom(Coding.class)) {
                    return c;
                } else if (fhirType.isAssignableFrom(CodeableConcept.class)) {
                    return new CodeableConcept().addCoding(c);
                } else {
                    throw new TransformationException("FHIR type of field " + fieldId + " (" + fhirType + ") is incompatible with CONCEPT.");
                }
            }
        }
        throw new TransformationException("Could not get concept for field " + fieldId + ".");
    } else if (value instanceof FieldValue) {
        FieldValue fv = (FieldValue) value;
        String fieldId = fv.getFieldId();
        FieldValue.DatePrecision pr = fv.getDatePrecision();
        au.csiro.redmatch.model.Field field = doc.getSchema().getField(fieldId);
        return field.getValue(vertex, fhirType, pr);
    } else {
        throw new TransformationException("Unable to get VALUE for " + value);
    }
}
Also used : CodeInfo(au.csiro.redmatch.terminology.CodeInfo) Matcher(java.util.regex.Matcher) Field(java.lang.reflect.Field) org.hl7.fhir.r4.model(org.hl7.fhir.r4.model) Pattern(java.util.regex.Pattern) JsonElement(com.google.gson.JsonElement)

Example 59 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project bunsen by cerner.

the class TestData method newPatient.

/**
 * Returns a FHIR Patient for testing purposes.
 */
public static Patient newPatient() {
    Patient patient = new Patient();
    patient.setId("test-patient");
    patient.setMultipleBirth(new IntegerType(1));
    return patient;
}
Also used : IntegerType(org.hl7.fhir.dstu3.model.IntegerType) Patient(org.hl7.fhir.dstu3.model.Patient)

Example 60 with IntegerType

use of org.hl7.fhir.dstu2016may.model.IntegerType in project bunsen by cerner.

the class TestData method newPatient.

/**
 * Returns a FHIR Patient for testing purposes.
 */
public static Patient newPatient() {
    Patient patient = new Patient();
    patient.setId("test-patient");
    patient.setMultipleBirth(new IntegerType(1));
    return patient;
}
Also used : IntegerType(org.hl7.fhir.dstu3.model.IntegerType) Patient(org.hl7.fhir.dstu3.model.Patient)

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