org.fhir.ucum.UcumService Java Examples

The following examples show how to use org.fhir.ucum.UcumService. 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: TestUtils.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
private static UcumService getUcumService() {
    if (ucumService == null) {
        setup();
    }

    return ucumService;
}
 
Example #2
Source File: LibraryBuilder.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
public LibraryBuilder(NamespaceInfo namespaceInfo, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService) {
    if (modelManager == null) {
        throw new IllegalArgumentException("modelManager is null");
    }

    if (libraryManager == null) {
        throw new IllegalArgumentException("libraryManager is null");
    }

    this.namespaceInfo = namespaceInfo; // Note: allowed to be null, implies global namespace
    this.modelManager = modelManager;
    this.libraryManager = libraryManager;

    this.library = of.createLibrary()
            .withSchemaIdentifier(of.createVersionedIdentifier()
                    .withId("urn:hl7-org:elm") // TODO: Pull this from the ELM library namespace
                    .withVersion("r1"));

    this.cqlToElmInfo = af.createCqlToElmInfo();
    this.cqlToElmInfo.setTranslatorVersion(LibraryBuilder.class.getPackage().getSpecificationVersion());
    this.library.getAnnotation().add(this.cqlToElmInfo);

    translatedLibrary = new TranslatedLibrary();
    translatedLibrary.setLibrary(library);

    this.ucumService = ucumService;
}
 
Example #3
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
private CqlTranslator(NamespaceInfo namespaceInfo, VersionedIdentifier sourceInfo, ANTLRInputStream is, ModelManager modelManager,
                      LibraryManager libraryManager, UcumService ucumService, CqlTranslatorOptions options) {
    this.sourceInfo = sourceInfo;
    this.namespaceInfo = namespaceInfo;
    this.modelManager = modelManager;
    this.libraryManager = libraryManager;
    this.ucumService = ucumService;
    this.errorLevel = options.getErrorLevel();

    if (this.sourceInfo == null) {
        this.sourceInfo = new VersionedIdentifier().withId("Anonymous").withSystem("text/cql");
    }

    if (this.namespaceInfo != null) {
        libraryManager.getNamespaceManager().ensureNamespaceRegistered(this.namespaceInfo);
    }

    if (libraryManager.getNamespaceManager().hasNamespaces() && libraryManager.getLibrarySourceLoader() instanceof NamespaceAware) {
        ((NamespaceAware)libraryManager.getLibrarySourceLoader()).setNamespaceManager(libraryManager.getNamespaceManager());
    }

    if (libraryManager.getUcumService() == null) {
        libraryManager.setUcumService(this.ucumService);
    }

    translateToELM(is, options);
}
 
Example #4
Source File: CqlTestSuite.java    From cql_engine with Apache License 2.0 5 votes vote down vote up
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 #5
Source File: ArgonautConverter.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public ArgonautConverter(UcumService ucumSvc, String path) throws Exception {
		super();
		this.ucumSvc = ucumSvc;
		context = SimpleWorkerContext.fromPack(path);
//		validator = new ValidationEngine();
//		validator.readDefinitions(path);
//		validator.setAnyExtensionsAllowed(true);
	}
 
Example #6
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromText(NamespaceInfo namespaceInfo, VersionedIdentifier sourceInfo, String cqlText, ModelManager modelManager,
                                     LibraryManager libraryManager, UcumService ucumService, CqlTranslatorOptions options) {
    return new CqlTranslator(namespaceInfo, sourceInfo, new ANTLRInputStream(cqlText), modelManager, libraryManager, ucumService, options);
}
 
Example #7
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(NamespaceInfo namespaceInfo, String cqlFileName, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService,
                                     CqlTranslatorException.ErrorSeverity errorLevel, CqlTranslator.Options... options) throws IOException {
    return new CqlTranslator(namespaceInfo, getSourceInfo(cqlFileName), new ANTLRInputStream(new FileInputStream(cqlFileName)), modelManager, libraryManager, ucumService, errorLevel, LibraryBuilder.SignatureLevel.None, options);
}
 
Example #8
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromText(NamespaceInfo namespaceInfo, String cqlText, ModelManager modelManager,
                                      LibraryManager libraryManager, UcumService ucumService, CqlTranslatorOptions options) {
    return new CqlTranslator(namespaceInfo, new ANTLRInputStream(cqlText), modelManager, libraryManager, ucumService, options);
}
 
