Search in sources :

Example 1 with UsingDef

use of org.hl7.elm.r1.UsingDef in project quality-measure-and-cohort-service by Alvearie.

the class PathCaptureContext method reportUsingDef.

public void reportUsingDef(UsingDef elm) {
    if (!elm.getUri().equals(CqlConstants.SYSTEM_MODEL_URI)) {
        VersionedIdentifier vid = new VersionedIdentifier().withId(elm.getLocalIdentifier()).withVersion(elm.getVersion());
        modelIdByUri.put(elm.getUri(), vid);
    }
}
Also used : VersionedIdentifier(org.hl7.elm.r1.VersionedIdentifier)

Example 2 with UsingDef

use of org.hl7.elm.r1.UsingDef in project CRD by HL7-DaVinci.

the class CqlRule method getFhirVersionFromCqlFile.

private static String getFhirVersionFromCqlFile(byte[] cql) {
    String fhirVersion = "";
    UsingDef usingDef = new UsingDef();
    Pattern pattern = Pattern.compile("using (.*?) version '(.*?)'");
    try {
        Matcher matcher = pattern.matcher(new String(cql));
        while (fhirVersion.isEmpty()) {
            matcher.find();
            if (matcher.groupCount() != 2) {
                throw new RuntimeException("Encountered bad CQL file, could not detect library identifier.");
            }
            if (matcher.group(1).equalsIgnoreCase("FHIR")) {
                fhirVersion = matcher.group(2);
            }
        }
    } catch (Exception e) {
        logger.warn("exception in CqlRule::getFhirVersionFromCqlFile(): " + e.getMessage());
    }
    return fhirVersion;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) UsingDef(org.hl7.elm.r1.UsingDef) IOException(java.io.IOException)

Example 3 with UsingDef

use of org.hl7.elm.r1.UsingDef in project clinical_quality_language by cqframework.

the class Cql2ElmVisitor method popChunk.

private void popChunk(ParseTree tree, Object o) {
    Chunk chunk = chunks.pop();
    if (o instanceof Element) {
        Element element = (Element) o;
        if (element.getLocalId() == null) {
            element.setLocalId(Integer.toString(getNextLocalId()));
        }
        chunk.setElement(element);
        if (!(tree instanceof cqlParser.LibraryContext)) {
            if (element instanceof UsingDef || element instanceof IncludeDef || element instanceof CodeSystemDef || element instanceof ValueSetDef || element instanceof CodeDef || element instanceof ConceptDef || element instanceof ParameterDef || element instanceof ContextDef || element instanceof ExpressionDef) {
                Annotation a = getAnnotation(element);
                if (a == null || a.getS() == null) {
                    // Add header information (comments prior to the definition)
                    BaseInfo definitionInfo = libraryInfo.resolveDefinition(tree);
                    if (definitionInfo != null && definitionInfo.getHeaderInterval() != null) {
                        Chunk headerChunk = new Chunk().withInterval(definitionInfo.getHeaderInterval()).withIsHeaderChunk(true);
                        Chunk newChunk = new Chunk().withInterval(new org.antlr.v4.runtime.misc.Interval(headerChunk.getInterval().a, chunk.getInterval().b));
                        newChunk.addChunk(headerChunk);
                        newChunk.setElement(chunk.getElement());
                        for (Chunk c : chunk.getChunks()) {
                            newChunk.addChunk(c);
                        }
                        chunk = newChunk;
                    }
                    if (a == null) {
                        element.getAnnotation().add(buildAnnotation(chunk));
                    } else {
                        addNarrativeToAnnotation(a, chunk);
                    }
                }
            }
        } else {
            if (libraryInfo.getDefinition() != null && libraryInfo.getHeaderInterval() != null) {
                Chunk headerChunk = new Chunk().withInterval(libraryInfo.getHeaderInterval()).withIsHeaderChunk(true);
                Chunk definitionChunk = new Chunk().withInterval(libraryInfo.getDefinition().getSourceInterval());
                Chunk newChunk = new Chunk().withInterval(new org.antlr.v4.runtime.misc.Interval(headerChunk.getInterval().a, definitionChunk.getInterval().b));
                newChunk.addChunk(headerChunk);
                newChunk.addChunk(definitionChunk);
                newChunk.setElement(chunk.getElement());
                chunk = newChunk;
                Annotation a = getAnnotation(libraryBuilder.getLibrary());
                if (a == null) {
                    libraryBuilder.getLibrary().getAnnotation().add(buildAnnotation(chunk));
                } else {
                    addNarrativeToAnnotation(a, chunk);
                }
            }
        }
    }
    if (!chunks.isEmpty()) {
        chunks.peek().addChunk(chunk);
    }
}
Also used : Element(org.hl7.elm.r1.Element) Annotation(org.hl7.cql_annotations.r1.Annotation)

Example 4 with UsingDef

use of org.hl7.elm.r1.UsingDef in project clinical_quality_language by cqframework.

the class Cql2ElmVisitor method processTags.

