Search in sources :

Example 36 with StructureMapGroupRuleTargetComponent

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

the class StructureMapUtilities method parseTarget.

private void parseTarget(StructureMapGroupRuleComponent rule, FHIRLexer lexer) throws FHIRException {
    StructureMapGroupRuleTargetComponent target = rule.addTarget();
    String start = lexer.take();
    if (lexer.hasToken(".")) {
        target.setContext(start);
        target.setContextType(StructureMapContextType.VARIABLE);
        start = null;
        lexer.token(".");
        target.setElement(lexer.take());
    }
    String name;
    boolean isConstant = false;
    if (lexer.hasToken("=")) {
        if (start != null)
            target.setContext(start);
        lexer.token("=");
        isConstant = lexer.isConstant(true);
        name = lexer.take();
    } else
        name = start;
    if ("(".equals(name)) {
        // inline fluentpath expression
        target.setTransform(StructureMapTransform.EVALUATE);
        ExpressionNode node = fpe.parse(lexer);
        target.setUserData(MAP_EXPRESSION, node);
        target.addParameter().setValue(new StringType(node.toString()));
        lexer.token(")");
    } else if (lexer.hasToken("(")) {
        target.setTransform(StructureMapTransform.fromCode(name));
        lexer.token("(");
        if (target.getTransform() == StructureMapTransform.EVALUATE) {
            parseParameter(target, lexer);
            lexer.token(",");
            ExpressionNode node = fpe.parse(lexer);
            target.setUserData(MAP_EXPRESSION, node);
            target.addParameter().setValue(new StringType(node.toString()));
        } else {
            while (!lexer.hasToken(")")) {
                parseParameter(target, lexer);
                if (!lexer.hasToken(")"))
                    lexer.token(",");
            }
        }
        lexer.token(")");
    } else if (name != null) {
        target.setTransform(StructureMapTransform.COPY);
        if (!isConstant) {
            String id = name;
            while (lexer.hasToken(".")) {
                id = id + lexer.take() + lexer.take();
            }
            target.addParameter().setValue(new IdType(id));
        } else
            target.addParameter().setValue(readConstant(name, lexer));
    }
    if (lexer.hasToken("as")) {
        lexer.take();
        target.setVariable(lexer.take());
    }
    while (Utilities.existsInList(lexer.getCurrent(), "first", "last", "share", "collate")) {
        if (lexer.getCurrent().equals("share")) {
            target.addListMode(StructureMapTargetListMode.SHARE);
            lexer.next();
            target.setListRuleId(lexer.take());
        } else if (lexer.getCurrent().equals("first"))
            target.addListMode(StructureMapTargetListMode.FIRST);
        else
            target.addListMode(StructureMapTargetListMode.LAST);
        lexer.next();
    }
}
Also used : StringType(org.hl7.fhir.dstu3.model.StringType) ExpressionNode(org.hl7.fhir.dstu3.model.ExpressionNode) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 37 with StructureMapGroupRuleTargetComponent

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

the class StructureMapUtilities method renderRule.

private static void renderRule(StringBuilder b, StructureMapGroupRuleComponent r, int indent) {
    for (int i = 0; i < indent; i++) b.append(' ');
    b.append(r.getName());
    b.append(" : for ");
    boolean canBeAbbreviated = checkisSimple(r);
    boolean first = true;
    for (StructureMapGroupRuleSourceComponent rs : r.getSource()) {
        if (first)
            first = false;
        else
            b.append(", ");
        renderSource(b, rs, canBeAbbreviated);
    }
    if (r.getTarget().size() > 1) {
        b.append(" make ");
        first = true;
        for (StructureMapGroupRuleTargetComponent rt : r.getTarget()) {
            if (first)
                first = false;
            else
                b.append(", ");
            if (RENDER_MULTIPLE_TARGETS_ONELINE)
                b.append(' ');
            else {
                b.append("\r\n");
                for (int i = 0; i < indent + 4; i++) b.append(' ');
            }
            renderTarget(b, rt, false);
        }
    } else if (r.hasTarget()) {
        b.append(" make ");
        renderTarget(b, r.getTarget().get(0), canBeAbbreviated);
    }
    if (!canBeAbbreviated) {
        if (r.hasRule()) {
            b.append(" then {\r\n");
            renderDoco(b, r.getDocumentation());
            for (StructureMapGroupRuleComponent ir : r.getRule()) {
                renderRule(b, ir, indent + 2);
            }
            for (int i = 0; i < indent; i++) b.append(' ');
            b.append("}\r\n");
        } else {
            if (r.hasDependent()) {
                b.append(" then ");
                first = true;
                for (StructureMapGroupRuleDependentComponent rd : r.getDependent()) {
                    if (first)
                        first = false;
                    else
                        b.append(", ");
                    b.append(rd.getName());
                    b.append("(");
                    boolean ifirst = true;
                    for (StringType rdp : rd.getVariable()) {
                        if (ifirst)
                            ifirst = false;
                        else
                            b.append(", ");
                        b.append(rdp.asStringValue());
                    }
                    b.append(")");
                }
            }
        }
    }
    renderDoco(b, r.getDocumentation());
    b.append("\r\n");
}
Also used : StringType(org.hl7.fhir.dstu3.model.StringType) StructureMapGroupRuleDependentComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleDependentComponent) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) StructureMapGroupRuleSourceComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleSourceComponent) StructureMapGroupRuleTargetComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleTargetComponent) StructureMapGroupRuleComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapGroupRuleComponent)