Example #9
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromText(String cqlText, ModelManager modelManager,
                                     LibraryManager libraryManager, UcumService ucumService, CqlTranslatorOptions options) {
    return new CqlTranslator(null, new ANTLRInputStream(cqlText), modelManager, libraryManager, ucumService, options);
}
 
Example #10
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(NamespaceInfo namespaceInfo, File cqlFile, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService,
                                     CqlTranslatorException.ErrorSeverity errorLevel, LibraryBuilder.SignatureLevel signatureLevel, CqlTranslator.Options... options) throws IOException {
    return new CqlTranslator(namespaceInfo, getSourceInfo(cqlFile), new ANTLRInputStream(new FileInputStream(cqlFile)), modelManager, libraryManager, ucumService, errorLevel, signatureLevel, options);
}
 
Example #11
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(File cqlFile, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService,
                                     CqlTranslatorException.ErrorSeverity errorLevel, LibraryBuilder.SignatureLevel signatureLevel, CqlTranslator.Options... options) throws IOException {
    return new CqlTranslator(null, getSourceInfo(cqlFile), new ANTLRInputStream(new FileInputStream(cqlFile)), modelManager, libraryManager, ucumService, errorLevel, signatureLevel, options);
}
 
Example #12
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(NamespaceInfo namespaceInfo, File cqlFile, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService,
                                     CqlTranslatorException.ErrorSeverity errorLevel, CqlTranslator.Options... options) throws IOException {
    return new CqlTranslator(namespaceInfo, getSourceInfo(cqlFile), new ANTLRInputStream(new FileInputStream(cqlFile)), modelManager, libraryManager, ucumService, errorLevel, LibraryBuilder.SignatureLevel.None, options);
}
 
Example #13
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(File cqlFile, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService,
                                     CqlTranslatorException.ErrorSeverity errorLevel, CqlTranslator.Options... options) throws IOException {
    return new CqlTranslator(null, getSourceInfo(cqlFile), new ANTLRInputStream(new FileInputStream(cqlFile)), modelManager, libraryManager, ucumService, errorLevel, LibraryBuilder.SignatureLevel.None, options);
}
 
Example #14
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(NamespaceInfo namespaceInfo, File cqlFile, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService, CqlTranslator.Options... options) throws IOException {
    return new CqlTranslator(namespaceInfo, getSourceInfo(cqlFile), new ANTLRInputStream(new FileInputStream(cqlFile)), modelManager, libraryManager, ucumService, CqlTranslatorException.ErrorSeverity.Info, LibraryBuilder.SignatureLevel.None, options);
}
 
Example #15
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(File cqlFile, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService, CqlTranslator.Options... options) throws IOException {
    return new CqlTranslator(null, getSourceInfo(cqlFile), new ANTLRInputStream(new FileInputStream(cqlFile)), modelManager, libraryManager, ucumService, CqlTranslatorException.ErrorSeverity.Info, LibraryBuilder.SignatureLevel.None, options);
}
 
Example #16
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(NamespaceInfo namespaceInfo, String cqlFileName, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService,
                                     CqlTranslatorException.ErrorSeverity errorLevel, LibraryBuilder.SignatureLevel signatureLevel, CqlTranslator.Options... options) throws IOException {
    return new CqlTranslator(namespaceInfo, getSourceInfo(cqlFileName), new ANTLRInputStream(new FileInputStream(cqlFileName)), modelManager, libraryManager, ucumService, errorLevel, signatureLevel, options);
}
 
Example #17
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(String cqlFileName, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService,
                                     CqlTranslatorException.ErrorSeverity errorLevel, LibraryBuilder.SignatureLevel signatureLevel, CqlTranslator.Options... options) throws IOException {
    return new CqlTranslator(null, getSourceInfo(cqlFileName), new ANTLRInputStream(new FileInputStream(cqlFileName)), modelManager, libraryManager, ucumService, errorLevel, signatureLevel, options);
}
 
Example #18
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(NamespaceInfo namespaceInfo, String cqlFileName, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService, CqlTranslator.Options... options) throws IOException {
    return new CqlTranslator(namespaceInfo, getSourceInfo(cqlFileName), new ANTLRInputStream(new FileInputStream(cqlFileName)), modelManager, libraryManager, ucumService, CqlTranslatorException.ErrorSeverity.Info, LibraryBuilder.SignatureLevel.None, options);
}
 
