Search in sources :

Example 6 with StringType

use of org.hl7.fhir.dstu2.model.StringType in project kindling by HL7.

the class Regenerator method generateInner.

public void generateInner(ResourceDefn r) throws FileNotFoundException, IOException {
    String root = Utilities.path(srcFolder, r.getName());
    generateSearchParams(root, r);
    generateExamples(root, r);
    generateOperations(r, root);
    generatePacks(r, root);
    // private List<Profile> conformancePackages = new ArrayList<Profile>();
    // private Profile conformancePack;
    StructureDefinition sd = r.getProfile().copy();
    sd.setSnapshot(null);
    sd.setText(null);
    if (r.getEnteredInErrorStatus() != null) {
        sd.addExtension(BuildExtensions.EXT_ENTERED_IN_ERROR_STATUS, new CodeType(r.getEnteredInErrorStatus()));
    }
    if (r.getProposedOrder() != null) {
        sd.addExtension(BuildExtensions.EXT_PROPOSED_ORDER, new StringType(r.getProposedOrder()));
    }
    if (r.getTemplate() != null) {
        sd.addExtension(BuildExtensions.EXT_TEMPLATE, new StringType(r.getTemplate().getName()));
    }
    // now, walk through the elements.
    generateElement(root, r.getName(), sd.getDifferential(), r, r.getRoot());
    File fn = new File(Utilities.path(root, sd.fhirType().toLowerCase() + "-" + sd.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), sd);
    fn.setLastModified(r.getTimestamp());
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) StringType(org.hl7.fhir.r5.model.StringType) FileOutputStream(java.io.FileOutputStream) CodeType(org.hl7.fhir.r5.model.CodeType) File(java.io.File)

Example 7 with StringType

use of org.hl7.fhir.dstu2.model.StringType in project kindling by HL7.

the class Regenerator method generateExamples.

private void generateExamples(String root, ResourceDefn r) throws FileNotFoundException, IOException {
    ListResource list = new ListResource();
    list.setId(r.getName() + "-examples");
    list.setStatus(ListStatus.CURRENT);
    list.setMode(ListMode.WORKING);
    for (Example ex : r.getExamples()) {
        ListResourceEntryComponent li = list.addEntry();
        li.getItem().setReference(ex.getResourceName() + "/" + ex.getId());
        li.getItem().setDisplay(ex.getName());
        if (ex.getDescription() != null) {
            li.addExtension(BuildExtensions.EXT_DESCRIPTION, new StringType(ex.getDescription()));
        }
        if (ex.getTitle() != null) {
            li.addExtension(BuildExtensions.EXT_TITLE, new StringType(ex.getTitle()));
        }
        switch(ex.getType()) {
            case Container:
                li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "container", null);
                break;
            case CsvFile:
                li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "csv", null);
                break;
            case Tool:
                li.getFlag().addCoding(BuildExtensions.EXT_EXAMPLE_TYPE, "tool", null);
                break;
            default:
                break;
        }
        if (!ex.isRegistered()) {
            li.addExtension(BuildExtensions.EXT_NOT_REGISTERED, new BooleanType(!ex.isRegistered()));
        }
        if (ex.getIg() != null) {
            li.addExtension(BuildExtensions.EXT_IG, new CodeType(ex.getIg()));
        }
        if (ex.getExampleFor() != null) {
            li.addExtension(BuildExtensions.EXT_EXAMPLE_FOR, new StringType(ex.getExampleFor()));
        }
    }
    File fn = new File(Utilities.path(root, list.fhirType().toLowerCase() + "-" + list.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), list);
    fn.setLastModified(r.getTimestamp());
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) StringType(org.hl7.fhir.r5.model.StringType) Example(org.hl7.fhir.definitions.model.Example) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) ListResourceEntryComponent(org.hl7.fhir.r5.model.ListResource.ListResourceEntryComponent) FileOutputStream(java.io.FileOutputStream) BooleanType(org.hl7.fhir.r5.model.BooleanType) CodeType(org.hl7.fhir.r5.model.CodeType) ListResource(org.hl7.fhir.r5.model.ListResource) File(java.io.File)