Example 38 with StructureMapGroupRuleTargetComponent

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

the class StructureMapUtilities method updateProfile.

private PropertyWithType updateProfile(VariableForProfiling var, String element, TypeDetails type, StructureMap map, List<StructureDefinition> profiles, String sliceName, Type fixed, StructureMapGroupRuleTargetComponent tgt) throws FHIRException {
    if (var == null) {
        assert (Utilities.noString(element));
        // 1. start the new structure definition
        StructureDefinition sdn = worker.fetchResource(StructureDefinition.class, type.getType());
        if (sdn == null)
            throw new FHIRException("Unable to find definition for " + type.getType());
        ElementDefinition edn = sdn.getSnapshot().getElementFirstRep();
        PropertyWithType pn = createProfile(map, profiles, new PropertyWithType(sdn.getId(), new Property(worker, edn, sdn), null, type), sliceName, tgt);
        // }
        return pn;
    } else {
        assert (!Utilities.noString(element));
        Property pvb = var.getProperty().getBaseProperty();
        Property pvd = var.getProperty().getProfileProperty();
        Property pc = pvb.getChild(element, var.property.types);
        if (pc == null)
            throw new DefinitionException("Unable to find a definition for " + pvb.getDefinition().getPath() + "." + element);
        // the profile structure definition (derived)
        StructureDefinition sd = var.getProperty().profileProperty.getStructure();
        ElementDefinition ednew = sd.getDifferential().addElement();
        ednew.setPath(var.getProperty().profileProperty.getDefinition().getPath() + "." + pc.getName());
        ednew.setUserData("slice-name", sliceName);
        ednew.setFixed(fixed);
        for (ProfiledType pt : type.getProfiledTypes()) {
            if (pt.hasBindings())
                ednew.setBinding(pt.getBindings().get(0));
            if (pt.getUri().startsWith("http://hl7.org/fhir/StructureDefinition/")) {
                String t = pt.getUri().substring(40);
                t = checkType(t, pc, pt.getProfiles());
                if (t != null) {
                    if (pt.hasProfiles()) {
                        for (String p : pt.getProfiles()) if (t.equals("Reference"))
                            ednew.addType().setCode(t).setTargetProfile(p);
                        else
                            ednew.addType().setCode(t).setProfile(p);
                    } else
                        ednew.addType().setCode(t);
                }
            }
        }
        return new PropertyWithType(var.property.path + "." + element, pc, new Property(worker, ednew, sd), type);
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) ProfiledType(org.hl7.fhir.dstu3.model.TypeDetails.ProfiledType) ElementDefinition(org.hl7.fhir.dstu3.model.ElementDefinition) DefinitionException(org.hl7.fhir.exceptions.DefinitionException) FHIRException(org.hl7.fhir.exceptions.FHIRException) Property(org.hl7.fhir.dstu3.elementmodel.Property)

Example 39 with StructureMapGroupRuleTargetComponent

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

the class StructureMapUtilities method describeTransformCCorC.

@SuppressWarnings("rawtypes")
private String describeTransformCCorC(StructureMapGroupRuleTargetComponent tgt) throws FHIRException {
    if (tgt.getParameter().size() < 2)
        return null;
    Type p1 = tgt.getParameter().get(0).getValue();
    Type p2 = tgt.getParameter().get(1).getValue();
    if (p1 instanceof IdType || p2 instanceof IdType)
        return null;
    if (!(p1 instanceof PrimitiveType) || !(p2 instanceof PrimitiveType))
        return null;
    String uri = ((PrimitiveType) p1).asStringValue();
    String code = ((PrimitiveType) p2).asStringValue();
    if (Utilities.noString(uri))
        throw new FHIRException("Describe Transform, but the uri is blank");
    if (Utilities.noString(code))
        throw new FHIRException("Describe Transform, but the code is blank");
    Coding c = buildCoding(uri, code);
    return NarrativeGenerator.describeSystem(c.getSystem()) + "#" + c.getCode() + (c.hasDisplay() ? "(" + c.getDisplay() + ")" : "");
}
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) Coding(org.hl7.fhir.dstu3.model.Coding) PrimitiveType(org.hl7.fhir.dstu3.model.PrimitiveType) FHIRException(org.hl7.fhir.exceptions.FHIRException) IdType(org.hl7.fhir.dstu3.model.IdType)

Example 40 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.r4.model.CodeableConcept)

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