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);
}
}
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;
}
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);
}
}
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);
}
}
}
}
}
}
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;
}
Aggregations