Search in sources :

Example 11 with StructureMapGroupRuleTargetParameterComponent

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

the class StructureMapUtilities method analyseTarget.

private void analyseTarget(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMap map, StructureMapGroupRuleTargetComponent tgt, String tv, TargetWriter tw, List<StructureDefinition> profiles, String sliceName) throws FHIRException {
    VariableForProfiling var = null;
    if (tgt.hasContext()) {
        var = vars.get(VariableMode.OUTPUT, tgt.getContext());
        if (var == null)
            throw new FHIRException("Rule \"" + ruleId + "\": target context not known: " + tgt.getContext());
        if (!tgt.hasElement())
            throw new FHIRException("Rule \"" + ruleId + "\": Not supported yet");
    }
    TypeDetails type = null;
    if (tgt.hasTransform()) {
        type = analyseTransform(context, map, tgt, var, vars);
    } else {
        Property vp = var.getProperty().getBaseProperty().getChild(tgt.getElement(), tgt.getElement());
        if (vp == null)
            throw new FHIRException("Unknown Property " + tgt.getElement() + " on " + var.getProperty().getPath());
        type = new TypeDetails(CollectionStatus.SINGLETON, vp.getType(tgt.getElement()));
    }
    if (tgt.getTransform() == StructureMapTransform.CREATE) {
        String s = getParamString(vars, tgt.getParameter().get(0));
        if (worker.getResourceNames().contains(s))
            tw.newResource(tgt.getVariable(), s);
    } else {
        boolean mapsSrc = false;
        for (StructureMapGroupRuleTargetParameterComponent p : tgt.getParameter()) {
            DataType pr = p.getValue();
            if (pr instanceof IdType && ((IdType) pr).asStringValue().equals(tv))
                mapsSrc = true;
        }
        if (mapsSrc) {
            if (var == null)
                throw new Error("Rule \"" + ruleId + "\": Attempt to assign with no context");
            tw.valueAssignment(tgt.getContext(), var.getProperty().getPath() + "." + tgt.getElement() + getTransformSuffix(tgt.getTransform()));
        } else if (tgt.hasContext()) {
            if (isSignificantElement(var.getProperty(), tgt.getElement())) {
                String td = describeTransform(tgt);
                if (td != null)
                    tw.keyAssignment(tgt.getContext(), var.getProperty().getPath() + "." + tgt.getElement() + " = " + td);
            }
        }
    }
    DataType fixed = generateFixedValue(tgt);
    PropertyWithType prop = updateProfile(var, tgt.getElement(), type, map, profiles, sliceName, fixed, tgt);
    if (tgt.hasVariable())
        if (tgt.hasElement())
            vars.add(VariableMode.OUTPUT, tgt.getVariable(), prop);
        else
            vars.add(VariableMode.OUTPUT, tgt.getVariable(), prop);
}
Also used : FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException) Property(org.hl7.fhir.r5.elementmodel.Property)

Example 12 with StructureMapGroupRuleTargetParameterComponent

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

the class StructureMapUtilities method getParam.

private Base getParam(Variables vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException {
    DataType p = parameter.getValue();
    if (!(p instanceof IdType))
        return p;
    else {
        String n = ((IdType) p).asStringValue();
        Base b = vars.get(VariableMode.INPUT, n);
        if (b == null)
            b = vars.get(VariableMode.OUTPUT, n);
        if (b == null)
            throw new DefinitionException("Variable " + n + " not found (" + vars.summary() + ")");
        return b;
    }
}
Also used : DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 13 with StructureMapGroupRuleTargetParameterComponent

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

the class StructureMapUtilities method analyseTarget.

private void analyseTarget(String ruleId, TransformContext context, VariablesForProfiling vars, StructureMap map, StructureMapGroupRuleTargetComponent tgt, String tv, TargetWriter tw, List<StructureDefinition> profiles, String sliceName) throws Exception {
    VariableForProfiling var = null;
    if (tgt.hasContext()) {
        var = vars.get(VariableMode.OUTPUT, tgt.getContext());
        if (var == null)
            throw new Exception("Rule \"" + ruleId + "\": target context not known: " + tgt.getContext());
        if (!tgt.hasElement())
            throw new Exception("Rule \"" + ruleId + "\": Not supported yet");
    }
    TypeDetails type = null;
    if (tgt.hasTransform()) {
        type = analyseTransform(context, map, tgt, var, vars);
    // profiling: dest.setProperty(tgt.getElement().hashCode(), tgt.getElement(), v);
    } else {
        Property vp = var.property.baseProperty.getChild(tgt.getElement(), tgt.getElement());
        if (vp == null)
            throw new Exception("Unknown Property " + tgt.getElement() + " on " + var.property.path);
        type = new TypeDetails(CollectionStatus.SINGLETON, vp.getType(tgt.getElement()));
    }
    if (tgt.getTransform() == StructureMapTransform.CREATE) {
        String s = getParamString(vars, tgt.getParameter().get(0));
        if (worker.getResourceNames().contains(s))
            tw.newResource(tgt.getVariable(), s);
    } else {
        boolean mapsSrc = false;
        for (StructureMapGroupRuleTargetParameterComponent p : tgt.getParameter()) {
            Type pr = p.getValue();
            if (pr instanceof IdType && ((IdType) pr).asStringValue().equals(tv))
                mapsSrc = true;
        }
        if (mapsSrc) {
            if (var == null)
                throw new Error("Rule \"" + ruleId + "\": Attempt to assign with no context");
            tw.valueAssignment(tgt.getContext(), var.property.getPath() + "." + tgt.getElement() + getTransformSuffix(tgt.getTransform()));
        } else if (tgt.hasContext()) {
            if (isSignificantElement(var.property, tgt.getElement())) {
                String td = describeTransform(tgt);
                if (td != null)
                    tw.keyAssignment(tgt.getContext(), var.property.getPath() + "." + tgt.getElement() + " = " + td);
            }
        }
    }
    Type fixed = generateFixedValue(tgt);
    PropertyWithType prop = updateProfile(var, tgt.getElement(), type, map, profiles, sliceName, fixed, tgt);
    if (tgt.hasVariable())
        if (tgt.hasElement())
            vars.add(VariableMode.OUTPUT, tgt.getVariable(), prop);
        else
            vars.add(VariableMode.OUTPUT, tgt.getVariable(), prop);
}
Also used : TypeDetails(org.hl7.fhir.dstu3.model.TypeDetails) NodeType(org.hl7.fhir.utilities.xhtml.NodeType) Type(org.hl7.fhir.dstu3.model.Type) IdType(org.hl7.fhir.dstu3.model.IdType) StringType(org.hl7.fhir.dstu3.model.StringType) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) CodeType(org.hl7.fhir.dstu3.model.CodeType) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) ProfiledType(org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType) UriType(org.hl7.fhir.dstu3.model.UriType) StructureMapContextType(org.hl7.fhir.dstu3.model.StructureMap.StructureMapContextType) DecimalType(org.hl7.fhir.dstu3.model.DecimalType) PrimitiveType(org.hl7.fhir.dstu3.model.PrimitiveType) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) StructureMapGroupRuleTargetParameterComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetParameterComponent) 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) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 14 with StructureMapGroupRuleTargetParameterComponent

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

