Search in sources :

Example 1 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project kindling by HL7.

the class SpreadSheetReloader method parseType.

private void parseType(ElementDefinition ed, String value, String hierarchy) throws Exception {
    ed.getType().clear();
    ed.setContentReferenceElement(null);
    if (ed.getPath().equals("Resource.id")) {
        ed.addType().setCode("http://hl7.org/fhirpath/System.String").addExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type", new UriType("id"));
    } else {
        if (Utilities.noString(value)) {
            if (ed.getPath().contains(".")) {
                ed.addType().setCode("BackboneElement");
            }
        } else if (value.startsWith("#")) {
            ed.setContentReference(value);
        } else {
            List<TypeRef> tl = new TypeParser(version).parse(value, false, null, context, false);
            for (TypeRef tr : tl) {
                TypeRefComponent t = ed.addType().setCode(tr.getName());
                if ("SimpleQuantity".equals(t.getCode())) {
                    t.setCode("Quantity");
                    t.addProfile("http://hl7.org/fhir/StructureDefinition/SimpleQuantity");
                }
                for (String p : tr.getParams()) {
                    if (p.equals("Definition")) {
                        t.addExtension(BuildExtensions.EXT_PATTERN, new CanonicalType("http://hl7.org/fhir/StructureDefinition/Definition"));
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/ActivityDefinition");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EventDefinition");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/EvidenceVariable");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Measure");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/OperationDefinition");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/PlanDefinition");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/Questionnaire");
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/SubscriptionTopic");
                    } else {
                        t.addTargetProfile("http://hl7.org/fhir/StructureDefinition/" + p);
                    }
                }
                if (Utilities.existsInList(tr.getName(), "canonical", "Reference") && !Utilities.noString(hierarchy)) {
                    t.addExtension(BuildExtensions.EXT_HIERARCHY, new BooleanType(Utilities.existsInList(hierarchy, "true", "True", "TRUE", "1", "y", "Y")));
                }
            }
        }
    }
}
Also used : TypeParser(org.hl7.fhir.definitions.parsers.TypeParser) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) TypeRef(org.hl7.fhir.definitions.model.TypeRef) BooleanType(org.hl7.fhir.r5.model.BooleanType) List(java.util.List) ArrayList(java.util.ArrayList) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) UriType(org.hl7.fhir.r5.model.UriType)

Example 2 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project kindling by HL7.

the class ResourceParser method parseED.

