org.cqframework.cql.cql2elm.ModelManager Java Examples
The following examples show how to use
org.cqframework.cql.cql2elm.ModelManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LibraryOperationsProvider.java From cqf-ruler with Apache License 2.0 | 8 votes |
@Operation(name = "$refresh-generated-content", type = Library.class) public MethodOutcome refreshGeneratedContent(HttpServletRequest theRequest, RequestDetails theRequestDetails, @IdParam IdType theId) { Library theResource = this.libraryResourceProvider.getDao().read(theId); //this.formatCql(theResource); ModelManager modelManager = this.getModelManager(); LibraryManager libraryManager = this.getLibraryManager(modelManager); CqlTranslator translator = this.dataRequirementsProvider.getTranslator(theResource, libraryManager, modelManager); if (translator.getErrors().size() > 0) { throw new RuntimeException("Errors during library compilation."); } this.dataRequirementsProvider.ensureElm(theResource, translator); this.dataRequirementsProvider.ensureRelatedArtifacts(theResource, translator, this); this.dataRequirementsProvider.ensureDataRequirements(theResource, translator); Narrative n = this.narrativeProvider.getNarrative(this.libraryResourceProvider.getContext(), theResource); theResource.setText(n); return this.libraryResourceProvider.update(theRequest, theResource, theId, theRequestDetails.getConditionalUrl(RestOperationTypeEnum.UPDATE), theRequestDetails); }
Example #2
Source File: TranslatorHelper.java From cqf-ruler with Apache License 2.0 | 6 votes |
public static CqlTranslator getTranslator(InputStream cqlStream, LibraryManager libraryManager, ModelManager modelManager) { ArrayList<CqlTranslator.Options> options = new ArrayList<>(); options.add(CqlTranslator.Options.EnableAnnotations); options.add(CqlTranslator.Options.EnableLocators); options.add(CqlTranslator.Options.DisableListDemotion); options.add(CqlTranslator.Options.DisableListPromotion); options.add(CqlTranslator.Options.DisableMethodInvocation); CqlTranslator translator; try { translator = CqlTranslator.fromStream(cqlStream, modelManager, libraryManager, options.toArray(new CqlTranslator.Options[options.size()])); } catch (IOException e) { throw new IllegalArgumentException(String.format("Errors occurred translating library: %s", e.getMessage())); } return translator; }
Example #3
Source File: DataRequirementsProvider.java From cqf-ruler with Apache License 2.0 | 6 votes |
public CqlTranslator getTranslator(org.hl7.fhir.r4.model.Library library, LibraryManager libraryManager, ModelManager modelManager) { Attachment cql = null; for (Attachment a : library.getContent()) { if (a.getContentType().equals("text/cql")) { cql = a; break; } } if (cql == null) { return null; } return TranslatorHelper.getTranslator( new ByteArrayInputStream(Base64.getDecoder().decode(cql.getDataElement().getValueAsString())), libraryManager, modelManager); }
Example #4
Source File: LibraryOperationsProvider.java From cqf-ruler with Apache License 2.0 | 6 votes |
@Operation(name = "$get-elm", idempotent = true, type = Library.class) public Parameters getElm(@IdParam IdType theId, @OptionalParam(name="format") String format) { Library theResource = this.libraryResourceProvider.getDao().read(theId); // this.formatCql(theResource); ModelManager modelManager = this.getModelManager(); LibraryManager libraryManager = this.getLibraryManager(modelManager); String elm = ""; CqlTranslator translator = this.dataRequirementsProvider.getTranslator(theResource, libraryManager, modelManager); if (translator != null) { if (format.equals("json")) { elm = translator.toJson(); } else { elm = translator.toXml(); } } Parameters p = new Parameters(); p.addParameter().setValue(new StringType(elm)); return p; }
Example #5
Source File: DataRequirementsProvider.java From cqf-ruler with Apache License 2.0 | 6 votes |
public CqlTranslator getTranslator(org.hl7.fhir.dstu3.model.Library library, LibraryManager libraryManager, ModelManager modelManager) { Attachment cql = null; for (Attachment a : library.getContent()) { if (a.getContentType().equals("text/cql")) { cql = a; break; } } if (cql == null) { return null; } CqlTranslator translator = TranslatorHelper.getTranslator( new ByteArrayInputStream(Base64.getDecoder().decode(cql.getDataElement().getValueAsString())), libraryManager, modelManager); return translator; }
Example #6
Source File: LibraryOperationsProvider.java From cqf-ruler with Apache License 2.0 | 6 votes |
@Operation(name = "$get-elm", idempotent = true, type = Library.class) public Parameters getElm(@IdParam IdType theId, @OptionalParam(name="format") String format) { Library theResource = this.libraryResourceProvider.getDao().read(theId); // this.formatCql(theResource); ModelManager modelManager = this.getModelManager(); LibraryManager libraryManager = this.getLibraryManager(modelManager); String elm = ""; CqlTranslator translator = this.dataRequirementsProvider.getTranslator(theResource, libraryManager, modelManager); if (translator != null) { if (format.equals("json")) { elm = translator.toJson(); } else { elm = translator.toXml(); } } Parameters p = new Parameters(); p.addParameter().setValue(new StringType(elm)); return p; }
Example #7
Source File: QueryTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(QueryTest.class.getResourceAsStream("../OperatorTests/Query.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); for (ExpressionDef def: library.getStatements().getDef()) { defs.put(def.getName(), def); } }
Example #8
Source File: CqlIntervalOperatorsTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(CqlIntervalOperatorsTest.class.getResourceAsStream("../OperatorTests/CqlIntervalOperators.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); if (library.getStatements() != null) { for (ExpressionDef def : library.getStatements().getDef()) { defs.put(def.getName(), def); } } }
Example #9
Source File: TimeOperatorsTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(TimeOperatorsTest.class.getResourceAsStream("../OperatorTests/TimeOperators.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); for (ExpressionDef def: library.getStatements().getDef()) { defs.put(def.getName(), def); } }
Example #10
Source File: ArithmeticOperatorsTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(ArithmeticOperatorsTest.class.getResourceAsStream("../OperatorTests/ArithmeticOperators.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); for (ExpressionDef def: library.getStatements().getDef()) { defs.put(def.getName(), def); } }
Example #11
Source File: SortingTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(QueryTest.class.getResourceAsStream("../OperatorTests/Sorting.cql"), modelManager, new LibraryManager(modelManager)); // The alias test creates an error assertThat(translator.getErrors().size(), is(1)); Library library = translator.toELM(); defs = new HashMap<>(); for (ExpressionDef def: library.getStatements().getDef()) { defs.put(def.getName(), def); } }
Example #12
Source File: ListOperatorsTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(ListOperatorsTest.class.getResourceAsStream("../OperatorTests/ListOperators.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); for (ExpressionDef def: library.getStatements().getDef()) { defs.put(def.getName(), def); } }
Example #13
Source File: TypeOperatorsTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(TypeOperatorsTest.class.getResourceAsStream("../OperatorTests/TypeOperators.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); for (ExpressionDef def: library.getStatements().getDef()) { defs.put(def.getName(), def); } }
Example #14
Source File: CqlListOperatorsTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(CqlListOperatorsTest.class.getResourceAsStream("../OperatorTests/CqlListOperators.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); if (library.getStatements() != null) { for (ExpressionDef def : library.getStatements().getDef()) { defs.put(def.getName(), def); } } }
Example #15
Source File: AggregateOperatorsTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(AggregateOperatorsTest.class.getResourceAsStream("../OperatorTests/AggregateOperators.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); if (library.getStatements() != null) { for (ExpressionDef def : library.getStatements().getDef()) { defs.put(def.getName(), def); } } }
Example #16
Source File: AgeOperatorsTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(AgeOperatorsTest.class.getResourceAsStream("../OperatorTests/AgeOperators.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); if (library.getStatements() != null) { for (ExpressionDef def : library.getStatements().getDef()) { defs.put(def.getName(), def); } } }
Example #17
Source File: StringOperatorsTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(StringOperatorsTest.class.getResourceAsStream("../OperatorTests/StringOperators.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); for (ExpressionDef def: library.getStatements().getDef()) { defs.put(def.getName(), def); } }
Example #18
Source File: NullologicalOperatorsTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(NullologicalOperatorsTest.class.getResourceAsStream("../OperatorTests/NullologicalOperators.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); for (ExpressionDef def: library.getStatements().getDef()) { defs.put(def.getName(), def); } }
Example #19
Source File: CqlComparisonOperatorsTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(CqlComparisonOperatorsTest.class.getResourceAsStream("../OperatorTests/CqlComparisonOperators.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); if (library.getStatements() != null) { for (ExpressionDef def : library.getStatements().getDef()) { defs.put(def.getName(), def); } } }
Example #20
Source File: DateTimeOperatorsTest.java From clinical_quality_language with Apache License 2.0 | 5 votes |
@BeforeTest public void setup() throws IOException { ModelManager modelManager = new ModelManager(); CqlTranslator translator = CqlTranslator.fromStream(DateTimeOperatorsTest.class.getResourceAsStream("../OperatorTests/DateTimeOperators.cql"), modelManager, new LibraryManager(modelManager)); assertThat(translator.getErrors().size(), is(0)); Library library = translator.toELM(); defs = new HashMap<>(); for (ExpressionDef def: library.getStatements().getDef()) { defs.put(def.getName(), def); } }
Example #21
Source File: TestDstu3ModelResolver.java From cql_engine with Apache License 2.0 | 5 votes |
@Test // This tests all the types that are present in the modelinfo public void resolveModelInfoTests() { ModelResolver resolver = new Dstu3FhirModelResolver(); ModelManager mm = new ModelManager(); Model m = mm.resolveModel(new VersionedIdentifier().withId("FHIR").withVersion("3.0.0")); List<TypeInfo> typeInfos = m.getModelInfo().getTypeInfo(); for (TypeInfo ti : typeInfos) { ClassInfo ci = (ClassInfo)ti; if (ci != null) { switch (ci.getBaseType()) { // Astract classes case "FHIR.BackboneElement": case "FHIR.Element": continue; } switch (ci.getName()) { // TODO: HAPI Doesn't have a ResourceContainer type for Dstu3 case "ResourceContainer": continue; } resolver.resolveType(ci.getName()); } } }
Example #22
Source File: TestR4ModelResolver.java From cql_engine with Apache License 2.0 | 5 votes |
@Test public void resolveModelInfoTests() { ModelResolver resolver = new R4FhirModelResolver(); ModelManager mm = new ModelManager(); Model m = mm.resolveModel(new VersionedIdentifier().withId("FHIR").withVersion("4.0.0")); List<TypeInfo> typeInfos = m.getModelInfo().getTypeInfo(); for (TypeInfo ti : typeInfos) { ClassInfo ci = (ClassInfo)ti; if (ci != null) { switch (ci.getBaseType()) { // Astract classes case "FHIR.BackboneElement": case "FHIR.Element": continue; } switch (ci.getName()) { // TODO: HAPI Doesn't have a ResourceContainer type case "ResourceContainer": continue; } // TODO: The cause of failure for this is unknown. // Need to figure out if it's a gap in happy, // or if a manual mapping is required, or what. switch(ci.getName()) { case "ItemInstance" : continue; } resolver.resolveType(ci.getName()); } } }
Example #23
Source File: LibraryOperationsProvider.java From cqf-ruler with Apache License 2.0 | 5 votes |
@Operation(name = "$refresh-generated-content", type = Library.class) public MethodOutcome refreshGeneratedContent(HttpServletRequest theRequest, RequestDetails theRequestDetails, @IdParam IdType theId) { Library theResource = this.libraryResourceProvider.getDao().read(theId); //this.formatCql(theResource); ModelManager modelManager = this.getModelManager(); LibraryManager libraryManager = this.getLibraryManager(modelManager); CqlTranslator translator = this.dataRequirementsProvider.getTranslator(theResource, libraryManager, modelManager); if (translator.getErrors().size() > 0) { throw new RuntimeException("Errors during library compilation."); } this.dataRequirementsProvider.ensureElm(theResource, translator); this.dataRequirementsProvider.ensureRelatedArtifacts(theResource, translator, this); this.dataRequirementsProvider.ensureDataRequirements(theResource, translator); try { Narrative n = this.narrativeProvider.getNarrative(this.libraryResourceProvider.getContext(), theResource); theResource.setText(n); } catch (Exception e) { //Ignore the exception so the resource still gets updated } return this.libraryResourceProvider.update(theRequest, theResource, theId, theRequestDetails.getConditionalUrl(RestOperationTypeEnum.UPDATE), theRequestDetails); }
Example #24
Source File: LibraryOperationsProvider.java From cqf-ruler with Apache License 2.0 | 5 votes |
private LibraryManager getLibraryManager(ModelManager modelManager) { LibraryManager libraryManager = new LibraryManager(modelManager); libraryManager.getLibrarySourceLoader().clearProviders(); libraryManager.getLibrarySourceLoader().registerProvider(getLibrarySourceProvider()); return libraryManager; }
Example #25
Source File: LibraryHelper.java From cqf-ruler with Apache License 2.0 | 5 votes |
public static LibraryLoader createLibraryLoader(LibraryResolutionProvider<org.hl7.fhir.r4.model.Library> provider) { ModelManager modelManager = new ModelManager(); LibraryManager libraryManager = new LibraryManager(modelManager); libraryManager.getLibrarySourceLoader().clearProviders(); libraryManager.getLibrarySourceLoader().registerProvider( new LibrarySourceProvider<org.hl7.fhir.r4.model.Library, org.hl7.fhir.r4.model.Attachment>( provider, x -> x.getContent(), x -> x.getContentType(), x -> x.getData())); return new LibraryLoader(libraryManager, modelManager); }
Example #26
Source File: LibraryOperationsProvider.java From cqf-ruler with Apache License 2.0 | 5 votes |
private LibraryManager getLibraryManager(ModelManager modelManager) { LibraryManager libraryManager = new LibraryManager(modelManager); libraryManager.getLibrarySourceLoader().clearProviders(); libraryManager.getLibrarySourceLoader().registerProvider(getLibrarySourceProvider()); return libraryManager; }
Example #27
Source File: CqlTestSuite.java From cql_engine with Apache License 2.0 | 5 votes |
private Library translate(String file) throws UcumException, JAXBException, IOException { ModelManager modelManager = new ModelManager(); LibraryManager libraryManager = new LibraryManager(modelManager); UcumService ucumService = new UcumEssenceService(UcumEssenceService.class.getResourceAsStream("/ucum-essence.xml")); File cqlFile = new File(URLDecoder.decode(this.getClass().getResource(file).getFile(), "UTF-8")); CqlTranslator translator = CqlTranslator.fromFile(cqlFile, modelManager, libraryManager, ucumService); if (translator.getErrors().size() > 0) { System.err.println("Translation failed due to errors:"); ArrayList<String> errors = new ArrayList<>(); for (CqlTranslatorException error : translator.getErrors()) { TrackBack tb = error.getLocator(); String lines = tb == null ? "[n/a]" : String.format("[%d:%d, %d:%d]", tb.getStartLine(), tb.getStartChar(), tb.getEndLine(), tb.getEndChar()); System.err.printf("%s %s%n", lines, error.getMessage()); errors.add(lines + error.getMessage()); } throw new IllegalArgumentException(errors.toString()); } assertThat(translator.getErrors().size(), is(0)); String xml = translator.toXml(); return CqlLibraryReader.read(new StringReader(xml)); }
Example #28
Source File: LibraryHelper.java From cqf-ruler with Apache License 2.0 | 5 votes |
public static LibraryLoader createLibraryLoader(LibraryResolutionProvider<org.hl7.fhir.dstu3.model.Library> provider) { ModelManager modelManager = new ModelManager(); LibraryManager libraryManager = new LibraryManager(modelManager); libraryManager.getLibrarySourceLoader().clearProviders(); libraryManager.getLibrarySourceLoader().registerProvider( new LibrarySourceProvider<org.hl7.fhir.dstu3.model.Library, org.hl7.fhir.dstu3.model.Attachment>( provider, x -> x.getContent(), x -> x.getContentType(), x -> x.getData())); return new LibraryLoader(libraryManager, modelManager); }
Example #29
Source File: FhirExecutionTestBase.java From cql_engine with Apache License 2.0 | 4 votes |
@BeforeMethod public void beforeEachTestMethod() throws JAXBException, IOException, UcumException { String fileName = this.getClass().getSimpleName(); library = libraries.get(fileName); if (library == null) { ModelManager modelManager = new ModelManager(); LibraryManager libraryManager = new LibraryManager(modelManager); UcumService ucumService = new UcumEssenceService(UcumEssenceService.class.getResourceAsStream("/ucum-essence.xml")); try { File cqlFile = new File(URLDecoder.decode(this.getClass().getResource(fileName + ".cql").getFile(), "UTF-8")); ArrayList<CqlTranslator.Options> options = new ArrayList<>(); options.add(CqlTranslator.Options.EnableDateRangeOptimization); CqlTranslator translator = CqlTranslator.fromFile(cqlFile, modelManager, libraryManager, ucumService, options.toArray(new CqlTranslator.Options[options.size()])); if (translator.getErrors().size() > 0) { System.err.println("Translation failed due to errors:"); ArrayList<String> errors = new ArrayList<>(); for (CqlTranslatorException error : translator.getErrors()) { TrackBack tb = error.getLocator(); String lines = tb == null ? "[n/a]" : String.format("[%d:%d, %d:%d]", tb.getStartLine(), tb.getStartChar(), tb.getEndLine(), tb.getEndChar()); System.err.printf("%s %s%n", lines, error.getMessage()); errors.add(lines + error.getMessage()); } throw new IllegalArgumentException(errors.toString()); } assertThat(translator.getErrors().size(), is(0)); xmlFile = new File(cqlFile.getParent(), fileName + ".xml"); xmlFile.createNewFile(); PrintWriter pw = new PrintWriter(xmlFile, "UTF-8"); pw.println(translator.toXml()); pw.println(); pw.close(); } catch (IOException e) { e.printStackTrace(); } library = CqlLibraryReader.read(xmlFile); libraries.put(fileName, library); } }
Example #30
Source File: TranslatorHelper.java From cqf-ruler with Apache License 2.0 | 4 votes |
public static Library translateLibrary(String cql, LibraryManager libraryManager, ModelManager modelManager) { return translateLibrary(new ByteArrayInputStream(cql.getBytes(StandardCharsets.UTF_8)), libraryManager, modelManager); }