Search in sources :

Example 1 with StructureMapGroupRuleTargetComponent

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

the class StructureMapUtilities method runTransform.

private Base runTransform(TransformContext context, StructureMap map, StructureMapGroupRuleTargetComponent tgt, Variables vars) throws FHIRException {
    switch(tgt.getTransform()) {
        case CREATE:
            return ResourceFactory.createResourceOrType(getParamString(vars, tgt.getParameter().get(0)));
        case COPY:
            return getParam(vars, tgt.getParameter().get(0));
        case EVALUATE:
            ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
            if (expr == null) {
                expr = fpe.parse(getParamString(vars, tgt.getParameter().get(1)));
                tgt.setUserData(MAP_WHERE_EXPRESSION, expr);
            }
            List<Base> v = fpe.evaluate(null, null, getParam(vars, tgt.getParameter().get(0)), expr);
            if (v.size() != 1)
                throw new FHIRException("evaluation of " + expr.toString() + " returned " + Integer.toString(v.size()) + " objects");
            return v.get(0);
        case TRUNCATE:
            String src = getParamString(vars, tgt.getParameter().get(0));
            String len = getParamString(vars, tgt.getParameter().get(1));
            if (Utilities.isInteger(len)) {
                int l = Integer.parseInt(len);
                if (src.length() > l)
                    src = src.substring(0, l);
            }
            return new StringType(src);
        case ESCAPE:
            throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
        case CAST:
            throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
        case APPEND:
            throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
        case TRANSLATE:
            return translate(context, map, vars, tgt.getParameter());
        case REFERENCE:
            throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
        case DATEOP:
            throw new Error("Transform " + tgt.getTransform().toCode() + " not supported yet");
        case UUID:
            return new IdType(UUID.randomUUID().toString());
        case POINTER:
            Base b = getParam(vars, tgt.getParameter().get(0));
            if (b instanceof Resource)
                return new UriType("urn:uuid:" + ((Resource) b).getId());
            else
                throw new FHIRException("Transform engine cannot point at an element of type " + b.fhirType());
        default:
            throw new Error("Transform Unknown: " + tgt.getTransform().toCode());
    }
}
Also used : StringType(org.hl7.fhir.dstu2016may.model.StringType) ExpressionNode(org.hl7.fhir.dstu2016may.model.ExpressionNode) Resource(org.hl7.fhir.dstu2016may.model.Resource) FHIRException(org.hl7.fhir.exceptions.FHIRException) Base(org.hl7.fhir.dstu2016may.model.Base) IdType(org.hl7.fhir.dstu2016may.model.IdType) UriType(org.hl7.fhir.dstu2016may.model.UriType)

Example 2 with StructureMapGroupRuleTargetComponent

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

the class StructureMapUtilities method renderTarget.

private static void renderTarget(StringBuilder b, StructureMapGroupRuleTargetComponent rt, boolean abbreviate) {
    if (rt.hasContext()) {
        if (rt.getContextType() == StructureMapContextType.TYPE)
            b.append("@");
        b.append(rt.getContext());
        if (rt.hasElement()) {
            b.append('.');
            b.append(rt.getElement());
        }
    }
    if (!abbreviate && rt.hasTransform()) {
        if (rt.hasContext())
            b.append(" = ");
        if (rt.getTransform() == StructureMapTransform.COPY && rt.getParameter().size() == 1) {
            renderTransformParam(b, rt.getParameter().get(0));
        } else if (rt.getTransform() == StructureMapTransform.EVALUATE && rt.getParameter().size() == 1) {
            b.append("(");
            b.append("\"" + ((StringType) rt.getParameter().get(0).getValue()).asStringValue() + "\"");
            b.append(")");
        } else if (rt.getTransform() == StructureMapTransform.EVALUATE && rt.getParameter().size() == 2) {
            b.append(rt.getTransform().toCode());
            b.append("(");
            b.append(((IdType) rt.getParameter().get(0).getValue()).asStringValue());
            b.append("\"" + ((StringType) rt.getParameter().get(1).getValue()).asStringValue() + "\"");
            b.append(")");
        } else {
            b.append(rt.getTransform().toCode());
            b.append("(");
            boolean first = true;
            for (StructureMapGroupRuleTargetParameterComponent rtp : rt.getParameter()) {
                if (first)
                    first = false;
                else
                    b.append(", ");
                renderTransformParam(b, rtp);
            }
            b.append(")");
        }
    }
    if (!abbreviate && rt.hasVariable()) {
        b.append(" as ");
        b.append(rt.getVariable());
    }
    for (Enumeration<StructureMapTargetListMode> lm : rt.getListMode()) {
        b.append(" ");
        b.append(lm.getValue().toCode());
        if (lm.getValue() == StructureMapTargetListMode.SHARE) {
            b.append(" ");
            b.append(rt.getListRuleId());
        }
    }
}
Also used : StructureMapTargetListMode(org.hl7.fhir.dstu3.model.StructureMap.StructureMapTargetListMode) StringType(org.hl7.fhir.dstu3.model.StringType) StructureMapGroupRuleTargetParameterComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetParameterComponent)

Example 3 with StructureMapGroupRuleTargetComponent

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

the class StructureMapUtilities method targetToString.

