Search in sources :

Example 56 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method render.

public static String render(StructureMap map) {
    StringBuilder b = new StringBuilder();
    b.append("map \"");
    b.append(map.getUrl());
    b.append("\" = \"");
    b.append(Utilities.escapeJava(map.getName()));
    b.append("\"\r\n\r\n");
    renderConceptMaps(b, map);
    renderUses(b, map);
    renderImports(b, map);
    for (StructureMapGroupComponent g : map.getGroup()) renderGroup(b, g);
    return b.toString();
}
Also used : StructureMapGroupComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupComponent) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 57 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method renderUses.

private static void renderUses(StringBuilder b, StructureMap map) {
    for (StructureMapStructureComponent s : map.getStructure()) {
        b.append("uses \"");
        b.append(s.getUrl());
        b.append("\" ");
        if (s.hasAlias()) {
            b.append("alias ");
            b.append(s.getAlias());
            b.append(" ");
        }
        b.append("as ");
        b.append(s.getMode().toCode());
        b.append("\r\n");
        renderDoco(b, s.getDocumentation());
    }
    if (map.hasStructure())
        b.append("\r\n");
}
Also used : StructureMapStructureComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapStructureComponent)

Example 58 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method generateMapFromMappings.

public StructureMap generateMapFromMappings(StructureDefinition sd) throws IOException, FHIRException {
    String id = getLogicalMappingId(sd);
    if (id == null)
        return null;
    String prefix = ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_MAPPING_PREFIX);
    String suffix = ToolingExtensions.readStringExtension(sd, ToolingExtensions.EXT_MAPPING_SUFFIX);
    if (prefix == null || suffix == null)
        return null;
    // we build this by text. Any element that has a mapping, we put it's mappings inside it....
    StringBuilder b = new StringBuilder();
    b.append(prefix);
    ElementDefinition root = sd.getSnapshot().getElementFirstRep();
    String m = getMapping(root, id);
    if (m != null)
        b.append(m + "\r\n");
    addChildMappings(b, id, "", sd, root, false);
    b.append("\r\n");
    b.append(suffix);
    b.append("\r\n");
    StructureMap map = parse(b.toString());
    map.setId(tail(map.getUrl()));
    if (!map.hasStatus())
        map.setStatus(PublicationStatus.DRAFT);
    map.getText().setStatus(NarrativeStatus.GENERATED);
    map.getText().setDiv(new XhtmlNode(NodeType.Element, "div"));
    map.getText().getDiv().addTag("pre").addText(render(map));
    return map;
}
Also used : StructureMap(org.hl7.fhir.dstu3.model.StructureMap) CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Example 59 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method processTarget.

private void processTarget(String ruleId, TransformContext context, Variables vars, StructureMap map, StructureMapGroupComponent group, StructureMapGroupRuleTargetComponent tgt, String srcVar) throws FHIRException {
    Base dest = null;
    if (tgt.hasContext()) {
        dest = vars.get(VariableMode.OUTPUT, tgt.getContext());
        if (dest == null)
            throw new FHIRException("Rule \"" + ruleId + "\": target context not known: " + tgt.getContext());
        if (!tgt.hasElement())
            throw new FHIRException("Rule \"" + ruleId + "\": Not supported yet");
    }
    Base v = null;
    if (tgt.hasTransform()) {
        v = runTransform(ruleId, context, map, group, tgt, vars, dest, tgt.getElement(), srcVar);
        if (v != null && dest != null)
            // reset v because some implementations may have to rewrite v when setting the value
            v = dest.setProperty(tgt.getElement().hashCode(), tgt.getElement(), v);
    } else if (dest != null)
        v = dest.makeProperty(tgt.getElement().hashCode(), tgt.getElement());
    if (tgt.hasVariable() && v != null)
        vars.add(VariableMode.OUTPUT, tgt.getVariable(), v);
}
Also used : FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.dstu3.model.Base)

Example 60 with StructureMap

use of org.hl7.fhir.r5.model.StructureMap in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method analyseRule.

private void analyseRule(String indent, TransformContext context, StructureMap map, VariablesForProfiling vars, StructureMapGroupComponent group, StructureMapGroupRuleComponent rule, StructureMapAnalysis result) throws Exception {
    log(indent + "Analyse rule : " + rule.getName());
    XhtmlNode tr = result.summary.addTag("tr");
    XhtmlNode xs = tr.addTag("td");
    XhtmlNode xt = tr.addTag("td");
    VariablesForProfiling srcVars = vars.copy();
    if (rule.getSource().size() != 1)
        throw new Exception("Rule \"" + rule.getName() + "\": not handled yet");
    VariablesForProfiling source = analyseSource(rule.getName(), context, srcVars, rule.getSourceFirstRep(), xs);
    TargetWriter tw = new TargetWriter();
    for (StructureMapGroupRuleTargetComponent t : rule.getTarget()) {
        analyseTarget(rule.getName(), context, source, map, t, rule.getSourceFirstRep().getVariable(), tw, result.profiles, rule.getName());
    }
    tw.commit(xt);
    for (StructureMapGroupRuleComponent childrule : rule.getRule()) {
        analyseRule(indent + "  ", context, map, source, group, childrule, result);
    }
// for (StructureMapGroupRuleDependentComponent dependent : rule.getDependent()) {
// executeDependency(indent+"  ", context, map, v, group, dependent); // do we need group here?
// }
}
Also used : FHIRLexerException(org.hl7.fhir.dstu3.utils.FHIRLexer.FHIRLexerException) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) PathEngineException(org.hl7.fhir.exceptions.PathEngineException) IOException(java.io.IOException) FHIRException(org.hl7.fhir.exceptions.FHIRException) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent) XhtmlNode(org.hl7.fhir.utilities.xhtml.XhtmlNode)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)69 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)23 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)17 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)16 StructureMap (org.hl7.fhir.r4b.model.StructureMap)13 StructureMap (org.hl7.fhir.r5.model.StructureMap)13 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 StructureMap (org.hl7.fhir.r4.model.StructureMap)11 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)10 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)9 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)9 StructureMap (org.hl7.fhir.dstu3.model.StructureMap)8 File (java.io.File)7 UriType (org.hl7.fhir.r4.model.UriType)7 Test (org.junit.jupiter.api.Test)7 Base (org.hl7.fhir.dstu3.model.Base)6 TextFile (org.hl7.fhir.utilities.TextFile)6 FileOutputStream (java.io.FileOutputStream)5