Search in sources :

Example 1 with StructureMapGroupRuleSourceComponent

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

the class StructureMapUtilities method analyseSource.

private List<Variables> analyseSource(TransformContext context, Variables vars, StructureMapGroupRuleSourceComponent src) throws Exception {
    Base b = vars.get(VariableMode.INPUT, src.getContext());
    if (b == null)
        throw new FHIRException("Unknown input variable " + src.getContext());
    if (src.hasCondition()) {
        ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_EXPRESSION);
        if (expr == null) {
            expr = fpe.parse(src.getCondition());
            // fpe.check(context.appInfo, ??, ??, expr)
            src.setUserData(MAP_WHERE_EXPRESSION, expr);
        }
        if (!fpe.evaluateToBoolean(null, b, expr))
            return null;
    }
    if (src.hasCheck()) {
        ExpressionNode expr = (ExpressionNode) src.getUserData(MAP_WHERE_CHECK);
        if (expr == null) {
            expr = fpe.parse(src.getCondition());
            // fpe.check(context.appInfo, ??, ??, expr)
            src.setUserData(MAP_WHERE_CHECK, expr);
        }
        if (!fpe.evaluateToBoolean(null, b, expr))
            throw new Exception("Check condition failed");
    }
    List<Base> items = new ArrayList<Base>();
    if (!src.hasElement())
        items.add(b);
    else
        getChildrenByName(b, src.getElement(), items);
    List<Variables> result = new ArrayList<Variables>();
    for (Base r : items) {
        Variables v = vars.copy();
        if (src.hasVariable())
            v.add(VariableMode.INPUT, src.getVariable(), r);
        result.add(v);
    }
    return result;
}
Also used : ExpressionNode(org.hl7.fhir.dstu2016may.model.ExpressionNode) ArrayList(java.util.ArrayList) FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.dstu2016may.model.Base) FHIRLexerException(org.hl7.fhir.dstu2016may.utils.FHIRLexer.FHIRLexerException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 2 with StructureMapGroupRuleSourceComponent

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

the class StructureMapUtilities method analyseSource.

private VariablesForProfiling analyseSource(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMapGroupRuleSourceComponent src, XhtmlNode td) throws Exception {
    VariableForProfiling var = vars.get(VariableMode.INPUT, src.getContext());
    if (var == null)
        throw new FHIRException("Rule \"" + ruleId + "\": Unknown input variable " + src.getContext());
    PropertyWithType prop = var.getProperty();
    boolean optional = false;
    boolean repeating = false;
    if (src.hasCondition()) {
        optional = true;
    }
    if (src.hasElement()) {
        Property element = prop.getBaseProperty().getChild(prop.types.getType(), src.getElement());
        if (element == null)
            throw new Exception("Rule \"" + ruleId + "\": Unknown element name " + src.getElement());
        if (element.getDefinition().getMin() == 0)
            optional = true;
        if (element.getDefinition().getMax().equals("*"))
            repeating = true;
        VariablesForProfiling result = vars.copy(optional, repeating);
        TypeDetails type = new TypeDetails(CollectionStatus.SINGLETON);
        for (TypeRefComponent tr : element.getDefinition().getType()) {
            if (!tr.hasCode())
                throw new Error("Rule \"" + ruleId + "\": Element has no type");
            ProfiledType pt = new ProfiledType(tr.getCode());
            if (tr.hasProfile())
                pt.addProfile(tr.getProfile());
            if (element.getDefinition().hasBinding())
                pt.addBinding(element.getDefinition().getBinding());
            type.addType(pt);
        }
        td.addText(prop.getPath() + "." + src.getElement());
        if (src.hasVariable())
            result.add(VariableMode.INPUT, src.getVariable(), new PropertyWithType(prop.getPath() + "." + src.getElement(), element, null, type));
        return result;
    } else {
        // ditto!
        td.addText(prop.getPath());
        return vars.copy(optional, repeating);
    }
}
Also used : TypeDetails(org.hl7.fhir.dstu3.model.TypeDetails) ProfiledType(org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType) TypeRefComponent(org.hl7.fhir.dstu3.model.ElementDefinition.TypeRefComponent) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException) Property(org.hl7.fhir.dstu3.elementmodel.Property) 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)

Example 3 with StructureMapGroupRuleSourceComponent

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

the class StructureMapUtilities method sourceToString.