public static String targetToString(StructureMapGroupRuleTargetComponent rt) {
    StringBuilder b = new StringBuilder();
    renderTarget(b, rt, false);
    return b.toString();
}
Also used : CommaSeparatedStringBuilder(org.hl7.fhir.utilities.CommaSeparatedStringBuilder)

Example 4 with StructureMapGroupRuleTargetComponent

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

the class StructureMapUtilities method generateFixedValue.

private Type generateFixedValue(StructureMapGroupRuleTargetComponent tgt) {
    if (!allParametersFixed(tgt))
        return null;
    if (!tgt.hasTransform())
        return null;
    switch(tgt.getTransform()) {
        case COPY:
            return tgt.getParameter().get(0).getValue();
        case TRUNCATE:
            return null;
        // case APPEND:
        case TRANSLATE:
            return null;
        // case EVALUATE,
        case CC:
            CodeableConcept cc = new CodeableConcept();
            cc.addCoding(buildCoding(tgt.getParameter().get(0).getValue(), tgt.getParameter().get(1).getValue()));
            return cc;
        case C:
            return buildCoding(tgt.getParameter().get(0).getValue(), tgt.getParameter().get(1).getValue());
        case QTY:
            return null;
        // case CP,
        default:
            return null;
    }
}
Also used : CodeableConcept(org.hl7.fhir.dstu3.model.CodeableConcept)

Example 5 with StructureMapGroupRuleTargetComponent

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

the class StructureMapUtilities method analyseTransform.

private TypeDetails analyseTransform(TransformContext context, StructureMap map, StructureMapGroupRuleTargetComponent tgt, VariableForProfiling var, VariablesForProfiling vars) throws FHIRException {
    switch(tgt.getTransform()) {
        case CREATE:
            String p = getParamString(vars, tgt.getParameter().get(0));
            return new TypeDetails(CollectionStatus.SINGLETON, p);
        case COPY:
            return getParam(vars, tgt.getParameter().get(0));
        case EVALUATE:
            ExpressionNode expr = (ExpressionNode) tgt.getUserData(MAP_EXPRESSION);
            if (expr == null) {
                expr = fpe.parse(getParamString(vars, tgt.getParameter().get(tgt.getParameter().size() - 1)));
                tgt.setUserData(MAP_WHERE_EXPRESSION, expr);
            }
            return fpe.check(vars, null, expr);
        // //  throw new Error("Transform "+tgt.getTransform().toCode()+" not supported yet");
        case TRANSLATE:
            return new TypeDetails(CollectionStatus.SINGLETON, "CodeableConcept");
        case CC:
            ProfiledType res = new ProfiledType("CodeableConcept");
            if (tgt.getParameter().size() >= 2 && isParamId(vars, tgt.getParameter().get(1))) {
                TypeDetails td = vars.get(null, getParamId(vars, tgt.getParameter().get(1))).property.types;
                if (td != null && td.hasBinding())
                    // todo: do we need to check that there's no implicit translation her? I don't think we do...
                    res.addBinding(td.getBinding());
            }
            return new TypeDetails(CollectionStatus.SINGLETON, res);
        case C:
            return new TypeDetails(CollectionStatus.SINGLETON, "Coding");
        case QTY:
            return new TypeDetails(CollectionStatus.SINGLETON, "Quantity");
        case REFERENCE:
            VariableForProfiling vrs = vars.get(VariableMode.OUTPUT, getParamId(vars, tgt.getParameterFirstRep()));
            if (vrs == null)
                throw new FHIRException("Unable to resolve variable \"" + getParamId(vars, tgt.getParameterFirstRep()) + "\"");
            String profile = vrs.property.getProfileProperty().getStructure().getUrl();
            TypeDetails td = new TypeDetails(CollectionStatus.SINGLETON);
            td.addType("Reference", profile);
            return td;
        // //    throw new FHIRException("Transform engine cannot point at an element of type "+b.fhirType());
        default:
            throw new Error("Transform Unknown or not handled yet: " + tgt.getTransform().toCode());
    }
}
Also used : TypeDetails(org.hl7.fhir.dstu3.model.TypeDetails) ProfiledType(org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType) ExpressionNode(org.hl7.fhir.dstu3.model.ExpressionNode) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)35 FHIRFormatError (org.hl7.fhir.exceptions.FHIRFormatError)12 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)10 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)7 IOException (java.io.IOException)6 StringType (org.hl7.fhir.dstu3.model.StringType)6 StringType (org.hl7.fhir.r4.model.StringType)6 IdType (org.hl7.fhir.dstu3.model.IdType)4 StructureMapGroupRuleTargetComponent (org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent)4 ProfiledType (org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType)4 PathEngineException (org.hl7.fhir.exceptions.PathEngineException)4 StructureMapGroupRuleTargetComponent (org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetComponent)4 NodeType (org.hl7.fhir.utilities.xhtml.NodeType)4 StringType (org.hl7.fhir.dstu2016may.model.StringType)3 StructureMapGroupRuleTargetComponent (org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapGroupRuleTargetComponent)3 Base (org.hl7.fhir.dstu3.model.Base)3 BooleanType (org.hl7.fhir.dstu3.model.BooleanType)3 UriType (org.hl7.fhir.dstu3.model.UriType)3 Base (org.hl7.fhir.r4.model.Base)3 IdType (org.hl7.fhir.r4.model.IdType)3