private void parseED(ProfileUtilities pu, ElementDefn ed, ElementDefinition focus, StructureDefinition sd, String parentName) throws IOException {
    ed.setMinCardinality(focus.getMin());
    ed.setMaxCardinality("*".equals(focus.getMax()) ? Integer.MAX_VALUE : Integer.parseInt(focus.getMax()));
    ed.setIsModifier(focus.getIsModifier());
    ed.setModifierReason(focus.getIsModifierReason());
    ed.setMustSupport(focus.getMustSupport());
    ed.setSummaryItem(focus.getIsSummary());
    ed.setRegex(ToolingExtensions.readStringExtension(focus, ToolingExtensions.EXT_REGEX));
    ed.setXmlAttribute(focus.hasRepresentation(PropertyRepresentation.XMLATTR));
    if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_DIR)) {
        ed.setUmlDir(ToolingExtensions.readStringExtension(focus, BuildExtensions.EXT_UML_DIR));
    }
    if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_UML_BREAK)) {
        ed.setUmlBreak(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_UML_BREAK));
    }
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_SVG)) {
        String svg = BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_SVG);
        if (svg.contains("w=")) {
            ed.setSvgWidth(Integer.parseInt(svg.substring(svg.indexOf("w=") + 2)));
            svg = svg.substring(0, svg.indexOf(";"));
        }
        ed.setSvgLeft(Integer.parseInt(svg.substring(0, svg.indexOf(","))));
        ed.setSvgTop(Integer.parseInt(svg.substring(svg.indexOf(",") + 1)));
    }
    ed.setName(tail(focus.getPath()));
    ed.setShortDefn(focus.getShort());
    ed.setDefinition(focus.getDefinition());
    ed.setRequirements(focus.getRequirements());
    ed.setComments(focus.getComment());
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_TODO)) {
        ed.setTodo(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_TODO));
    }
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES)) {
        ed.setCommitteeNotes(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_COMMITTEE_NOTES));
    }
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_HINT)) {
        ed.setDisplayHint(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_HINT));
    }
    if (focus.hasExtension(BuildExtensions.EXT_NO_BINDING)) {
        ed.setNoBindingAllowed(focus.getExtensionString(BuildExtensions.EXT_NO_BINDING).equals("true"));
    }
    for (StringType t : focus.getAlias()) {
        ed.getAliases().add(t.getValue());
    }
    if (focus.hasMaxLength()) {
        ed.setMaxLength(Integer.toString(focus.getMaxLength()));
    }
    ed.setExample(focus.getExampleFirstRep().getValue());
    ed.setMeaningWhenMissing(focus.getMeaningWhenMissing());
    if (ToolingExtensions.hasExtension(focus, BuildExtensions.EXT_TRANSLATABLE)) {
        ed.setTranslatable(ToolingExtensions.readBoolExtension(focus, BuildExtensions.EXT_TRANSLATABLE));
    }
    ed.setOrderMeaning(focus.getOrderMeaning());
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)) {
        ed.setStandardsStatus(StandardsStatus.fromCode(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_STANDARDS_STATUS)));
    }
    if (BuildExtensions.hasExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION)) {
        ed.setNormativeVersion(BuildExtensions.readStringExtension(focus, BuildExtensions.EXT_NORMATIVE_VERSION));
    }
    for (ElementDefinitionConstraintComponent cst : focus.getConstraint()) {
        Invariant inv = new Invariant();
        inv.setContext(focus.getPath());
        inv.setEnglish(cst.getHuman());
        if (cst.hasExtension(BuildExtensions.EXT_OCL)) {
            inv.setOcl(cst.getExtensionString(BuildExtensions.EXT_OCL));
        }
        inv.setXpath(cst.getXpath());
        inv.setId(cst.getKey());
        if (cst.hasExtension(BuildExtensions.EXT_FIXED_NAME)) {
            inv.setFixedName(cst.getExtensionString(BuildExtensions.EXT_FIXED_NAME));
        }
        inv.setSeverity(cst.getSeverity().toCode());
        if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE)) {
            inv.setSeverity("best-practice");
        }
        if (cst.hasExtension(BuildExtensions.EXT_TURTLE)) {
            inv.setTurtle(cst.getExtensionString(BuildExtensions.EXT_TURTLE));
        }
        inv.setRequirements(cst.getRequirements());
        inv.setExpression(cst.getExpression());
        if (cst.hasExtension(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION)) {
            inv.setExplanation(cst.getExtensionString(BuildExtensions.EXT_BEST_PRACTICE_EXPLANATION));
        }
        ed.getInvariants().put(inv.getId(), inv);
        invariants.put(inv.getId(), inv);
    }
    for (IdType cnd : focus.getCondition()) {
        Invariant inv = invariants.get(cnd.primitiveValue());
        if (inv == null) {
            System.out.println("Unable to find invariant " + cnd.primitiveValue());
        } else {
            ed.getStatedInvariants().add(inv);
        }
    }
    for (ElementDefinitionMappingComponent map : focus.getMapping()) {
        String uri = getMappingUri(sd, map.getIdentity());
        if ("http://hl7.org/fhir/fivews".equals(uri)) {
            ed.setW5(reverseW5(map.getMap()));
        } else {
            ed.getMappings().put(uri, map.getMap());
        }
    }
    if (focus.hasContentReference()) {
        ed.getTypes().add(new TypeRef("@" + focus.getContentReference().substring(1)));
    } else {
        for (TypeRefComponent tr : focus.getType()) {
            if (!Utilities.existsInList(tr.getCode(), "Element", "BackboneElement")) {
                TypeRef t = new TypeRef();
                ed.getTypes().add(t);
                if (tr.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")) {
                    t.setName(tr.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type"));
                } else {
                    t.setName(tr.getCode());
                }
                if (ToolingExtensions.hasExtension(tr, BuildExtensions.EXT_HIERARCHY)) {
                    ed.setHierarchy(ToolingExtensions.readBoolExtension(tr, BuildExtensions.EXT_HIERARCHY));
                }
                for (CanonicalType u : tr.getProfile()) {
                    t.setProfile(u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", ""));
                }
                for (CanonicalType u : tr.getTargetProfile()) {
                    String s = u.getValue().replace("http://hl7.org/fhir/StructureDefinition/", "");
                    if ("Resource".equals(s)) {
                        t.getParams().add("Any");
                    } else {
                        t.getParams().add(s);
                    }
                }
                if (t.getName().equals("Quantity") && "SimpleQuantity".equals(t.getProfile())) {
                    t.setName("SimpleQuantity");
                    t.setProfile(null);
                }
                if ("Resource".equals(t.getProfile())) {
                    t.setProfile("Any");
                }
                if (t.getParams().toString().equals("[ActivityDefinition, EventDefinition, EvidenceVariable, Measure, OperationDefinition, PlanDefinition, Questionnaire, SubscriptionTopic]")) {
                    t.getParams().clear();
                    t.getParams().add("Definition");
                }
            }
        }
        if (ed.getTypes().size() == STAR_TYPES_COUNT) {
            ed.getTypes().clear();
            ed.getTypes().add(new TypeRef("*"));
        }
    }
    String name = parentName + Utilities.capitalize(ed.getName());
    if (focus.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name")) {
        ed.setStatedType(focus.getExtensionString("http://hl7.org/fhir/StructureDefinition/structuredefinition-explicit-type-name"));
        ed.setDeclaredTypeName(ed.getStatedType());
    } else if (ed.getTypes().isEmpty() && !focus.hasContentReference()) {
        ed.setDeclaredTypeName(name + "Component");
    }
    if (focus.hasBinding()) {
        ed.setBinding(parseBinding(focus.getBinding()));
    }
    for (ElementDefinition child : pu.getChildList(sd, focus, true, false)) {
        ElementDefn c = new ElementDefn();
        ed.getElements().add(c);
        parseED(pu, c, child, sd, name);
    }
// todo:
// private ElementDefinition derivation;
}
Also used : Invariant(org.hl7.fhir.definitions.model.Invariant) StringType(org.hl7.fhir.r5.model.StringType) TypeRefComponent(org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent) TypeRef(org.hl7.fhir.definitions.model.TypeRef) ElementDefn(org.hl7.fhir.definitions.model.ElementDefn) ElementDefinition(org.hl7.fhir.r5.model.ElementDefinition) ElementDefinitionConstraintComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionConstraintComponent) ElementDefinitionMappingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionMappingComponent) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) IdType(org.hl7.fhir.r5.model.IdType)

