Search in sources :

Example 1 with CqlTranslatorOptions

use of org.cqframework.cql.cql2elm.CqlTranslatorOptions in project cqf-ruler by DBCG.

the class Translators method getTranslatorOptions.

public static CqlTranslatorOptions getTranslatorOptions() {
    CqlTranslatorOptions cqlTranslatorOptions = new CqlTranslatorOptions();
    cqlTranslatorOptions.getOptions().addAll(generateDefaultTranslatorOptions());
    cqlTranslatorOptions.setAnalyzeDataRequirements(true);
    cqlTranslatorOptions.setCollapseDataRequirements(true);
    return cqlTranslatorOptions;
}
Also used : CqlTranslatorOptions(org.cqframework.cql.cql2elm.CqlTranslatorOptions)

Example 2 with CqlTranslatorOptions

use of org.cqframework.cql.cql2elm.CqlTranslatorOptions in project CRD by HL7-DaVinci.

the class LocalLibraryLoader method loadLibrary.

private Library loadLibrary(VersionedIdentifier libraryIdentifier) {
    List<CqlTranslatorException> errors = new ArrayList<>();
    org.hl7.elm.r1.VersionedIdentifier identifier = new org.hl7.elm.r1.VersionedIdentifier().withId(libraryIdentifier.getId()).withSystem(libraryIdentifier.getSystem()).withVersion(libraryIdentifier.getVersion());
    CqlTranslatorOptions options = new CqlTranslatorOptions();
    org.cqframework.cql.cql2elm.model.TranslatedLibrary translatedLibrary = libraryManager.resolveLibrary(identifier, options, errors);
    String xml;
    try {
        JAXBContext jc = JAXBContext.newInstance(org.hl7.elm.r1.Library.class, Annotation.class);
        Marshaller marshaller = jc.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        StringWriter writer = new StringWriter();
        marshaller.marshal(new ObjectFactory().createLibrary(translatedLibrary.getLibrary()), writer);
        xml = writer.getBuffer().toString();
    } catch (JAXBException e) {
        throw new RuntimeException(String.format("Errors encountered while loading library %s: %s", libraryIdentifier.getId(), e.getMessage()));
    }
    Library library = null;
    try {
        library = CqlLibraryReader.read(new StringReader(xml));
    } catch (IOException | JAXBException e) {
        throw new RuntimeException(String.format("Errors encountered while loading library %s: %s", libraryIdentifier.getId(), e.getMessage()));
    }
    return library;
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) IOException(java.io.IOException) CqlTranslatorOptions(org.cqframework.cql.cql2elm.CqlTranslatorOptions) CqlTranslatorException(org.cqframework.cql.cql2elm.CqlTranslatorException) StringWriter(java.io.StringWriter) ObjectFactory(org.hl7.elm.r1.ObjectFactory) StringReader(java.io.StringReader) Library(org.cqframework.cql.elm.execution.Library)

Aggregations

CqlTranslatorOptions (org.cqframework.cql.cql2elm.CqlTranslatorOptions)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 ArrayList (java.util.ArrayList)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Marshaller (javax.xml.bind.Marshaller)1 CqlTranslatorException (org.cqframework.cql.cql2elm.CqlTranslatorException)1 Library (org.cqframework.cql.elm.execution.Library)1 ObjectFactory (org.hl7.elm.r1.ObjectFactory)1