the class StructureMapUtilities method getParam.

private TypeDetails getParam(VariablesForProfiling vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException {
    Type p = parameter.getValue();
    if (!(p instanceof IdType))
        return new TypeDetails(CollectionStatus.SINGLETON, "http://hl7.org/fhir/StructureDefinition/" + p.fhirType());
    else {
        String n = ((IdType) p).asStringValue();
        VariableForProfiling b = vars.get(VariableMode.INPUT, n);
        if (b == null)
            b = vars.get(VariableMode.OUTPUT, n);
        if (b == null)
            throw new DefinitionException("Variable " + n + " not found (" + vars.summary() + ")");
        return b.getProperty().getTypes();
    }
}
Also used : TypeDetails(org.hl7.fhir.dstu3.model.TypeDetails) NodeType(org.hl7.fhir.utilities.xhtml.NodeType) Type(org.hl7.fhir.dstu3.model.Type) IdType(org.hl7.fhir.dstu3.model.IdType) StringType(org.hl7.fhir.dstu3.model.StringType) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) CodeType(org.hl7.fhir.dstu3.model.CodeType) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) ProfiledType(org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType) UriType(org.hl7.fhir.dstu3.model.UriType) StructureMapContextType(org.hl7.fhir.dstu3.model.StructureMap.StructureMapContextType) DecimalType(org.hl7.fhir.dstu3.model.DecimalType) PrimitiveType(org.hl7.fhir.dstu3.model.PrimitiveType) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 15 with StructureMapGroupRuleTargetParameterComponent

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

the class StructureMapUtilities method getParam.

private Base getParam(Variables vars, StructureMapGroupRuleTargetParameterComponent parameter) throws DefinitionException {
    Type p = parameter.getValue();
    if (!(p instanceof IdType))
        return p;
    else {
        String n = ((IdType) p).asStringValue();
        Base b = vars.get(VariableMode.INPUT, n);
        if (b == null)
            b = vars.get(VariableMode.OUTPUT, n);
        if (b == null)
            throw new DefinitionException("Variable " + n + " not found (" + vars.summary() + ")");
        return b;
    }
}
Also used : NodeType(org.hl7.fhir.utilities.xhtml.NodeType) Type(org.hl7.fhir.dstu3.model.Type) IdType(org.hl7.fhir.dstu3.model.IdType) StringType(org.hl7.fhir.dstu3.model.StringType) BooleanType(org.hl7.fhir.dstu3.model.BooleanType) CodeType(org.hl7.fhir.dstu3.model.CodeType) IntegerType(org.hl7.fhir.dstu3.model.IntegerType) ProfiledType(org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType) UriType(org.hl7.fhir.dstu3.model.UriType) StructureMapContextType(org.hl7.fhir.dstu3.model.StructureMap.StructureMapContextType) DecimalType(org.hl7.fhir.dstu3.model.DecimalType) PrimitiveType(org.hl7.fhir.dstu3.model.PrimitiveType) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) Base(org.hl7.fhir.dstu3.model.Base) IdType(org.hl7.fhir.dstu3.model.IdType)

Aggregations

DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 NodeType (org.hl7.fhir.utilities.xhtml.NodeType)6 FHIRException (org.hl7.fhir.exceptions.FHIRException)5 StringType (org.hl7.fhir.dstu3.model.StringType)4 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)4 StringType (org.hl7.fhir.r4.model.StringType)4 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)4 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)3 CodeType (org.hl7.fhir.dstu3.model.CodeType)3 DecimalType (org.hl7.fhir.dstu3.model.DecimalType)3 IdType (org.hl7.fhir.dstu3.model.IdType)3 IntegerType (org.hl7.fhir.dstu3.model.IntegerType)3 PrimitiveType (org.hl7.fhir.dstu3.model.PrimitiveType)3 StructureMapContextType (org.hl7.fhir.dstu3.model.StructureMap.StructureMapContextType)3 Type (org.hl7.fhir.dstu3.model.Type)3 ProfiledType (org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType)3 UriType (org.hl7.fhir.dstu3.model.UriType)3 BooleanType (org.hl7.fhir.r4.model.BooleanType)3 CanonicalType (org.hl7.fhir.r4.model.CanonicalType)3 CodeType (org.hl7.fhir.r4.model.CodeType)3