Example 3 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project kindling by HL7.

the class ResourceParser method convertOperationParameter.

public OperationParameter convertOperationParameter(OperationDefinitionParameterComponent psrc, boolean part) throws IOException {
    List<String> pl = new ArrayList<>();
    for (CanonicalType u : psrc.getTargetProfile()) {
        pl.add(u.asStringValue().replace("http://hl7.org/fhir/StructureDefinition/", ""));
    }
    String t;
    if (psrc.hasExtension(BuildExtensions.EXT_ALLOWED_TYPE)) {
        for (Extension e : psrc.getExtensionsByUrl(BuildExtensions.EXT_ALLOWED_TYPE)) {
            pl.add(e.getValue().primitiveValue());
        }
        t = String.join(" | ", pl);
    } else if (psrc.hasType()) {
        t = psrc.getType().toCode();
        if (pl.size() > 0) {
            t = t + "(" + String.join("|", pl) + ")";
        }
    } else {
        t = "Tuple";
    }
    OperationParameter p = new OperationParameter(psrc.getName(), part ? null : psrc.getUse().toCode(), psrc.getDocumentation(), psrc.getMin(), psrc.getMax(), t, psrc.hasSearchType() ? psrc.getSearchType().toCode() : null, null);
    if (psrc.hasBinding()) {
        p.setBs(parseBinding(psrc.getBinding()));
    }
    for (OperationDefinitionParameterComponent pc : psrc.getPart()) {
        p.getParts().add(convertOperationParameter(pc, true));
    }
    return p;
}
Also used : Extension(org.hl7.fhir.r5.model.Extension) OperationParameter(org.hl7.fhir.definitions.model.OperationParameter) ArrayList(java.util.ArrayList) CanonicalType(org.hl7.fhir.r5.model.CanonicalType) OperationDefinitionParameterComponent(org.hl7.fhir.r5.model.OperationDefinition.OperationDefinitionParameterComponent)