Example #19
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromStream(InputStream cqlStream, ModelManager modelManager,
                                       LibraryManager libraryManager, UcumService ucumService, CqlTranslatorOptions options) throws IOException {
    return new CqlTranslator(null, new ANTLRInputStream(cqlStream), modelManager, libraryManager, ucumService, options);
}
 
Example #20
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromStream(NamespaceInfo namespaceInfo, InputStream cqlStream, ModelManager modelManager,
                                       LibraryManager libraryManager, UcumService ucumService, CqlTranslatorOptions options) throws IOException {
    return new CqlTranslator(namespaceInfo, new ANTLRInputStream(cqlStream), modelManager, libraryManager, ucumService, options);
}
 
Example #21
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromStream(NamespaceInfo namespaceInfo, VersionedIdentifier sourceInfo, InputStream cqlStream, ModelManager modelManager,
                                       LibraryManager libraryManager, UcumService ucumService, CqlTranslatorOptions options) throws IOException {
    return new CqlTranslator(namespaceInfo, sourceInfo, new ANTLRInputStream(cqlStream), modelManager, libraryManager, ucumService, options);
}
 
Example #22
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(File cqlFile, ModelManager modelManager,
                                     LibraryManager libraryManager, UcumService ucumService, CqlTranslatorOptions options) throws IOException {
    return new CqlTranslator(null, getSourceInfo(cqlFile), new ANTLRInputStream(new FileInputStream(cqlFile)), modelManager, libraryManager, ucumService, options);
}
 
Example #23
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(NamespaceInfo namespaceInfo, File cqlFile, ModelManager modelManager,
                                     LibraryManager libraryManager, UcumService ucumService, CqlTranslatorOptions options) throws IOException {
    return new CqlTranslator(namespaceInfo, getSourceInfo(cqlFile), new ANTLRInputStream(new FileInputStream(cqlFile)), modelManager, libraryManager, ucumService, options);
}
 
Example #24
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public static CqlTranslator fromFile(NamespaceInfo namespaceInfo, VersionedIdentifier sourceInfo, File cqlFile, ModelManager modelManager,
                                     LibraryManager libraryManager, UcumService ucumService, CqlTranslatorOptions options) throws IOException {
    return new CqlTranslator(namespaceInfo, sourceInfo, new ANTLRInputStream(new FileInputStream(cqlFile)), modelManager, libraryManager, ucumService, options);
}
 
Example #25
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
private CqlTranslator(NamespaceInfo namespaceInfo, VersionedIdentifier sourceInfo, ANTLRInputStream is, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService,
                      CqlTranslatorException.ErrorSeverity errorLevel, LibraryBuilder.SignatureLevel signatureLevel, CqlTranslator.Options... options) {
    this(namespaceInfo, sourceInfo, is, modelManager, libraryManager, ucumService, new CqlTranslatorOptions(errorLevel, signatureLevel, options));
}
 
Example #26
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
private CqlTranslator(NamespaceInfo namespaceInfo, ANTLRInputStream is, ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService,
                      CqlTranslatorException.ErrorSeverity errorLevel, LibraryBuilder.SignatureLevel signatureLevel, CqlTranslator.Options... options) {
    this(namespaceInfo, is, modelManager, libraryManager, ucumService, new CqlTranslatorOptions(errorLevel, signatureLevel, options));
}
 
Example #27
Source File: CqlTranslator.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
private CqlTranslator(NamespaceInfo namespaceInfo, ANTLRInputStream is, ModelManager modelManager,
                      LibraryManager libraryManager, UcumService ucumService, CqlTranslatorOptions options) {
    this(namespaceInfo, null, is, modelManager, libraryManager, ucumService, options);
}
 
Example #28
Source File: LibraryBuilder.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public LibraryBuilder(ModelManager modelManager, LibraryManager libraryManager, UcumService ucumService) {
    this(null, modelManager, libraryManager, ucumService);
}
 
Example #29
Source File: LibraryManager.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public UcumService getUcumService() {
    return this.ucumService;
}
 
Example #30
Source File: LibraryManager.java    From clinical_quality_language with Apache License 2.0 4 votes vote down vote up
public void setUcumService(UcumService ucumService) {
    this.ucumService = ucumService;
}