use of org.hl7.fhir.r4.model.Enumerations.DocumentReferenceStatus.CURRENT in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcRepeat.
private List<Base> funcRepeat(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> result = new ArrayList<Base>();
List<Base> current = new ArrayList<Base>();
current.addAll(focus);
List<Base> added = new ArrayList<Base>();
boolean more = true;
while (more) {
added.clear();
List<Base> pc = new ArrayList<Base>();
for (Base item : current) {
pc.clear();
pc.add(item);
added.addAll(execute(changeThis(context, item), pc, exp.getParameters().get(0), false));
}
more = !added.isEmpty();
result.addAll(added);
current.clear();
current.addAll(added);
}
return result;
}
use of org.hl7.fhir.r4.model.Enumerations.DocumentReferenceStatus.CURRENT in project org.hl7.fhir.core by hapifhir.
the class FHIRPathEngine method funcDescendants.
private List<Base> funcDescendants(ExecutionContext context, List<Base> focus, ExpressionNode exp) throws FHIRException {
List<Base> result = new ArrayList<Base>();
List<Base> current = new ArrayList<Base>();
current.addAll(focus);
List<Base> added = new ArrayList<Base>();
boolean more = true;
while (more) {
added.clear();
for (Base item : current) {
getChildrenByName(item, "*", added);
}
more = !added.isEmpty();
result.addAll(added);
current.clear();
current.addAll(added);
}
return result;
}
use of org.hl7.fhir.r4.model.Enumerations.DocumentReferenceStatus.CURRENT in project org.hl7.fhir.core by hapifhir.
the class DefinitionNavigator method loadChildren.
private void loadChildren() throws DefinitionException {
children = new ArrayList<DefinitionNavigator>();
String prefix = current().getPath() + ".";
Map<String, DefinitionNavigator> nameMap = new HashMap<String, DefinitionNavigator>();
for (int i = index + 1; i < structure.getSnapshot().getElement().size(); i++) {
String path = structure.getSnapshot().getElement().get(i).getPath();
if (path.startsWith(prefix) && !path.substring(prefix.length()).contains(".")) {
DefinitionNavigator dn = new DefinitionNavigator(context, structure, i, this.path + "." + tail(path), names, null);
if (nameMap.containsKey(path)) {
DefinitionNavigator master = nameMap.get(path);
if (!master.current().hasSlicing())
throw new DefinitionException("Found slices with no slicing details at " + dn.current().getPath());
if (master.slices == null)
master.slices = new ArrayList<DefinitionNavigator>();
master.slices.add(dn);
} else {
nameMap.put(path, dn);
children.add(dn);
}
} else if (path.length() < prefix.length())
break;
}
}
use of org.hl7.fhir.r4.model.Enumerations.DocumentReferenceStatus.CURRENT in project org.hl7.fhir.core by hapifhir.
the class FilesystemPackageCacheManager method checkCurrency.
private NpmPackage checkCurrency(String id, NpmPackage p) throws IOException {
checkBuildLoaded();
// special case: current versions roll over, and we have to check their currency
try {
String url = ciList.get(id);
JsonObject json = JsonTrackingParser.fetchJson(Utilities.pathURL(url, "package.manifest.json"));
String currDate = JSONUtil.str(json, "date");
String packDate = p.date();
if (!currDate.equals(packDate)) {
// nup, we need a new copy
return null;
}
} catch (Exception e) {
}
return p;
}
use of org.hl7.fhir.r4.model.Enumerations.DocumentReferenceStatus.CURRENT in project org.hl7.fhir.core by hapifhir.
the class FilesystemPackageCacheManager method addPackageToCache.
/**
* Add an already fetched package to the cache
*/
@Override
public NpmPackage addPackageToCache(String id, String version, InputStream packageTgzInputStream, String sourceDesc) throws IOException {
checkValidVersionString(version, id);
if (progress) {
log("Installing " + id + "#" + (version == null ? "?" : version) + " to the package cache");
log(" Fetching:");
}
NpmPackage npm = NpmPackage.fromPackage(packageTgzInputStream, sourceDesc, true);
if (progress) {
log("");
logn(" Installing: ");
}
if (!suppressErrors && npm.name() == null || id == null || !id.equalsIgnoreCase(npm.name())) {
if (!id.equals("hl7.fhir.r5.core") && !id.equals("hl7.fhir.us.immds")) {
// temporary work around
throw new IOException("Attempt to import a mis-identified package. Expected " + id + ", got " + npm.name());
}
}
if (version == null)
version = npm.version();
String v = version;
return new CacheLock(id + "#" + version).doWithLock(() -> {
NpmPackage pck = null;
String packRoot = Utilities.path(cacheFolder, id + "#" + v);
try {
// ok, now we have a lock on it... check if something created it while we were waiting
if (!new File(packRoot).exists() || Utilities.existsInList(v, "current", "dev")) {
Utilities.createDirectory(packRoot);
try {
Utilities.clearDirectory(packRoot);
} catch (Throwable t) {
log("Unable to clear directory: " + packRoot + ": " + t.getMessage() + " - this may cause problems later");
}
int i = 0;
int c = 0;
int size = 0;
for (Entry<String, NpmPackageFolder> e : npm.getFolders().entrySet()) {
String dir = e.getKey().equals("package") ? Utilities.path(packRoot, "package") : Utilities.path(packRoot, "package", e.getKey());
if (!(new File(dir).exists()))
Utilities.createDirectory(dir);
for (Entry<String, byte[]> fe : e.getValue().getContent().entrySet()) {
String fn = Utilities.path(dir, Utilities.cleanFileName(fe.getKey()));
byte[] cnt = fe.getValue();
TextFile.bytesToFile(cnt, fn);
size = size + cnt.length;
i++;
if (progress && i % 50 == 0) {
c++;
logn(".");
if (c == 120) {
log("");
logn(" ");
c = 2;
}
}
}
}
IniFile ini = new IniFile(Utilities.path(cacheFolder, "packages.ini"));
ini.setTimeStampFormat("yyyyMMddhhmmss");
ini.setTimestampProperty("packages", id + "#" + v, Timestamp.from(Instant.now()), null);
ini.setIntegerProperty("package-sizes", id + "#" + v, size, null);
ini.save();
if (progress)
log(" done.");
}
pck = loadPackageInfo(packRoot);
if (!id.equals(JSONUtil.str(npm.getNpm(), "name")) || !v.equals(JSONUtil.str(npm.getNpm(), "version"))) {
if (!id.equals(JSONUtil.str(npm.getNpm(), "name"))) {
npm.getNpm().addProperty("original-name", JSONUtil.str(npm.getNpm(), "name"));
npm.getNpm().remove("name");
npm.getNpm().addProperty("name", id);
}
if (!v.equals(JSONUtil.str(npm.getNpm(), "version"))) {
npm.getNpm().addProperty("original-version", JSONUtil.str(npm.getNpm(), "version"));
npm.getNpm().remove("version");
npm.getNpm().addProperty("version", v);
}
TextFile.stringToFile(new GsonBuilder().setPrettyPrinting().create().toJson(npm.getNpm()), Utilities.path(cacheFolder, id + "#" + v, "package", "package.json"), false);
}
} catch (Exception e) {
try {
// don't leave a half extracted package behind
log("Clean up package " + packRoot + " because installation failed: " + e.getMessage());
e.printStackTrace();
Utilities.clearDirectory(packRoot);
new File(packRoot).delete();
} catch (Exception ei) {
// nothing
}
throw e;
}
return pck;
});
}
Aggregations