Example 4 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project kindling by HL7.

the class ProfileGenerator method generateBinding.

private ElementDefinitionBindingComponent generateBinding(BindingSpecification src) throws Exception {
    if (src == null)
        return null;
    ElementDefinitionBindingComponent dst = new ElementDefinitionBindingComponent();
    dst.setDescription(src.getDescription());
    if (!Utilities.noString(src.getDefinition())) {
        dst.addExtension().setUrl(BuildExtensions.EXT_DEFINITION).setValue(new StringType(src.getDefinition()));
    }
    if (src.getBinding() != BindingMethod.Unbound) {
        dst.setStrength(src.getStrength());
        dst.setValueSet(buildValueSetReference(src));
        if (src.hasMax()) {
            dst.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-maxValueSet").setValue(new CanonicalType(src.getMaxReference() != null ? src.getMaxReference() : src.getMaxValueSet().getUrl()));
        }
    } else {
        dst.setStrength(BindingStrength.EXAMPLE);
    }
    dst.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-bindingName").setValue(new StringType(src.getName()));
    if (src.isShared())
        dst.addExtension().setUrl("http://hl7.org/fhir/StructureDefinition/elementdefinition-isCommonBinding").setValue(new BooleanType(true));
    return dst;
}
Also used : StringType(org.hl7.fhir.r5.model.StringType) BooleanType(org.hl7.fhir.r5.model.BooleanType) ElementDefinitionBindingComponent(org.hl7.fhir.r5.model.ElementDefinition.ElementDefinitionBindingComponent) CanonicalType(org.hl7.fhir.r5.model.CanonicalType)

Example 5 with CanonicalType

use of org.hl7.fhir.r4.model.CanonicalType in project cqf-ruler by DBCG.

the class CanonicalsTest method canonicalParts.

@Test
public void canonicalParts() {
    CanonicalType testUrl = new CanonicalType("http://fhir.acme.com/Questionnaire/example|1.0#vs1");
    CanonicalParts parts = Canonicals.getParts(testUrl);
    assertEquals("http://fhir.acme.com/Questionnaire/example", parts.url());
    assertEquals("Questionnaire", parts.resourceType());
    assertEquals("example", parts.idPart());
    assertEquals("1.0", parts.version());
    assertEquals("vs1", parts.fragment());
}
Also used : CanonicalType(org.hl7.fhir.r4.model.CanonicalType) Test(org.junit.jupiter.api.Test)

Aggregations

CanonicalType (org.hl7.fhir.r4.model.CanonicalType)43 CanonicalType (org.hl7.fhir.r5.model.CanonicalType)37 ArrayList (java.util.ArrayList)26 CanonicalType (org.hl7.fhir.r4b.model.CanonicalType)19 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)14 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)12 Test (org.junit.jupiter.api.Test)12 List (java.util.List)10 FHIRException (org.hl7.fhir.exceptions.FHIRException)9 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7 Library (org.hl7.fhir.r4.model.Library)7 StringType (org.hl7.fhir.r4.model.StringType)6 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)6 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)5 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)5 Extension (org.hl7.fhir.r4.model.Extension)5 IdType (org.hl7.fhir.r4.model.IdType)5