Search in sources :

Example 26 with CURRENT

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;
}
Also used : ArrayList(java.util.ArrayList) Base(org.hl7.fhir.r4b.model.Base)

Example 27 with CURRENT

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;
}
Also used : ArrayList(java.util.ArrayList) Base(org.hl7.fhir.r4b.model.Base)

Example 28 with CURRENT

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;
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DefinitionException(org.hl7.fhir.exceptions.DefinitionException)

Example 29 with CURRENT

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;
}
Also used : JsonObject(com.google.gson.JsonObject) ParseException(java.text.ParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 30 with CURRENT

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;
    });
}
Also used : IniFile(org.hl7.fhir.utilities.IniFile) GsonBuilder(com.google.gson.GsonBuilder) IOException(java.io.IOException) NpmPackageFolder(org.hl7.fhir.utilities.npm.NpmPackage.NpmPackageFolder) ParseException(java.text.ParseException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FHIRException(org.hl7.fhir.exceptions.FHIRException) RandomAccessFile(java.io.RandomAccessFile) IniFile(org.hl7.fhir.utilities.IniFile) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile)

Aggregations

ArrayList (java.util.ArrayList)38 Date (java.util.Date)31 Code (org.mitre.synthea.world.concepts.HealthRecord.Code)24 Coding (org.hl7.fhir.r4.model.Coding)21 Reference (org.hl7.fhir.r4.model.Reference)21 DocumentReference (org.hl7.fhir.r4.model.DocumentReference)20 Encounter (org.mitre.synthea.world.concepts.HealthRecord.Encounter)17 Reference (org.hl7.fhir.dstu3.model.Reference)16 HashMap (java.util.HashMap)15 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)15 Coding (org.hl7.fhir.dstu3.model.Coding)14 Identifier (org.hl7.fhir.r4.model.Identifier)14 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)13 JsonObject (com.google.gson.JsonObject)12 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)12 Meta (org.hl7.fhir.r4.model.Meta)12 List (java.util.List)11 Period (org.hl7.fhir.r4.model.Period)11 Test (org.junit.jupiter.api.Test)11 Extension (org.hl7.fhir.r4.model.Extension)10