use of org.cqframework.cql.cql2elm.FhirLibrarySourceProvider in project cqf-ruler by DBCG.
the class CqlBuilder method validate.
private void validate(String cql) {
ModelManager modelManager = new ModelManager();
LibraryManager libraryManager = new LibraryManager(modelManager);
libraryManager.getLibrarySourceLoader().registerProvider(new FhirLibrarySourceProvider());
CqlTranslator translator;
try {
translator = CqlTranslator.fromStream(new ByteArrayInputStream(cql.getBytes()), modelManager, libraryManager);
} catch (IOException e) {
throw new CqlTranslatorException("Error validating cql", e);
}
if (translator.getErrors().size() > 0) {
throw new CqlTranslatorException("Error validating cql: " + Translators.errorsToString(translator.getErrors()));
}
}
use of org.cqframework.cql.cql2elm.FhirLibrarySourceProvider in project CRD by HL7-DaVinci.
the class CqlExecution method translateToElm.
public static String translateToElm(String cql, LibrarySourceProvider librarySourceProvider) throws Exception {
ModelManager modelManager = new ModelManager();
LibraryManager libraryManager = new LibraryManager(modelManager);
libraryManager.getLibrarySourceLoader().registerProvider(new FhirLibrarySourceProvider());
if (librarySourceProvider != null) {
libraryManager.getLibrarySourceLoader().registerProvider(librarySourceProvider);
}
ArrayList<CqlTranslator.Options> options = new ArrayList<>();
options.add(CqlTranslator.Options.EnableDateRangeOptimization);
UcumService ucumService = new UcumEssenceService(UcumEssenceService.class.getResourceAsStream("/ucum-essence.xml"));
CqlTranslator translator = CqlTranslator.fromText(cql, modelManager, libraryManager, ucumService, options.toArray(new CqlTranslator.Options[options.size()]));
libraryManager.getLibrarySourceLoader().clearProviders();
if (translator.getErrors().size() > 0) {
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());
errors.add(lines + error.getMessage());
}
throw new IllegalArgumentException(errors.toString());
}
return translator.toJson();
}
Aggregations