Search in sources :

Example 11 with MarkdownType

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

the class MarkdownTypeNullTest method typedCopy.

@Test
@DisplayName("Test null value typedCopy()")
void typedCopy() {
    MarkdownType nullMarkdown = new MarkdownType();
    MarkdownType copyMarkdown = (MarkdownType) nullMarkdown.typedCopy();
    Assertions.assertNull(copyMarkdown.getValue());
}
Also used : MarkdownType(org.hl7.fhir.r4b.model.MarkdownType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with MarkdownType

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

the class MarkdownTypeNullTest method equalsDeep.

@Test
@DisplayName("Test null value equalsDeep()")
void equalsDeep() {
    MarkdownType nullMarkdown = new MarkdownType();
    MarkdownType validMarkdown = new MarkdownType("__MARKDOWN__");
    Assertions.assertFalse(nullMarkdown.equalsDeep(validMarkdown));
}
Also used : MarkdownType(org.hl7.fhir.r4b.model.MarkdownType) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 13 with MarkdownType

use of org.hl7.fhir.r4b.model.MarkdownType 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 14 with MarkdownType

use of org.hl7.fhir.r4b.model.MarkdownType in project kindling by HL7.

the class ProfileGenerator method convertConstraints.

private void convertConstraints(ElementDefn e, ElementDefinition ce, String source) throws FHIRException {
    for (String in : e.getInvariants().keySet()) {
        ElementDefinitionConstraintComponent con = new ElementDefinitionConstraintComponent();
        Invariant inv = e.getInvariants().get(in);
        con.setKey(inv.getId());
        if (!con.hasKey()) {
            profileCounter++;
            con.setKey("prf-" + Integer.toString(profileCounter));
        }
        con.setRequirements(inv.getRequirements());
        if (Utilities.noString(inv.getSeverity()))
            con.setSeverity(ConstraintSeverity.ERROR);
        else if (inv.getSeverity().equals("best-practice")) {
            con.setSeverity(ConstraintSeverity.WARNING);
            ToolingExtensions.addBooleanExtension(con, ToolingExtensions.EXT_BEST_PRACTICE, true);
            if (Utilities.noString(inv.getExplanation()))
                throw new FHIRException("Best Practice Invariants need to have an explanation");
            con.addExtension().setUrl(ToolingExtensions.EXT_BEST_PRACTICE_EXPLANATION).setValue(new MarkdownType(inv.getExplanation()));
        } else
            con.setSeverity(ConstraintSeverity.fromCode(inv.getSeverity()));
        con.setHuman(inv.getEnglish());
        con.setXpath(inv.getXpath());
        if (!Utilities.isAbsoluteUrl(source)) {
            throw new Error("source : " + source);
        }
        con.setSource(source);
        if (!"n/a".equals(inv.getExpression()))
            con.setExpression(inv.getExpression());
        ce.getConstraint().add(con);
    }
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) MarkdownType(org.hl7.fhir.r5.model.MarkdownType) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 15 with MarkdownType

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

the class RdfParser method composeMarkdown.

protected void composeMarkdown(Complex parent, String parentType, String name, MarkdownType value, int index) {
    if (value == null)
        return;
    Complex t = parent.predicate("fhir:" + parentType + "." + name);
    t.predicate("fhir:value", ttlLiteral(value.asStringValue()));
    composeElement(t, parentType, name, value, index);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Aggregations

PublicationStatusEnumFactory (org.hl7.fhir.dstu3.model.Enumerations.PublicationStatusEnumFactory)6 Test (org.junit.jupiter.api.Test)6 MarkdownType (org.hl7.fhir.r4b.model.MarkdownType)5 DisplayName (org.junit.jupiter.api.DisplayName)5 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)4 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)4 Observation (org.hl7.fhir.r4.model.Observation)4 Resource (org.hl7.fhir.r4.model.Resource)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)2 Practitioner (org.hl7.fhir.r4.model.Practitioner)2 ServiceRequest (org.hl7.fhir.r4.model.ServiceRequest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 CodeInfo (au.csiro.redmatch.terminology.CodeInfo)1 JsonElement (com.google.gson.JsonElement)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Field (java.lang.reflect.Field)1 URISyntaxException (java.net.URISyntaxException)1