public static String sourceToString(StructureMapGroupRuleSourceComponent r) {
    StringBuilder b = new StringBuilder();
    renderSource(b, r, false);
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 4 with StructureMapGroupRuleSourceComponent

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

the class MappingSheetParser method getStructureMap.

public StructureMap getStructureMap() throws FHIRException {
    StructureMap map = new StructureMap();
    loadMetadata(map);
    if (metadata.containsKey("copyright"))
        map.setCopyright(metadata.get("copyright"));
    StructureMapGroupComponent grp = map.addGroup();
    for (MappingRow row : rows) {
        StructureMapGroupRuleComponent rule = grp.addRule();
        rule.setName(row.getSequence());
        StructureMapGroupRuleSourceComponent src = rule.getSourceFirstRep();
        src.setContext("src");
        src.setElement(row.getIdentifier());
        src.setMin(row.getCardinalityMin());
        src.setMax(row.getCardinalityMax());
        src.setType(row.getDataType());
        src.addExtension(ToolingExtensions.EXT_MAPPING_NAME, new StringType(row.getName()));
        if (row.getCondition() != null) {
            src.setCheck(processCondition(row.getCondition()));
        }
        StructureMapGroupRuleTargetComponent tgt = rule.getTargetFirstRep();
        tgt.setContext("tgt");
        tgt.setElement(row.getAttribute());
        tgt.addExtension(ToolingExtensions.EXT_MAPPING_TGTTYPE, new StringType(row.getType()));
        tgt.addExtension(ToolingExtensions.EXT_MAPPING_TGTCARD, new StringType(row.getMinMax()));
        if (row.getDtMapping() != null) {
            src.setVariable("s");
            tgt.setVariable("t");
            tgt.setTransform(StructureMapTransform.CREATE);
            StructureMapGroupRuleDependentComponent dep = rule.addDependent();
            dep.setName(row.getDtMapping());
            dep.addVariable("s");
            dep.addVariable("t");
        } else if (row.getVocabMapping() != null) {
            tgt.setTransform(StructureMapTransform.TRANSLATE);
            tgt.addParameter().setValue(new StringType(row.getVocabMapping()));
            tgt.addParameter().setValue(new IdType("src"));
        } else {
            tgt.setTransform(StructureMapTransform.COPY);
        }
        rule.setDocumentation(row.getComments());
        if (row.getDerived() != null) {
            tgt = rule.addTarget();
            tgt.setContext("tgt");
            tgt.setElement(row.getDerived());
            tgt.setTransform(StructureMapTransform.COPY);
            tgt.addParameter().setValue(new StringType(row.getDerivedMapping()));
        }
    }
    return map;
}
Also used : StructureMap(org.hl7.fhir.r4b.model.StructureMap) StructureMapGroupComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupComponent) StringType(org.hl7.fhir.r4b.model.StringType) StructureMapGroupRuleDependentComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleDependentComponent) StructureMapGroupRuleComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleComponent) StructureMapGroupRuleSourceComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleSourceComponent) StructureMapGroupRuleTargetComponent(org.hl7.fhir.r4b.model.StructureMap.StructureMapGroupRuleTargetComponent) IdType(org.hl7.fhir.r4b.model.IdType)

Example 5 with StructureMapGroupRuleSourceComponent

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

the class StructureMapUtilities method analyseSource.

private VariablesForProfiling analyseSource(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMapGroupRuleSourceComponent src, XhtmlNode td) throws FHIRException {
    VariableForProfiling var = vars.get(VariableMode.INPUT, src.getContext());
    if (var == null)
        throw new FHIRException("Rule \"" + ruleId + "\": Unknown input variable " + src.getContext());
    PropertyWithType prop = var.getProperty();
    boolean optional = false;
    boolean repeating = false;
    if (src.hasCondition()) {
        optional = true;
    }
    if (src.hasElement()) {
        Property element = prop.getBaseProperty().getChild(prop.getTypes().getType(), src.getElement());
        if (element == null)
            throw new FHIRException("Rule \"" + ruleId + "\": Unknown element name " + src.getElement());
        if (element.getDefinition().getMin() == 0)
            optional = true;
        if (element.getDefinition().getMax().equals("*"))
            repeating = true;
        VariablesForProfiling result = vars.copy(optional, repeating);
        TypeDetails type = new TypeDetails(CollectionStatus.SINGLETON);
        for (TypeRefComponent tr : element.getDefinition().getType()) {
            if (!tr.hasCode())
                throw new Error("Rule \"" + ruleId + "\": Element has no type");
            ProfiledType pt = new ProfiledType(tr.getWorkingCode());
            if (tr.hasProfile())
                pt.addProfiles(tr.getProfile());
            if (element.getDefinition().hasBinding())
                pt.addBinding(element.getDefinition().getBinding());
            type.addType(pt);
        }
        td.addText(prop.getPath() + "." + src.getElement());
        if (src.hasVariable())
            result.add(VariableMode.INPUT, src.getVariable(), new PropertyWithType(prop.getPath() + "." + src.getElement(), element, null, type));
        return result;
    } else {
        // ditto!
        td.addText(prop.getPath());
        return vars.copy(optional, repeating);
    }
}
Also used : ProfiledType(org.hl7.fhir.r4b.model.TypeDetails.ProfiledType) TypeRefComponent(org.hl7.fhir.r4b.model.ElementDefinition.TypeRefComponent) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException) Property(org.hl7.fhir.r4b.elementmodel.Property)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)9 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)7 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)4 ArrayList (java.util.ArrayList)3 StringType (org.hl7.fhir.dstu3.model.StringType)3 StringType (org.hl7.fhir.r4.model.StringType)3 ExpressionNode (org.hl7.fhir.dstu2016may.model.ExpressionNode)2 StructureMapGroupRuleSourceComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleSourceComponent)2 ExpressionNode (org.hl7.fhir.dstu3.model.ExpressionNode)2 StructureMapGroupRuleSourceComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleSourceComponent)2 ExpressionNode (org.hl7.fhir.r4.model.ExpressionNode)2 StructureMapGroupRuleSourceComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleSourceComponent)2 IOException (java.io.IOException)1 Base (org.hl7.fhir.dstu2016may.model.Base)1 StringType (org.hl7.fhir.dstu2016may.model.StringType)1 StructureMapGroupRuleDependentComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleDependentComponent)1 StructureMapGroupRuleTargetComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent)1 FHIRLexerException (org.hl7.fhir.dstu2016may.utils.FHIRLexer.FHIRLexerException)1 Property (org.hl7.fhir.dstu3.elementmodel.Property)1 Base (org.hl7.fhir.dstu3.model.Base)1