Example 8 with StringType

use of org.hl7.fhir.dstu2.model.StringType 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 9 with StringType

use of org.hl7.fhir.dstu2.model.StringType in project kindling by HL7.

the class Regenerator method generateOperation.

private void generateOperation(String root, ResourceDefn r, Operation op) throws IOException {
    OperationDefinition opd = op.getResource().copy();
    opd.setId(r.getName() + "-" + op.getName());
    opd.setUrl("http://hl7.org/fhir/build/OperationDefinition/" + opd.getId());
    if (!Utilities.noString(op.getFooter())) {
        opd.addExtension(BuildExtensions.EXT_FOOTER, new MarkdownType(op.getFooter()));
    }
    if (!Utilities.noString(op.getFooter2())) {
        opd.addExtension(BuildExtensions.EXT_FOOTER2, new MarkdownType(op.getFooter2()));
    }
    for (OperationExample opex : op.getExamples()) {
        Extension ex = new Extension(BuildExtensions.EXT_OP_EXAMPLE);
        if (!Utilities.noString(opex.getContent())) {
            ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_CONTENT, new StringType(opex.getContent()));
        }
        if (!Utilities.noString(opex.getComment())) {
            ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_COMMENT, new StringType(opex.getComment()));
        }
        ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_RESPONSE, new BooleanType(opex.isResponse()));
        ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_LIST, new IntegerType(1));
        opd.addExtension(ex);
    }
    for (OperationExample opex : op.getExamples2()) {
        Extension ex = new Extension(BuildExtensions.EXT_OP_EXAMPLE);
        if (!Utilities.noString(opex.getContent())) {
            ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_CONTENT, new StringType(opex.getContent()));
        }
        if (!Utilities.noString(opex.getComment())) {
            ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_COMMENT, new StringType(opex.getComment()));
        }
        ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_RESPONSE, new BooleanType(opex.isResponse()));
        ex.addExtension(BuildExtensions.EXT_OP_EXAMPLE_LIST, new IntegerType(2));
        opd.addExtension(ex);
    }
    File fn = new File(Utilities.path(root, opd.fhirType().toLowerCase() + "-" + opd.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), opd);
    fn.setLastModified(r.getTimestamp());
}
Also used : Extension(org.hl7.fhir.r5.model.Extension) IntegerType(org.hl7.fhir.r5.model.IntegerType) XmlParser(org.hl7.fhir.r5.formats.XmlParser) OperationExample(org.hl7.fhir.definitions.model.Operation.OperationExample) StringType(org.hl7.fhir.r5.model.StringType) FileOutputStream(java.io.FileOutputStream) BooleanType(org.hl7.fhir.r5.model.BooleanType) MarkdownType(org.hl7.fhir.r5.model.MarkdownType) OperationDefinition(org.hl7.fhir.r5.model.OperationDefinition) File(java.io.File)

Example 10 with StringType

use of org.hl7.fhir.dstu2.model.StringType 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)

Aggregations

StringType (org.hl7.fhir.r4.model.StringType)158 ArrayList (java.util.ArrayList)77 Test (org.junit.jupiter.api.Test)77 StringType (org.hl7.fhir.dstu3.model.StringType)65 Parameters (org.hl7.fhir.r4.model.Parameters)62 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)62 StringType (org.hl7.fhir.r5.model.StringType)61 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)58 StringType (org.hl7.fhir.r4b.model.StringType)45 FHIRException (org.hl7.fhir.exceptions.FHIRException)43 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)42 HashMap (java.util.HashMap)28 StringType (org.hl7.fhir.dstu2.model.StringType)27 StringType (org.hl7.fhir.dstu2016may.model.StringType)26 Coding (org.hl7.fhir.r4.model.Coding)26 Extension (org.hl7.fhir.r4.model.Extension)25 Measure (org.hl7.fhir.r4.model.Measure)23 Test (org.junit.Test)23 Base (org.hl7.fhir.r5.model.Base)20 NotImplementedException (org.apache.commons.lang3.NotImplementedException)19