All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
org.opencds.cqf.processor.IGRefreshProcessor Maven / Gradle / Ivy
package org.opencds.cqf.processor;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.apache.commons.io.FilenameUtils;
import org.hl7.fhir.instance.model.api.IAnyResource;
import org.opencds.cqf.parameter.RefreshIGParameters;
import org.opencds.cqf.parameter.RefreshLibraryParameters;
import org.opencds.cqf.processor.IGProcessor.IGVersion;
import org.opencds.cqf.utilities.IGUtils;
import org.opencds.cqf.utilities.IOUtils;
import org.opencds.cqf.utilities.IOUtils.Encoding;
import org.opencds.cqf.utilities.LogUtils;
import org.opencds.cqf.utilities.ResourceUtils;
import ca.uhn.fhir.context.FhirContext;
public class IGRefreshProcessor {
public static ArrayList refreshedResourcesNames = new ArrayList();
public static void refreshIG(RefreshIGParameters params) {
String igResourcePath = params.igResourcePath;
String igPath = params.igPath;
IGVersion igVersion = params.igVersion;
Encoding encoding = params.outputEncoding;
Boolean includeELM = params.includeELM;
Boolean includeDependencies = params.includeDependencies;
Boolean includeTerminology = params.includeTerminology;
Boolean includePatientScenarios = params.includePatientScenarios;
Boolean versioned = params.versioned;
String fhirUri = params.fhirUri;
String measureToRefreshPath = params.measureToRefreshPath;
ArrayList resourceDirs = params.resourceDirs;
IOUtils.resourceDirectories.addAll(resourceDirs);
FhirContext fhirContext = IGProcessor.getIgFhirContext(igVersion);
Boolean igResourcePathIsSpecified = igResourcePath != null && !igResourcePath.isEmpty();
IAnyResource implementationGuide = null;
String igCanonicalBase = null;
IGProcessor.ensure(igPath, includePatientScenarios, includeTerminology, IOUtils.resourceDirectories);
LibraryProcessor libraryProcessor;
switch (fhirContext.getVersion().getVersion()) {
case DSTU3:
libraryProcessor = new STU3LibraryProcessor();
break;
case R4:
libraryProcessor = new R4LibraryProcessor();
break;
default:
throw new IllegalArgumentException(
"Unknown fhir version: " + fhirContext.getVersion().getVersion().getFhirVersionString());
}
if (igResourcePathIsSpecified) {
implementationGuide = IOUtils.readResource(igResourcePath, fhirContext, false);
Object urlProperty = ResourceUtils.resolveProperty(implementationGuide, "url", fhirContext);
String urlValue = ResourceUtils.resolveProperty(urlProperty, "value", fhirContext).toString();
if (urlValue != null && !urlValue.isEmpty()) {
igCanonicalBase = IGUtils.getImplementationGuideCanonicalBase(urlValue);
}
}
refreshedResourcesNames = refreshIgLibraryContent(igCanonicalBase, libraryProcessor, igPath, encoding, includeELM, versioned, fhirContext, igVersion);
List refreshedMeasureNames = new ArrayList();
refreshedMeasureNames = MeasureProcessor.refreshIgMeasureContent(igPath, encoding, versioned, fhirContext, measureToRefreshPath);
refreshedResourcesNames.addAll(refreshedMeasureNames);
if (refreshedResourcesNames.isEmpty()) {
LogUtils.info("No libraries successfully refreshed.");
return;
}
if (includePatientScenarios) {
TestCaseProcessor.refreshTestCases(FilenameUtils.concat(igPath, IGProcessor.testCasePathElement), encoding, fhirContext, refreshedResourcesNames);
}
}
public static ArrayList refreshIgLibraryContent(String igCanonicalBase, LibraryProcessor libraryProcessor, String igPath, Encoding outputEncoding, Boolean includeELM,
Boolean versioned, FhirContext fhirContext, IGVersion igVersion) {
LogUtils.info("Refreshing libraries...");
ArrayList refreshedLibraryNames = new ArrayList();
HashSet cqlContentPaths = IOUtils.getCqlLibraryPaths();
for (String cqlPath : cqlContentPaths) {
try {
//ask about how to do this better
String libraryPath;
try {
libraryPath = IOUtils.getLibraryPathAssociatedWithCqlFileName(cqlPath, fhirContext);
} catch (Exception e) {
libraryPath = "";
}
RefreshLibraryParameters lp = new RefreshLibraryParameters();
lp.igCanonicalBase = igCanonicalBase;
lp.cqlContentPath = cqlPath;
lp.libraryPath = libraryPath;
lp.fhirContext = fhirContext;
lp.encoding = outputEncoding;
lp.versioned = versioned;
libraryProcessor.refreshLibraryContent(lp);
refreshedLibraryNames.add(FilenameUtils.getBaseName(cqlPath));
} catch (Exception e) {
LogUtils.putException(cqlPath, e);
}
LogUtils.warn(cqlPath);
}
return refreshedLibraryNames;
}
}