Search in sources :

Example 6 with Package

use of org.hl7.fhir.utilities.graphql.Package in project Gravity-SDOH-Exchange-RI by FHIR.

the class ConvertService method initValidationEngine.

@EventListener(ApplicationReadyEvent.class)
protected void initValidationEngine() throws IOException, URISyntaxException {
    String definitions = VersionUtilities.packageForVersion(PACKAGE_VERSION) + "#" + VersionUtilities.getCurrentVersion(PACKAGE_VERSION);
    this.validationEngine = new ValidationEngine(definitions, FhirPublication.R4, PACKAGE_VERSION, new TimeTracker());
    // Loading structure definitions from official package and uploading custom definitions if needed from resources
    this.validationEngine.loadPackage(SDOH_CLINICAL_CARE_PACKAGE, SDOH_CLINICAL_CARE_VERSION);
    // Loading  custom structure definitions, copying all resources from jar to local folder to be able for HAPI to
    // upload them. Just passing resources folder is not working for "in jar" files.
    loadStructureDefinitions();
}
Also used : TimeTracker(org.hl7.fhir.utilities.TimeTracker) ValidationEngine(org.hl7.fhir.validation.ValidationEngine) EventListener(org.springframework.context.event.EventListener)

Example 7 with Package

use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.

the class ExtensionDefinitionGenerator method loadSource.

private List<StructureDefinition> loadSource() throws IOException, FHIRException {
    List<StructureDefinition> list = new ArrayList<>();
    FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    NpmPackage npm = pcm.loadPackage("hl7.fhir.core", sourceVersion.toCode());
    if (sourceVersion == FHIRVersion._4_0_0)
        context = SimpleWorkerContext.fromPackage(npm);
    else if (sourceVersion == FHIRVersion._3_0_1)
        context = SimpleWorkerContext.fromPackage(npm, new R3ToR4Loader());
    else if (sourceVersion == FHIRVersion._1_4_0)
        context = SimpleWorkerContext.fromPackage(npm, new R2016MayToR4Loader());
    else if (sourceVersion == FHIRVersion._1_0_2)
        context = SimpleWorkerContext.fromPackage(npm, new R2ToR4Loader());
    pu = new ProfileUtilities(context, null, null);
    for (String fn : npm.listResources("StructureDefinition")) {
        list.add((StructureDefinition) loadResource(npm.load("package", fn), sourceVersion));
    }
    for (StructureDefinition sd : list) if (sd.getName().equals("Extension")) {
        extbase = sd;
        extv = extbase.getSnapshot().getElement().get(extbase.getSnapshot().getElement().size() - 1);
    }
    return list;
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) R2ToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R2ToR4Loader) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) R3ToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R3ToR4Loader) R2016MayToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R2016MayToR4Loader)

Example 8 with Package

use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.

the class PackageMaintainer method check.

private void check(String ver) throws IOException {
    System.out.println("Check " + ver);
    List<String> allIds = listResources(Utilities.path(PATH, "hl7.fhir." + ver + ".examples", "package"));
    List<String> coreIds = listResources(Utilities.path(PATH, "hl7.fhir." + ver + ".core", "package"));
    for (String s : coreIds) {
        if (!allIds.contains(s)) {
            System.out.println("Core contains " + s + " but allIds doesn't");
        }
    }
    for (String s : allIds) {
        if (!coreIds.contains(s)) {
            String c = s.substring(0, s.indexOf("-"));
            if (Utilities.existsInList(c, "CodeSystem", "ValueSet", "ConceptMap", "StructureDefinition", "StructureMap", "NamingSystem", "SearchParameter", "OperationDefinition", "CapabilityStatement", "Conformance"))
                System.out.println("Examples contains " + s + " but core doesn't");
        }
    }
    strip(new File(Utilities.path(PATH, "hl7.fhir." + ver + ".core", "package")));
    strip(new File(Utilities.path(PATH, "hl7.fhir." + ver + ".expansions", "package")));
    if (!ver.equals("r2b"))
        strip(new File(Utilities.path(PATH, "hl7.fhir." + ver + ".elements", "package")));
}
Also used : TextFile(org.hl7.fhir.utilities.TextFile) File(java.io.File)

Example 9 with Package

use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.

the class CountryCodesConverter method execute.

