當前位置: 首頁>>代碼示例>>Java>>正文


Java CqlTranslator類代碼示例

本文整理匯總了Java中org.cqframework.cql.cql2elm.CqlTranslator的典型用法代碼示例。如果您正苦於以下問題:Java CqlTranslator類的具體用法?Java CqlTranslator怎麽用?Java CqlTranslator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CqlTranslator類屬於org.cqframework.cql.cql2elm包,在下文中一共展示了CqlTranslator類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getTranslator

import org.cqframework.cql.cql2elm.CqlTranslator; //導入依賴的package包/類
public static CqlTranslator getTranslator(InputStream cqlStream, LibraryManager libraryManager, ModelManager modelManager) {
    ArrayList<CqlTranslator.Options> options = new ArrayList<>();
    options.add(CqlTranslator.Options.EnableDateRangeOptimization);
    options.add(CqlTranslator.Options.EnableAnnotations);
    options.add(CqlTranslator.Options.EnableDetailedErrors);
    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()));
    }

    if (translator.getErrors().size() > 0) {
        throw new IllegalArgumentException(errorsToString(translator.getErrors()));
    }

    return translator;
}
 
開發者ID:DBCG,項目名稱:cqf-ruler,代碼行數:20,代碼來源:LibraryHelper.java

示例2: maybe_cql_to_elm_xml

import org.cqframework.cql.cql2elm.CqlTranslator; //導入依賴的package包/類
public static String maybe_cql_to_elm_xml(String maybe_cql_source_code,
    ArrayList<String> errors)
{
    ModelManager modelManager = new ModelManager();
    LibraryManager libraryManager = new LibraryManager(modelManager);

    ArrayList<CqlTranslator.Options> options = new ArrayList<>();
    options.add(CqlTranslator.Options.EnableDateRangeOptimization);

    CqlTranslator translator = CqlTranslator.fromText(
        maybe_cql_source_code, modelManager, libraryManager,
        options.toArray(new CqlTranslator.Options[options.size()]));

    if (translator.getErrors().size() > 0)
    {
        if (errors != null)
        {
            collect_errors(errors, translator.getErrors());
        }
        return null;
    }

    String elm_xml = translator.toXml();

    if (translator.getErrors().size() > 0)
    {
        if (errors != null)
        {
            collect_errors(errors, translator.getErrors());
        }
        return null;
    }

    return elm_xml;
}
 
開發者ID:DBCG,項目名稱:cql_engine,代碼行數:36,代碼來源:CqlToElmLib.java

示例3: loadLibrary

import org.cqframework.cql.cql2elm.CqlTranslator; //導入依賴的package包/類
private Library loadLibrary(VersionedIdentifier libraryIdentifier) {
    IdType id = new IdType(libraryIdentifier.getId());
    org.hl7.fhir.dstu3.model.Library library = provider.getDao().read(id);

    InputStream is = null;
    for (org.hl7.fhir.dstu3.model.Attachment content : library.getContent()) {
        is = new ByteArrayInputStream(content.getData());
        if (content.getContentType().equals("application/elm+xml")) {
            return readLibrary(is);
        }
        else if (content.getContentType().equals("text/cql")) {
            return translateLibrary(is, libraryManager, modelManager);
        }
    }

    org.hl7.elm.r1.VersionedIdentifier identifier = new org.hl7.elm.r1.VersionedIdentifier()
            .withId(libraryIdentifier.getId())
            .withSystem(libraryIdentifier.getSystem())
            .withVersion(libraryIdentifier.getVersion());

    ArrayList<CqlTranslatorException> errors = new ArrayList<>();
    org.hl7.elm.r1.Library translatedLibrary = libraryManager.resolveLibrary(identifier, errors).getLibrary();

    if (errors.size() > 0) {
        throw new IllegalArgumentException(errorsToString(errors));
    }

    try {
        return readLibrary(new ByteArrayInputStream(CqlTranslator.fromStream(is == null ? new ByteArrayInputStream(new byte[]{}) : is, modelManager, libraryManager).convertToXml(translatedLibrary).getBytes(StandardCharsets.UTF_8)));
    } catch (JAXBException | IOException e) {
        throw new IllegalArgumentException(String.format("Errors occurred translating library %s%s.",
                identifier.getId(), identifier.getVersion() != null ? ("-" + identifier.getVersion()) : ""));
    }
}
 
開發者ID:DBCG,項目名稱:cqf-ruler,代碼行數:35,代碼來源:STU3LibraryLoader.java

示例4: beforeEachTestMethod

import org.cqframework.cql.cql2elm.CqlTranslator; //導入依賴的package包/類
@BeforeMethod
public void beforeEachTestMethod() throws JAXBException, IOException {
    String fileName = this.getClass().getSimpleName();
    library = libraries.get(fileName);
    if (library == null) {
        ModelManager modelManager = new ModelManager();
        LibraryManager libraryManager = new LibraryManager(modelManager);
        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, 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);
    }
}
 
開發者ID:DBCG,項目名稱:cql_engine,代碼行數:45,代碼來源:FhirExecutionTestBase.java

示例5: beforeEachTestMethod

import org.cqframework.cql.cql2elm.CqlTranslator; //導入依賴的package包/類
@BeforeMethod
public void beforeEachTestMethod() throws JAXBException, IOException {
    String fileName = this.getClass().getSimpleName();
    library = libraries.get(fileName);
    if (library == null) {
        ModelManager modelManager = new ModelManager();
        LibraryManager libraryManager = new LibraryManager(modelManager);
        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, 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();

            String xml = translator.toXml();

            PrintWriter pw = new PrintWriter(xmlFile, "UTF-8");
            pw.println(xml);
            pw.println();
            pw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        library = CqlLibraryReader.read(xmlFile);
        libraries.put(fileName, library);
    }
}
 
開發者ID:DBCG,項目名稱:cql_engine,代碼行數:47,代碼來源:CqlExecutionTestBase.java

示例6: translateLibrary

import org.cqframework.cql.cql2elm.CqlTranslator; //導入依賴的package包/類
public static Library translateLibrary(InputStream cqlStream, LibraryManager libraryManager, ModelManager modelManager) {
    CqlTranslator translator = getTranslator(cqlStream, libraryManager, modelManager);
    return readLibrary(new ByteArrayInputStream(translator.toXml().getBytes(StandardCharsets.UTF_8)));
}
 
開發者ID:DBCG,項目名稱:cqf-ruler,代碼行數:5,代碼來源:LibraryHelper.java


注:本文中的org.cqframework.cql.cql2elm.CqlTranslator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。