Search in sources :

Example 61 with ElementDefinition

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

the class NarrativeGenerator method filterGrandChildren.

private void filterGrandChildren(List<ElementDefinition> grandChildren, String string, PropertyWrapper prop) {
    List<ElementDefinition> toRemove = new ArrayList<ElementDefinition>();
    toRemove.addAll(grandChildren);
    for (BaseWrapper b : prop.getValues()) {
        List<ElementDefinition> list = new ArrayList<ElementDefinition>();
        for (ElementDefinition ed : toRemove) {
            PropertyWrapper p = b.getChildByName(tail(ed.getPath()));
            if (p != null && p.hasValues())
                list.add(ed);
        }
        toRemove.removeAll(list);
    }
    grandChildren.removeAll(toRemove);
}
Also used : ArrayList(java.util.ArrayList) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition)

Example 62 with ElementDefinition

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

the class NarrativeGenerator method generateByProfile.

private void generateByProfile(ResourceWrapper res, StructureDefinition profile, BaseWrapper e, List<ElementDefinition> allElements, ElementDefinition defn, List<ElementDefinition> children, XhtmlNode x, String path, boolean showCodeDetails) throws FHIRException, UnsupportedEncodingException, IOException {
    if (children.isEmpty()) {
        renderLeaf(res, e, defn, x, false, showCodeDetails, readDisplayHints(defn));
    } else {
        for (PropertyWrapper p : splitExtensions(profile, e.children())) {
            if (p.hasValues()) {
                ElementDefinition child = getElementDefinition(children, path + "." + p.getName(), p);
                if (child != null) {
                    Map<String, String> displayHints = readDisplayHints(child);
                    if (!exemptFromRendering(child)) {
                        List<ElementDefinition> grandChildren = getChildrenForPath(allElements, path + "." + p.getName());
                        filterGrandChildren(grandChildren, path + "." + p.getName(), p);
                        if (p.getValues().size() > 0 && child != null) {
                            if (isPrimitive(child)) {
                                XhtmlNode para = x.addTag("p");
                                String name = p.getName();
                                if (name.endsWith("[x]"))
                                    name = name.substring(0, name.length() - 3);
                                if (showCodeDetails || !isDefaultValue(displayHints, p.getValues())) {
                                    para.addTag("b").addText(name);
                                    para.addText(": ");
                                    if (renderAsList(child) && p.getValues().size() > 1) {
                                        XhtmlNode list = x.addTag("ul");
                                        for (BaseWrapper v : p.getValues()) renderLeaf(res, v, child, list.addTag("li"), false, showCodeDetails, displayHints);
                                    } else {
                                        boolean first = true;
                                        for (BaseWrapper v : p.getValues()) {
                                            if (first)
                                                first = false;
                                            else
                                                para.addText(", ");
                                            renderLeaf(res, v, child, para, false, showCodeDetails, displayHints);
                                        }
                                    }
                                }
                            } else if (canDoTable(path, p, grandChildren)) {
                                x.addTag("h3").addText(Utilities.capitalize(Utilities.camelCase(Utilities.pluralizeMe(p.getName()))));
                                XhtmlNode tbl = x.addTag("table").setAttribute("class", "grid");
                                XhtmlNode tr = tbl.addTag("tr");
                                // work around problem with empty table rows
                                tr.addTag("td").addText("-");
                                addColumnHeadings(tr, grandChildren);
                                for (BaseWrapper v : p.getValues()) {
                                    if (v != null) {
                                        tr = tbl.addTag("tr");
                                        // work around problem with empty table rows
                                        tr.addTag("td").addText("*");
                                        addColumnValues(res, tr, grandChildren, v, showCodeDetails, displayHints);
                                    }
                                }
                            } else {
                                for (BaseWrapper v : p.getValues()) {
                                    if (v != null) {
                                        XhtmlNode bq = x.addTag("blockquote");
                                        bq.addTag("p").addTag("b").addText(p.getName());
                                        generateByProfile(res, profile, v, allElements, child, grandChildren, bq, path + "." + p.getName(), showCodeDetails);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 63 with ElementDefinition

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

the class LoincToDEConvertor method processLoincCodes.

private void processLoincCodes() {
    Element row = XMLUtil.getFirstChild(xml.getDocumentElement());
    int i = 0;
    while (row != null) {
        i++;
        if (i % 1000 == 0)
            System.out.print(".");
        String code = col(row, "LOINC_NUM");
        String comp = col(row, "COMPONENT");
        DataElement de = new DataElement();
        de.setId("loinc-" + code);
        de.setMeta(new Meta().setLastUpdatedElement(InstantType.now()));
        bundle.getEntry().add(new BundleEntryComponent().setResource(de));
        Identifier id = new Identifier();
        id.setSystem("http://hl7.org/fhir/commondataelement/loinc");
        id.setValue(code);
        de.addIdentifier(id);
        de.setPublisher("Regenstrief + FHIR Project Team");
        if (!col(row, "STATUS").equals("ACTIVE"))
            // till we get good at this
            de.setStatus(ConformanceResourceStatus.DRAFT);
        else
            de.setStatus(ConformanceResourceStatus.RETIRED);
        de.setDateElement(DateTimeType.now());
        de.setName(comp);
        ElementDefinition dee = de.addElement();
        // PROPERTY	ignore
        // TIME_ASPCT
        // SYSTEM
        // SCALE_TYP
        // METHOD_TYP
        // dee.getCategory().add(new CodeableConcept().setText(col(row, "CLASS")));
        // SOURCE
        // DATE_LAST_CHANGED - should be in ?
        // CHNG_TYPE
        dee.setComments(col(row, "COMMENTS"));
        if (hasCol(row, "CONSUMER_NAME"))
            dee.addAlias(col(row, "CONSUMER_NAME"));
        // SURVEY_QUEST_SRC
        if (hasCol(row, "RELATEDNAMES2")) {
            String n = col(row, "RELATEDNAMES2");
            for (String s : n.split("\\;")) {
                if (!Utilities.noString(s))
                    dee.addAlias(s);
            }
        }
        dee.addAlias(col(row, "SHORTNAME"));
        // ORDER_OBS
        // CDISC Code
        // HL7_FIELD_SUBFIELD_ID
        // ------------------ EXTERNAL_COPYRIGHT_NOTICE todo
        dee.setDefinition(col(row, "LONG_COMMON_NAME"));
        // HL7_V2_DATATYPE
        String cc = makeType(col(row, "HL7_V3_DATATYPE"), code);
        if (cc != null)
            dee.addType().setCode(cc);
        // todo... CURATED_RANGE_AND_UNITS
        // todo: DOCUMENT_SECTION
        // STATUS_REASON
        // STATUS_TEXT
        // CHANGE_REASON_PUBLIC
        // COMMON_TEST_RANK
        // COMMON_ORDER_RANK
        // COMMON_SI_TEST_RANK
        // HL7_ATTACHMENT_STRUCTURE
        // units:
        // UNITSREQUIRED
        // SUBMITTED_UNITS
        ToolingExtensions.setAllowableUnits(dee, makeUnits(col(row, "EXAMPLE_UNITS"), col(row, "EXAMPLE_UCUM_UNITS")));
        // EXAMPLE_SI_UCUM_UNITS
        row = XMLUtil.getNextSibling(row);
    }
    System.out.println("done");
}
Also used : DataElement(org.hl7.fhir.dstu2.model.DataElement) Meta(org.hl7.fhir.dstu2.model.Meta) BundleEntryComponent(org.hl7.fhir.dstu2.model.Bundle.BundleEntryComponent) Identifier(org.hl7.fhir.dstu2.model.Identifier) Element(org.w3c.dom.Element) DataElement(org.hl7.fhir.dstu2.model.DataElement) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition)

Example 64 with ElementDefinition

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

the class FHIRPathEngine method getChildTypesByName.

private void getChildTypesByName(String type, String name, TypeDetails result) throws PathEngineException, DefinitionException {
    if (Utilities.noString(type))
        throw new PathEngineException("No type provided in BuildToolPathEvaluator.getChildTypesByName");
    if (type.equals("xhtml"))
        return;
    String url = null;
    if (type.contains(".")) {
        url = "http://hl7.org/fhir/StructureDefinition/" + type.substring(0, type.indexOf("."));
    } else {
        url = "http://hl7.org/fhir/StructureDefinition/" + type;
    }
    String tail = "";
    StructureDefinition sd = worker.fetchResource(StructureDefinition.class, url);
    if (sd == null)
        // this really is an error, because we can only get to here if the internal infrastrucgture is wrong
        throw new DefinitionException("Unknown type " + type);
    List<StructureDefinition> sdl = new ArrayList<StructureDefinition>();
    ElementDefinitionMatch m = null;
    if (type.contains("."))
        m = getElementDefinition(sd, type, false);
    if (m != null && hasDataType(m.definition)) {
        if (m.fixedType != null) {
            StructureDefinition dt = worker.fetchTypeDefinition(m.fixedType);
            if (dt == null)
                throw new DefinitionException("unknown data type " + m.fixedType);
            sdl.add(dt);
        } else
            for (TypeRefComponent t : m.definition.getType()) {
                StructureDefinition dt = worker.fetchTypeDefinition(t.getCode());
                if (dt == null)
                    throw new DefinitionException("unknown data type " + t.getCode());
                sdl.add(dt);
            }
    } else {
        sdl.add(sd);
        if (type.contains("."))
            tail = type.substring(type.indexOf("."));
    }
    for (StructureDefinition sdi : sdl) {
        String path = sdi.getSnapshot().getElement().get(0).getPath() + tail + ".";
        if (name.equals("**")) {
            assert (result.getCollectionStatus() == CollectionStatus.UNORDERED);
            for (ElementDefinition ed : sdi.getSnapshot().getElement()) {
                if (ed.getPath().startsWith(path))
                    for (TypeRefComponent t : ed.getType()) {
                        if (t.hasCode() && t.getCodeElement().hasValue()) {
                            String tn = null;
                            if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
                                tn = ed.getPath();
                            else
                                tn = t.getCode();
                            if (t.getCode().equals("Resource")) {
                                for (String rn : worker.getResourceNames()) {
                                    if (!result.hasType(worker, rn)) {
                                        result.addType(rn);
                                        getChildTypesByName(rn, "**", result);
                                    }
                                }
                            } else if (!result.hasType(worker, tn)) {
                                result.addType(tn);
                                getChildTypesByName(tn, "**", result);
                            }
                        }
                    }
            }
        } else if (name.equals("*")) {
            assert (result.getCollectionStatus() == CollectionStatus.UNORDERED);
            for (ElementDefinition ed : sdi.getSnapshot().getElement()) {
                if (ed.getPath().startsWith(path) && !ed.getPath().substring(path.length()).contains("."))
                    for (TypeRefComponent t : ed.getType()) {
                        if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
                            result.addType(ed.getPath());
                        else if (t.getCode().equals("Resource"))
                            result.addTypes(worker.getResourceNames());
                        else
                            result.addType(t.getCode());
                    }
            }
        } else {
            path = sdi.getSnapshot().getElement().get(0).getPath() + tail + "." + name;
            ElementDefinitionMatch ed = getElementDefinition(sdi, path, false);
            if (ed != null) {
                if (!Utilities.noString(ed.getFixedType()))
                    result.addType(ed.getFixedType());
                else
                    for (TypeRefComponent t : ed.getDefinition().getType()) {
                        if (Utilities.noString(t.getCode()))
                            // throw new PathEngineException("Illegal reference to primitive value attribute @ "+path);
                            break;
                        if (t.getCode().equals("Element") || t.getCode().equals("BackboneElement"))
                            result.addType(path);
                        else if (t.getCode().equals("Resource"))
                            result.addTypes(worker.getResourceNames());
                        else
                            result.addType(t.getCode());
                    }
            }
        }
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu2.model.StructureDefinition) TypeRefComponent(org.hl7.fhir.dstu2.model.ElementDefinition.TypeRefComponent) ArrayList(java.util.ArrayList) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) ElementDefinition(org.hl7.fhir.dstu2.model.ElementDefinition) PathEngineException(org.hl7.fhir.exceptions.PathEngineException)

Example 65 with ElementDefinition

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

the class RdfParser method composeElementDefinitionTypeRefComponent.

protected void composeElementDefinitionTypeRefComponent(Complex parent, String parentType, String name, ElementDefinition.TypeRefComponent element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeElement(t, "type", name, element, index);
    if (element.hasCodeElement())
        composeCode(t, "ElementDefinition", "code", element.getCodeElement(), -1);
    for (int i = 0; i < element.getProfile().size(); i++) composeUri(t, "ElementDefinition", "profile", element.getProfile().get(i), i);
    for (int i = 0; i < element.getAggregation().size(); i++) composeEnum(t, "ElementDefinition", "aggregation", element.getAggregation().get(i), i);
    if (element.hasVersioningElement())
        composeEnum(t, "ElementDefinition", "versioning", element.getVersioningElement(), -1);
}
Also used : Complex(org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)

Aggregations

ArrayList (java.util.ArrayList)226 ElementDefinition (org.hl7.fhir.r5.model.ElementDefinition)199 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)120 FHIRException (org.hl7.fhir.exceptions.FHIRException)116 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)92 ElementDefinition (org.hl7.fhir.r4b.model.ElementDefinition)91 ValidationMessage (org.hl7.fhir.utilities.validation.ValidationMessage)85 ElementDefinition (org.hl7.fhir.dstu3.model.ElementDefinition)82 ElementDefinition (org.hl7.fhir.r4.model.ElementDefinition)68 TypeRefComponent (org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent)60 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)57 Cell (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Cell)51 StructureDefinition (org.hl7.fhir.r4b.model.StructureDefinition)50 StructureDefinition (org.hl7.fhir.dstu3.model.StructureDefinition)46 Piece (org.hl7.fhir.utilities.xhtml.HierarchicalTableGenerator.Piece)44 ElementDefinition (org.hl7.fhir.dstu2016may.model.ElementDefinition)42 ElementDefinition (org.hl7.fhir.dstu2.model.ElementDefinition)41 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)41 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 List (java.util.List)37