private void execute() throws ParserConfigurationException, SAXException, IOException {
    Document src = load();
    CodeSystem cs1 = new CodeSystem();
    CodeSystem cs2 = new CodeSystem();
    CodeSystem cs3 = new CodeSystem();
    setMetadata(src, cs1, "iso3166", "urn:iso:std:iso:3166", "", "");
    setMetadata(src, cs2, "iso3166-2", "urn:iso:std:iso:3166:-2", "Part2", " Part 2");
    cs1.addProperty().setCode("canonical").setDescription("The 2 letter code that identifies the same country (so 2/3/numeric codes can be aligned)").setType(PropertyType.CODE);
    cs2.addProperty().setCode("country").setDescription("The 2 letter code that identifies the country for the subdivision").setType(PropertyType.CODE);
    for (Element e : XMLUtil.getNamedChildren(src.getDocumentElement(), "country")) {
        System.out.println(e.getAttribute("id"));
        String c2 = XMLUtil.getNamedChildText(e, "alpha-2-code");
        String c3 = XMLUtil.getNamedChildText(e, "alpha-3-code");
        String cN = XMLUtil.getNamedChildText(e, "numeric-code");
        Element n = XMLUtil.getNamedChildByAttribute(e, "short-name", "lang3code", "eng");
        if (n == null)
            n = XMLUtil.getNamedChildByAttribute(e, "short-name-upper-case", "lang3code", "eng");
        if (n == null)
            continue;
        String name = n.getTextContent();
        n = XMLUtil.getNamedChildByAttribute(e, "full-name", "lang3code", "eng");
        if (n == null)
            n = XMLUtil.getNamedChildByAttribute(e, "full-name-upper-case", "lang3code", "eng");
        if (n == null)
            n = XMLUtil.getNamedChildByAttribute(e, "short-name", "lang3code", "eng");
        if (n == null)
            n = XMLUtil.getNamedChildByAttribute(e, "short-name-upper-case", "lang3code", "eng");
        String desc = n.getTextContent();
        ConceptDefinitionComponent cc = cs1.addConcept();
        cc.setCode(c2);
        cc.setDisplay(name);
        cc.setDefinition(desc);
        poplang(e, cc);
        if (c3 != null) {
            cc = cs1.addConcept();
            cc.setCode(c3);
            cc.setDisplay(name);
            cc.setDefinition(desc);
            cc.addProperty().setCode("canonical").setValue(new CodeType(c2));
            poplang(e, cc);
        }
        if (cN != null) {
            cc = cs1.addConcept();
            cc.setCode(cN);
            cc.setDisplay(name);
            cc.setDefinition(desc);
            cc.addProperty().setCode("canonical").setValue(new CodeType(c2));
            poplang(e, cc);
        }
        for (Element sd : XMLUtil.getNamedChildren(e, "subdivision")) {
            cc = cs2.addConcept();
            cc.setCode(XMLUtil.getNamedChildText(sd, "subdivision-code"));
            Element l = XMLUtil.getNamedChild(sd, "subdivision-locale");
            cc.setDisplay(XMLUtil.getNamedChildText(l, "subdivision-locale-name"));
            cc.addProperty().setCode("country").setValue(new CodeType(c2));
        }
    }
    cs1.setCount(cs1.getConcept().size());
    cs2.setCount(cs2.getConcept().size());
    throw new Error("Needs revisiting");
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "4.0.1", "package", "CodeSstem-iso3166.json")), cs1);
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "3.0.2", "package", "CodeSstem-iso3166.json")), cs1); // format hasn't changed
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "4.0.1", "package", "CodeSstem-iso3166-2.json")), cs2);
// new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path(dest, "3.0.2", "package", "CodeSstem-iso3166-2.json")), cs2); // format hasn't changed
}
Also used : ConceptDefinitionComponent(org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent) Element(org.w3c.dom.Element) CodeType(org.hl7.fhir.r4.model.CodeType) Document(org.w3c.dom.Document) CodeSystem(org.hl7.fhir.r4.model.CodeSystem)

Example 10 with Package

use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.

the class PackagePreparer method main.

public static void main(String[] args) {
    for (File f : new File("C:\\work\\fhirserver\\resources\\mihin").listFiles()) {
        try {
            org.hl7.fhir.dstu3.model.Resource r = new org.hl7.fhir.dstu3.formats.JsonParser().parse(new FileInputStream(f));
            if (r instanceof Bundle) {
                Bundle b = (Bundle) r;
                for (BundleEntryComponent be : b.getEntry()) {
                    try {
                        org.hl7.fhir.r4.model.Resource r4 = VersionConvertorFactory_30_40.convertResource(be.getResource());
                        if (r4.getId().startsWith(r4.fhirType() + "-"))
                            be.getResource().setId(r4.getId().substring(r4.fhirType().length() + 1));
                        if (be.getResource().hasId())
                            new org.hl7.fhir.r4.formats.JsonParser().compose(new FileOutputStream(Utilities.path("C:\\work\\fhirserver\\resources\\fhir.test.data\\3.5.0\\package", be.getResource().fhirType() + "-" + be.getResource().getId() + ".json")), r4);
                        else
                            System.out.println(f.getName() + " bundle entry has no id");
                    } catch (Exception e) {
                        System.out.println(f.getName() + ": " + e.getMessage());
                    }
                }
            } else if (r.hasId())
                new org.hl7.fhir.r4.formats.JsonParser().compose(new FileOutputStream(Utilities.path(Utilities.getDirectoryForFile(f.getAbsolutePath()), r.fhirType() + "-" + r.getId() + ".json")), VersionConvertorFactory_30_40.convertResource(r));
            else
                System.out.println(f.getName() + " has no id");
        } catch (Exception e) {
            System.out.println(f.getName() + ": " + e.getMessage());
            e.printStackTrace();
        }
    }
    System.out.println("Completed OK");
}
Also used : Bundle(org.hl7.fhir.dstu3.model.Bundle) FileInputStream(java.io.FileInputStream) BundleEntryComponent(org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

File (java.io.File)25 FHIRException (org.hl7.fhir.exceptions.FHIRException)22 TextFile (org.hl7.fhir.utilities.TextFile)22 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)15 JsonObject (com.google.gson.JsonObject)12 FileNotFoundException (java.io.FileNotFoundException)11 FileInputStream (java.io.FileInputStream)9 IniFile (org.hl7.fhir.utilities.IniFile)9 FilesystemPackageCacheManager (org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager)9 ParseException (java.text.ParseException)8 HashMap (java.util.HashMap)7 Gson (com.google.gson.Gson)6 GsonBuilder (com.google.gson.GsonBuilder)6 TarArchiveEntry (org.apache.commons.compress.archivers.tar.TarArchiveEntry)6 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)6 JsonElement (com.google.gson.JsonElement)5 FileOutputStream (java.io.FileOutputStream)5 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)5 CSFile (org.hl7.fhir.utilities.CSFile)5