Search in sources :

Example 11 with FHIRLexer

use of org.hl7.fhir.r4b.utils.FHIRLexer in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method parseUses.

private void parseUses(StructureMap result, FHIRLexer lexer) throws FHIRException {
    lexer.token("uses");
    StructureMapStructureComponent st = result.addStructure();
    st.setUrl(lexer.readConstant("url"));
    lexer.token("as");
    st.setMode(StructureMapModelMode.fromCode(lexer.take()));
    lexer.skipToken(";");
    if (lexer.hasComment()) {
        st.setDocumentation(lexer.take().substring(2).trim());
    }
    lexer.skipComments();
}
Also used : StructureMapStructureComponent(org.hl7.fhir.dstu2016may.model.StructureMap.StructureMapStructureComponent)

Example 12 with FHIRLexer

use of org.hl7.fhir.r4b.utils.FHIRLexer in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method parseUses.

private void parseUses(StructureMap result, FHIRLexer lexer) throws FHIRException {
    lexer.token("uses");
    StructureMapStructureComponent st = result.addStructure();
    st.setUrl(lexer.readConstant("url"));
    if (lexer.hasToken("alias")) {
        lexer.token("alias");
        st.setAlias(lexer.take());
    }
    lexer.token("as");
    st.setMode(StructureMapModelMode.fromCode(lexer.take()));
    lexer.skipToken(";");
    if (lexer.hasComment()) {
        st.setDocumentation(lexer.take().substring(2).trim());
    }
    lexer.skipComments();
}
Also used : StructureMapStructureComponent(org.hl7.fhir.dstu3.model.StructureMap.StructureMapStructureComponent)

Example 13 with FHIRLexer

use of org.hl7.fhir.r4b.utils.FHIRLexer in project org.hl7.fhir.core by hapifhir.

the class StructureMapUtilities method parseConceptMap.

private void parseConceptMap(StructureMap result, FHIRLexer lexer) throws FHIRLexerException {
    lexer.token("conceptmap");
    ConceptMap map = new ConceptMap();
    String id = lexer.readConstant("map id");
    if (!id.startsWith("#"))
        lexer.error("Concept Map identifier must start with #");
    map.setId(id);
    // todo: how to add this to the text format
    map.setStatus(PublicationStatus.DRAFT);
    result.getContained().add(map);
    lexer.token("{");
    lexer.skipComments();
    // lexer.token("source");
    // map.setSource(new UriType(lexer.readConstant("source")));
    // lexer.token("target");
    // map.setSource(new UriType(lexer.readConstant("target")));
    Map<String, String> prefixes = new HashMap<String, String>();
    while (lexer.hasToken("prefix")) {
        lexer.token("prefix");
        String n = lexer.take();
        lexer.token("=");
        String v = lexer.readConstant("prefix url");
        prefixes.put(n, v);
    }
    while (lexer.hasToken("unmapped")) {
        lexer.token("unmapped");
        lexer.token("for");
        String n = readPrefix(prefixes, lexer);
        ConceptMapGroupComponent g = getGroup(map, n, null);
        lexer.token("=");
        String v = lexer.take();
        if (v.equals("provided")) {
            g.getUnmapped().setMode(ConceptMapGroupUnmappedMode.PROVIDED);
        } else
            lexer.error("Only unmapped mode PROVIDED is supported at this time");
    }
    while (!lexer.hasToken("}")) {
        String srcs = readPrefix(prefixes, lexer);
        lexer.token(":");
        String sc = lexer.getCurrent().startsWith("\"") ? lexer.readConstant("code") : lexer.take();
        ConceptMapEquivalence eq = readEquivalence(lexer);
        String tgts = (eq != ConceptMapEquivalence.UNMATCHED) ? readPrefix(prefixes, lexer) : "";
        ConceptMapGroupComponent g = getGroup(map, srcs, tgts);
        SourceElementComponent e = g.addElement();
        e.setCode(sc);
        if (e.getCode().startsWith("\""))
            e.setCode(lexer.processConstant(e.getCode()));
        TargetElementComponent tgt = e.addTarget();
        if (eq != ConceptMapEquivalence.EQUIVALENT)
            tgt.setEquivalence(eq);
        if (tgt.getEquivalence() != ConceptMapEquivalence.UNMATCHED) {
            lexer.token(":");
            tgt.setCode(lexer.take());
            if (tgt.getCode().startsWith("\""))
                tgt.setCode(lexer.processConstant(tgt.getCode()));
        }
        if (lexer.hasComment())
            tgt.setComment(lexer.take().substring(2).trim());
    }
    lexer.token("}");
}
Also used : HashMap(java.util.HashMap) TargetElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent) ConceptMapEquivalence(org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence) ConceptMap(org.hl7.fhir.dstu3.model.ConceptMap) ConceptMapGroupComponent(org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent) SourceElementComponent(org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)

