org.fhir.ucum.UcumEssenceService Java Examples

The following examples show how to use org.fhir.ucum.UcumEssenceService. 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: TestingUtilities.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static IWorkerContext context(String version) {
    String v = VersionUtilities.getMajMin(version);
    if (fcontexts == null) {
      fcontexts = new HashMap<>();
    }
    if (!fcontexts.containsKey(v)) {
      FilesystemPackageCacheManager pcm;
      try {
        pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
        IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
        fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
        fcontext.setExpansionProfile(new Parameters());
//        ((SimpleWorkerContext) fcontext).connectToTSServer(new TerminologyClientR5("http://tx.fhir.org/r4"), null);
        fcontexts.put(v, fcontext);
      } catch (Exception e) {
        throw new Error(e);
      }
    }
    return fcontexts.get(v);
  }
 
Example #2
Source File: TestingUtilitiesX.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static IWorkerContext context(String version) {
   if (fcontexts == null) {
     fcontexts = new HashMap<>();
   }
  if (!fcontexts.containsKey(version)) {
    FilesystemPackageCacheManager pcm;
    try {
      pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
      IWorkerContext fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage(VersionUtilities.packageForVersion(version), version), loaderForVersion(version));
      fcontext.setUcumService(new UcumEssenceService(TestingUtilitiesX.loadTestResourceStream("ucum", "ucum-essence.xml")));
      fcontext.setExpansionProfile(new Parameters());
      fcontexts.put(version, fcontext);
    } catch (Exception e) {
      throw new Error(e);
    }
  }
  return fcontexts.get(version);
}
 
Example #3
Source File: Test.java    From org.hl7.fhir.core with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
	try {
		CCDAConverter c = new CCDAConverter(new UcumEssenceService(UCUM_PATH), SimpleWorkerContext.fromPack(Utilities.path(SRC_PATH, "validation.zip")));
		Bundle a = c.convert(new FileInputStream(DEF_PATH + "ccda.xml"));
		String fx = DEF_PATH + "output.xml";
		IParser x = new XmlParser().setOutputStyle(OutputStyle.PRETTY);
		x.compose(new FileOutputStream(fx),  a);
		String fj = DEF_PATH + "output.json";
		IParser j = new JsonParser().setOutputStyle(OutputStyle.PRETTY);
		j.compose(new FileOutputStream(fj),  a);
		System.out.println("done. save as "+fx+" and "+fj);
	} catch (Exception e) {
		e.printStackTrace();
	}
	

}
 
Example #4
Source File: TestingUtilities.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static IWorkerContext context() {
  if (fcontext == null) {
    FilesystemPackageCacheManager pcm;
    try {
      pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
      fcontext = SimpleWorkerContext.fromPackage(pcm.loadPackage("hl7.fhir.core", "4.0.0"));
      fcontext.setUcumService(new UcumEssenceService(TestingUtilities.resourceNameToFile("ucum", "ucum-essence.xml")));
      fcontext.setExpansionProfile(new Parameters());
    } catch (Exception e) {
      throw new Error(e);
    }

  }
  return fcontext;
}
 
Example #5
Source File: ArgonautConverter.java    From org.hl7.fhir.core with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	try {
		ArgonautConverter c = new ArgonautConverter(new UcumEssenceService(UCUM_PATH), Utilities.path(SRC_PATH, "validation.xml.zip"));
		c.destFolder = "C:\\work\\com.healthintersections.fhir\\argonaut\\fhir";
		c.convert("C:\\work\\com.healthintersections.fhir\\argonaut\\cda\\file_emergency", new Coding().setSystem("http://hl7.org/fhir/v3/ActCode").setCode("EMER"));
		c.convert("C:\\work\\com.healthintersections.fhir\\argonaut\\cda\\file_ed", new Coding().setSystem("http://hl7.org/fhir/v3/ActCode").setCode("IMP"));
		c.convert("C:\\work\\com.healthintersections.fhir\\argonaut\\cda\\fileX", new Coding().setSystem("http://hl7.org/fhir/v3/ActCode").setCode("AMB"));
		c.printSectionSummaries();
		c.closeZips();
		System.out.println("All done. "+Integer.toString(c.getErrors())+" errors, "+Integer.toString(c.getWarnings())+" warnings");
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example #6
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 #7
Source File: TestUtils.java    From clinical_quality_language with Apache License 2.0 5 votes vote down vote up
private static void setup() {
    modelManager = new ModelManager();
    libraryManager = new LibraryManager(modelManager);
    libraryManager.getLibrarySourceLoader().registerProvider(new TestLibrarySourceProvider());
    libraryManager.getLibrarySourceLoader().registerProvider(new FhirLibrarySourceProvider());
    try {
        ucumService = new UcumEssenceService(UcumEssenceService.class.getResourceAsStream("/ucum-essence.xml"));
    }
    catch (UcumException e) {
        e.printStackTrace();
    }
}
 
Example #8
Source File: FhirExecutionTestBase.java    From cql_engine with Apache License 2.0 4 votes vote down vote up
@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 #9
Source File: CqlExecutionTestBase.java    From cql_engine with Apache License 2.0 4 votes vote down vote up
@BeforeMethod
public void beforeEachTestMethod() throws JAXBException, IOException, UcumException {
    String fileName = this.getClass().getSimpleName();
    library = libraries.get(fileName);
    if (library == null) {
        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);
            options.add(CqlTranslator.Options.EnableAnnotations);
            options.add(CqlTranslator.Options.EnableLocators);
            CqlTranslator translator = CqlTranslator.fromFile(cqlFile, getModelManager(), getLibraryManager(), 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();

            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);
    }
}
 
Example #10
Source File: IEEE11073Convertor.java    From org.hl7.fhir.core with Apache License 2.0 3 votes vote down vote up
/**
 * argument 1: path to the rosetta csv file
 * argument 2: basePath to produce files to
 *  
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
  UcumService ucum = new UcumEssenceService(UCUM_PATH);

  CodeSystem mdc = generateMDC(args[0], args[1], ucum);
  ConceptMap loinc = generateLoincMdcMap(mdc, args[1], args[2]);
}