use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class NPMPackageGenerator method loadFiles.
public void loadFiles(String root, File dir, String... noload) throws IOException {
for (File f : dir.listFiles()) {
if (!Utilities.existsInList(f.getName(), noload)) {
if (f.isDirectory()) {
loadFiles(root, f);
} else {
String path = f.getAbsolutePath().substring(root.length() + 1);
byte[] content = TextFile.fileToBytes(f);
if (created.contains(path))
System.out.println("Duplicate package file " + path);
else {
created.add(path);
TarArchiveEntry entry = new TarArchiveEntry(path);
entry.setSize(content.length);
tar.putArchiveEntry(entry);
tar.write(content);
tar.closeArchiveEntry();
}
}
}
}
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class BaseWorkerContext method cacheResourceFromPackage.
public void cacheResourceFromPackage(Resource r, PackageVersion packageInfo) throws FHIRException {
synchronized (lock) {
if (r.getId() != null) {
Map<String, ResourceProxy> map = allResourcesById.get(r.fhirType());
if (map == null) {
map = new HashMap<String, ResourceProxy>();
allResourcesById.put(r.fhirType(), map);
}
if ((packageInfo == null || !packageInfo.isExamplesPackage()) || !map.containsKey(r.getId())) {
map.put(r.getId(), new ResourceProxy(r));
} else {
logger.logDebugMessage(LogCategory.PROGRESS, "Ignore " + r.fhirType() + "/" + r.getId() + " from package " + packageInfo.toString());
}
}
if (r instanceof CodeSystem || r instanceof NamingSystem) {
oidCache.clear();
}
if (r instanceof CanonicalResource) {
CanonicalResource m = (CanonicalResource) r;
String url = m.getUrl();
if (!allowLoadingDuplicates && hasResource(r.getClass(), url)) {
// special workaround for known problems with existing packages
if (Utilities.existsInList(url, "http://hl7.org/fhir/SearchParameter/example")) {
return;
}
throw new DefinitionException(formatMessage(I18nConstants.DUPLICATE_RESOURCE_, url));
}
if (r instanceof StructureDefinition) {
StructureDefinition sd = (StructureDefinition) m;
if ("1.4.0".equals(version)) {
fixOldSD(sd);
}
structures.see(sd, packageInfo);
} else if (r instanceof ValueSet) {
valueSets.see((ValueSet) m, packageInfo);
} else if (r instanceof CodeSystem) {
CodeSystemUtilities.crossLinkCodeSystem((CodeSystem) r);
codeSystems.see((CodeSystem) m, packageInfo);
} else if (r instanceof ImplementationGuide) {
guides.see((ImplementationGuide) m, packageInfo);
} else if (r instanceof CapabilityStatement) {
capstmts.see((CapabilityStatement) m, packageInfo);
} else if (r instanceof Measure) {
measures.see((Measure) m, packageInfo);
} else if (r instanceof Library) {
libraries.see((Library) m, packageInfo);
} else if (r instanceof SearchParameter) {
searchParameters.see((SearchParameter) m, packageInfo);
} else if (r instanceof PlanDefinition) {
plans.see((PlanDefinition) m, packageInfo);
} else if (r instanceof OperationDefinition) {
operations.see((OperationDefinition) m, packageInfo);
} else if (r instanceof Questionnaire) {
questionnaires.see((Questionnaire) m, packageInfo);
} else if (r instanceof ConceptMap) {
maps.see((ConceptMap) m, packageInfo);
} else if (r instanceof StructureMap) {
transforms.see((StructureMap) m, packageInfo);
} else if (r instanceof NamingSystem) {
systems.see((NamingSystem) m, packageInfo);
}
}
}
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class ParsingTests method data.
public static Stream<Arguments> data() throws ParserConfigurationException, IOException, FHIRFormatError, SAXException {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
npm = pcm.loadPackage("hl7.fhir.r5.examples", "5.0.0");
List<Arguments> objects = new ArrayList<>();
List<String> names = npm.list("package");
for (String n : names) {
if (!n.contains("manifest.json") && !n.contains("xver-") && !n.contains("uml.json") && !n.contains("package-min-ver.json")) {
objects.add(Arguments.of(n));
}
}
return objects.stream();
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class StandAloneValidatorFetcher method resolveURL.
@Override
public boolean resolveURL(IResourceValidator validator, Object appContext, String path, String url, String type) throws IOException, FHIRException {
if (!Utilities.isAbsoluteUrl(url)) {
return false;
}
if (url.contains("|")) {
url = url.substring(0, url.lastIndexOf("|"));
}
if (type != null && type.equals("uri") && isMappingUri(url)) {
return true;
}
// if we've got to here, it's a reference to a FHIR URL. We're going to try to resolve it on the fly
String pid = null;
String ver = null;
String base = findBaseUrl(url);
if (base == null) {
return !url.startsWith("http://hl7.org/fhir") && !type.equals("canonical");
}
// the next operations are expensive. we're going to cache them
if (urlList.containsKey(url)) {
return urlList.get(url);
}
if (base.equals("http://terminology.hl7.org")) {
pid = "hl7.terminology";
} else if (url.startsWith("http://hl7.org/fhir")) {
pid = pcm.getPackageId(base);
} else {
if (pidList.containsKey(base)) {
pid = pidList.get(base);
} else {
pid = pcm.findCanonicalInLocalCache(base);
pidList.put(base, pid);
}
}
ver = url.contains("|") ? url.substring(url.indexOf("|") + 1) : null;
if (pid == null && Utilities.startsWithInList(url, "http://hl7.org/fhir", "http://terminology.hl7.org")) {
urlList.put(url, false);
return false;
}
if (url.startsWith("http://hl7.org/fhir")) {
// first possibility: it's a reference to a version specific URL http://hl7.org/fhir/X.X/...
VersionURLInfo vu = VersionUtilities.parseVersionUrl(url);
if (vu != null) {
NpmPackage pi = pcm.loadPackage(VersionUtilities.packageForVersion(vu.getVersion()), VersionUtilities.getCurrentVersion(vu.getVersion()));
boolean res = pi.hasCanonical(vu.getUrl());
urlList.put(url, res);
return res;
}
}
// ok maybe it's a reference to a package we know
if (pid != null) {
if ("sharedhealth.fhir.ca.common".equals(pid)) {
// special case - optimise this
return false;
}
NpmPackage pi = null;
if (pidMap.containsKey(pid + "|" + ver)) {
pi = pidMap.get(pid + "|" + ver);
} else if (installer.packageExists(pid, ver)) {
try {
installer.loadPackage(pid, ver);
pi = pcm.loadPackage(pid);
pidMap.put(pid + "|" + ver, pi);
} catch (Exception e) {
pidMap.put(pid + "|" + ver, null);
}
} else {
pidMap.put(pid + "|" + ver, null);
}
if (pi != null) {
context.loadFromPackage(pi, null);
return pi.hasCanonical(url);
}
}
// we don't bother with urls outside fhir space in the standalone validator - we assume they are valid
return !url.startsWith("http://hl7.org/fhir") && !type.equals("canonical");
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class R3TEchnicalCorrectionProcessor method extractToPackageMaster.
private void extractToPackageMaster(List<Resource> list, String root) throws IOException, FHIRFormatError {
System.out.println("Updating Packages Master");
String corePath = Utilities.path(root, "hl7.fhir.r3.core", "package");
String examplesPath = Utilities.path(root, "hl7.fhir.r3.examples", "package");
String elementsPath = Utilities.path(root, "hl7.fhir.r3.elements", "package");
int coreTotal = new File(corePath).list().length - 1;
int examplesTotal = new File(examplesPath).list().length - 1;
int elementsTotal = new File(elementsPath).list().length - 1;
int coreCount = 0;
int examplesCount = 0;
int elementsCount = 0;
for (Resource r : list) {
String n = r.fhirType() + "-" + r.getId() + ".json";
FileOutputStream dst = null;
if (n.startsWith("DataElement-")) {
elementsCount++;
dst = new FileOutputStream(Utilities.path(elementsPath, n));
new JsonParser().setOutputStyle(OutputStyle.NORMAL).compose(dst, r);
} else {
dst = new FileOutputStream(Utilities.path(examplesPath, n));
new JsonParser().setOutputStyle(OutputStyle.NORMAL).compose(dst, r);
examplesCount++;
if (isCoreResource(r.fhirType())) {
coreCount++;
DomainResource dr = (DomainResource) r;
dr.setText(null);
new JsonParser().setOutputStyle(OutputStyle.NORMAL).compose(new FileOutputStream(Utilities.path(corePath, n)), r);
}
}
}
System.out.println(" Core @ " + corePath + ": Replaced " + coreCount + " of " + coreTotal);
System.out.println(" Examples @ " + examplesPath + ": Replaced " + examplesCount + " of " + examplesTotal);
System.out.println(" Elements @ " + elementsPath + ": Replaced " + elementsCount + " of " + elementsTotal);
}
Aggregations