private void processTags(ParseTree tree, Object o) {
    if (libraryBuilder.isCompatibleWith("1.5")) {
        if (o instanceof Element) {
            Element element = (Element) o;
            if (!(tree instanceof cqlParser.LibraryContext)) {
                if (element instanceof UsingDef || element instanceof IncludeDef || element instanceof CodeSystemDef || element instanceof ValueSetDef || element instanceof CodeDef || element instanceof ConceptDef || element instanceof ParameterDef || element instanceof ContextDef || element instanceof ExpressionDef) {
                    List<Tag> tags = getTags(tree);
                    if (tags != null && tags.size() > 0) {
                        Annotation a = getAnnotation(element);
                        if (a == null) {
                            a = buildAnnotation();
                            element.getAnnotation().add(a);
                        }
                        // tags, and there is currently nothing that would add tags other than being processed from comments
                        if (a.getT().size() == 0) {
                            a.getT().addAll(tags);
                        }
                    }
                }
            } else {
                if (libraryInfo.getDefinition() != null && libraryInfo.getHeaderInterval() != null) {
                    List<Tag> tags = getTags(libraryInfo.getHeader());
                    if (tags != null && tags.size() > 0) {
                        Annotation a = getAnnotation(libraryBuilder.getLibrary());
                        if (a == null) {
                            a = buildAnnotation();
                            libraryBuilder.getLibrary().getAnnotation().add(a);
                        }
                        a.getT().addAll(tags);
                    }
                }
            }
        }
    }
}
Also used : Element(org.hl7.elm.r1.Element) Annotation(org.hl7.cql_annotations.r1.Annotation) Tag(org.hl7.cql_annotations.r1.Tag)

Example 5 with UsingDef

use of org.hl7.elm.r1.UsingDef in project clinical_quality_language by cqframework.

the class LibraryManager method generateCompiledLibrary.

private CompiledLibrary generateCompiledLibrary(Library library) {
    if (library == null) {
        return null;
    }
    boolean compilationSuccess = true;
    CompiledLibrary compiledLibrary = new CompiledLibrary();
    try {
        if (library != null) {
            compiledLibrary.setLibrary(library);
        }
        if (library.getIdentifier() != null) {
            compiledLibrary.setIdentifier(library.getIdentifier());
        }
        if (library.getUsings() != null && library.getUsings().getDef() != null) {
            for (UsingDef usingDef : library.getUsings().getDef()) {
                compiledLibrary.add(usingDef);
            }
        }
        if (library.getIncludes() != null && library.getIncludes().getDef() != null) {
            for (IncludeDef includeDef : library.getIncludes().getDef()) {
                compiledLibrary.add(includeDef);
            }
        }
        if (library.getCodeSystems() != null && library.getCodeSystems().getDef() != null) {
            for (CodeSystemDef codeSystemDef : library.getCodeSystems().getDef()) {
                compiledLibrary.add(codeSystemDef);
            }
        }
        for (ValueSetDef valueSetDef : library.getValueSets().getDef()) {
            compiledLibrary.add(valueSetDef);
        }
        if (library.getCodes() != null && library.getCodes().getDef() != null) {
            for (CodeDef codeDef : library.getCodes().getDef()) {
                compiledLibrary.add(codeDef);
            }
        }
        if (library.getConcepts() != null && library.getConcepts().getDef() != null) {
            for (ConceptDef conceptDef : library.getConcepts().getDef()) {
                compiledLibrary.add(conceptDef);
            }
        }
        if (library.getParameters() != null && library.getParameters().getDef() != null) {
            for (ParameterDef parameterDef : library.getParameters().getDef()) {
                compiledLibrary.add(parameterDef);
            }
        }
        if (library.getStatements() != null && library.getStatements().getDef() != null) {
            for (ExpressionDef expressionDef : library.getStatements().getDef()) {
                // to do implement an ElmTypeInferencingVisitor; make sure that the resultType is set for each node
                if (expressionDef.getResultType() != null) {
                    compiledLibrary.add(expressionDef);
                } else {
                    compilationSuccess = false;
                    break;
                }
            }
        }
    } catch (Exception e) {
        compilationSuccess = false;
    }
    if (compilationSuccess) {
        return compiledLibrary;
    }
    return null;
}
Also used : CompiledLibrary(org.cqframework.cql.cql2elm.model.CompiledLibrary) CodeDef(org.hl7.elm.r1.CodeDef) ConceptDef(org.hl7.elm.r1.ConceptDef) ParameterDef(org.hl7.elm.r1.ParameterDef) ExpressionDef(org.hl7.elm.r1.ExpressionDef) CodeSystemDef(org.hl7.elm.r1.CodeSystemDef) IncludeDef(org.hl7.elm.r1.IncludeDef) ValueSetDef(org.hl7.elm.r1.ValueSetDef) UsingDef(org.hl7.elm.r1.UsingDef) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Aggregations

UsingDef (org.hl7.elm.r1.UsingDef)3 IOException (java.io.IOException)2 Annotation (org.hl7.cql_annotations.r1.Annotation)2 Element (org.hl7.elm.r1.Element)2 ExpressionDef (org.hl7.elm.r1.ExpressionDef)2 CqlLibrary (com.ibm.cohort.cql.library.CqlLibrary)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 JAXBException (javax.xml.bind.JAXBException)1 CompiledLibrary (org.cqframework.cql.cql2elm.model.CompiledLibrary)1 Tag (org.hl7.cql_annotations.r1.Tag)1 CodeDef (org.hl7.elm.r1.CodeDef)1 CodeSystemDef (org.hl7.elm.r1.CodeSystemDef)1 ConceptDef (org.hl7.elm.r1.ConceptDef)1 IncludeDef (org.hl7.elm.r1.IncludeDef)1 Library (org.hl7.elm.r1.Library)1 ParameterDef (org.hl7.elm.r1.ParameterDef)1 ValueSetDef (org.hl7.elm.r1.ValueSetDef)1