Example 14 with FHIRLexer

use of org.hl7.fhir.r4b.utils.FHIRLexer in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method parse.

public ExpressionNode parse(String path, String name) throws FHIRLexerException {
    FHIRLexer lexer = new FHIRLexer(path, name);
    if (lexer.done())
        throw lexer.error("Path cannot be empty");
    ExpressionNode result = parseExpression(lexer, true);
    if (!lexer.done())
        throw lexer.error("Premature ExpressionNode termination at unexpected token \"" + lexer.getCurrent() + "\"");
    result.check();
    return result;
}
Also used : ExpressionNode(org.hl7.fhir.r4.model.ExpressionNode)

Example 15 with FHIRLexer

use of org.hl7.fhir.r4b.utils.FHIRLexer in project org.hl7.fhir.core by hapifhir.

the class FHIRPathEngine method parse.

/**
 * Parse a path that is part of some other syntax
 *
 * @return
 * @throws PathEngineException
 * @throws Exception
 */
public ExpressionNode parse(FHIRLexer lexer) throws FHIRLexerException {
    ExpressionNode result = parseExpression(lexer, true);
    result.check();
    return result;
}
Also used : ExpressionNode(org.hl7.fhir.r4.model.ExpressionNode)

Aggregations

ExpressionNode (org.hl7.fhir.r4.model.ExpressionNode)8 ExpressionNode (org.hl7.fhir.dstu2016may.model.ExpressionNode)7 ExpressionNode (org.hl7.fhir.dstu3.model.ExpressionNode)7 ExpressionNode (org.hl7.fhir.r4b.model.ExpressionNode)6 ExpressionNode (org.hl7.fhir.r5.model.ExpressionNode)6 ExpressionNode (org.hl7.fhir.dstu2.model.ExpressionNode)5 BigDecimal (java.math.BigDecimal)3 HashMap (java.util.HashMap)3 SourceLocation (org.hl7.fhir.utilities.SourceLocation)3 StringType (org.hl7.fhir.dstu3.model.StringType)2 StringType (org.hl7.fhir.r4.model.StringType)2 Function (org.hl7.fhir.dstu2.model.ExpressionNode.Function)1 SourceLocation (org.hl7.fhir.dstu2.model.ExpressionNode.SourceLocation)1 FunctionDetails (org.hl7.fhir.dstu2.utils.FHIRPathEngine.IEvaluationContext.FunctionDetails)1 ConceptMap (org.hl7.fhir.dstu2016may.model.ConceptMap)1 SourceElementComponent (org.hl7.fhir.dstu2016may.model.ConceptMap.SourceElementComponent)1 TargetElementComponent (org.hl7.fhir.dstu2016may.model.ConceptMap.TargetElementComponent)1 Function (org.hl7.fhir.dstu2016may.model.ExpressionNode.Function)1 SourceLocation (org.hl7.fhir.dstu2016may.model.ExpressionNode.SourceLocation)1 IdType (org.hl7.fhir.dstu2016may.model.IdType)1