Search in sources :

Example 56 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class ComparisonTests method test.

@ParameterizedTest(name = "{index}: id {0}")
@MethodSource("data")
public void test(String name, JsonObject content) throws Exception {
    this.content = content;
    if (content.has("use-test") && !content.get("use-test").getAsBoolean())
        return;
    if (context == null) {
        System.out.println("---- Load R5 ----------------------------------------------------------------");
        context = TestingUtilities.getSharedWorkerContext();
        FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
        NpmPackage npm = pcm.loadPackage("hl7.fhir.us.core#3.1.0");
        BaseWorkerContext bc = (BaseWorkerContext) context;
        boolean dupl = bc.isAllowLoadingDuplicates();
        bc.setAllowLoadingDuplicates(true);
        context.loadFromPackage(npm, new R4ToR5Loader(new String[] { "CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" }, new NullLoaderKnowledgeProviderR5(), context.getVersion()));
        bc.setAllowLoadingDuplicates(dupl);
    }
    if (!new File(Utilities.path("[tmp]", "comparison")).exists()) {
        System.out.println("---- Set up Output ----------------------------------------------------------");
        Utilities.createDirectory(Utilities.path("[tmp]", "comparison"));
        FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
        NpmPackage npm = pcm.loadPackage(CommonPackages.ID_PUBPACK, CommonPackages.VER_PUBPACK);
        for (String f : npm.list("other")) {
            TextFile.streamToFile(npm.load("other", f), Utilities.path("[tmp]", "comparison", f));
        }
    }
    System.out.println("---- " + name + " ----------------------------------------------------------------");
    CanonicalResource left = load("left");
    CanonicalResource right = load("right");
    ComparisonSession session = new ComparisonSession(context, context, "Comparison Tests", null);
    if (left instanceof CodeSystem && right instanceof CodeSystem) {
        CodeSystemComparer cs = new CodeSystemComparer(session);
        CodeSystemComparison csc = cs.compare((CodeSystem) left, (CodeSystem) right);
        Assertions.assertTrue(csc.getUnion().getConcept().size() > csc.getIntersection().getConcept().size());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
        String xmle = new XhtmlComposer(true).compose(cs.renderErrors(csc));
        String xml1 = new XhtmlComposer(true).compose(cs.renderMetadata(csc, "", ""));
        String xml2 = new XhtmlComposer(true).compose(cs.renderConcepts(csc, "", ""));
        TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Concepts") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
        checkOutcomes(csc.getMessages(), content);
    } else if (left instanceof ValueSet && right instanceof ValueSet) {
        ValueSetComparer cs = new ValueSetComparer(session);
        ValueSetComparison csc = cs.compare((ValueSet) left, (ValueSet) right);
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
        String xmle = new XhtmlComposer(true).compose(cs.renderErrors(csc));
        String xml1 = new XhtmlComposer(true).compose(cs.renderMetadata(csc, "", ""));
        String xml2 = new XhtmlComposer(true).compose(cs.renderCompose(csc, "", ""));
        String xml3 = new XhtmlComposer(true).compose(cs.renderExpansion(csc, "", ""));
        TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Definition") + xml2 + BREAK + hd("Expansion") + xml3 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
        checkOutcomes(csc.getMessages(), content);
    } else if (left instanceof StructureDefinition && right instanceof StructureDefinition) {
        ProfileUtilities utils = new ProfileUtilities(context, null, null);
        genSnapshot(utils, (StructureDefinition) left);
        genSnapshot(utils, (StructureDefinition) right);
        ProfileComparer pc = new ProfileComparer(session, utils, utils);
        ProfileComparison csc = pc.compare((StructureDefinition) left, (StructureDefinition) right);
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
        String xmle = new XhtmlComposer(true).compose(pc.renderErrors(csc));
        String xml1 = new XhtmlComposer(true).compose(pc.renderMetadata(csc, "", ""));
        String xml2 = new XhtmlComposer(true).compose(pc.renderStructure(csc, "", "", "http://hl7.org/fhir"));
        // String xml3 = new XhtmlComposer(true).compose(cs.renderExpansion(csc, "", ""));
        TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Structure") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
        checkOutcomes(csc.getMessages(), content);
    } else if (left instanceof CapabilityStatement && right instanceof CapabilityStatement) {
        CapabilityStatementComparer pc = new CapabilityStatementComparer(session);
        CapabilityStatementComparison csc = pc.compare((CapabilityStatement) left, (CapabilityStatement) right);
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-union.json")), csc.getUnion());
        new org.hl7.fhir.r5.formats.JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(Utilities.path("[tmp]", "comparison", name + "-intersection.json")), csc.getIntersection());
        String xmle = new XhtmlComposer(true).compose(pc.renderErrors(csc));
        String xml1 = new XhtmlComposer(true).compose(pc.renderMetadata(csc, "", ""));
        String xml2 = new XhtmlComposer(true).compose(pc.renderStatements(csc, "", ""));
        // String xml3 = new XhtmlComposer(true).compose(cs.renderExpansion(csc, "", ""));
        TextFile.stringToFile(HEADER + hd("Messages") + xmle + BREAK + hd("Metadata") + xml1 + BREAK + hd("Structure") + xml2 + FOOTER, Utilities.path("[tmp]", "comparison", name + ".html"));
        checkOutcomes(csc.getMessages(), content);
    } else {
        throw new FHIRException("Can't compare " + left.fhirType() + " to " + right.fhirType());
    }
}
Also used : ProfileComparison(org.hl7.fhir.r5.comparison.ProfileComparer.ProfileComparison) ComparisonSession(org.hl7.fhir.r5.comparison.ComparisonSession) ProfileComparer(org.hl7.fhir.r5.comparison.ProfileComparer) BaseWorkerContext(org.hl7.fhir.r5.context.BaseWorkerContext) StructureDefinition(org.hl7.fhir.r5.model.StructureDefinition) CapabilityStatementComparison(org.hl7.fhir.r5.comparison.CapabilityStatementComparer.CapabilityStatementComparison) XhtmlComposer(org.hl7.fhir.utilities.xhtml.XhtmlComposer) CapabilityStatement(org.hl7.fhir.r5.model.CapabilityStatement) CapabilityStatementComparer(org.hl7.fhir.r5.comparison.CapabilityStatementComparer) ValueSet(org.hl7.fhir.r5.model.ValueSet) JsonParser(org.hl7.fhir.r5.formats.JsonParser) FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) ValueSetComparison(org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison) CodeSystem(org.hl7.fhir.r5.model.CodeSystem) JsonParser(org.hl7.fhir.r5.formats.JsonParser) FHIRException(org.hl7.fhir.exceptions.FHIRException) CodeSystemComparer(org.hl7.fhir.r5.comparison.CodeSystemComparer) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) CodeSystemComparison(org.hl7.fhir.r5.comparison.CodeSystemComparer.CodeSystemComparison) ProfileUtilities(org.hl7.fhir.r5.conformance.ProfileUtilities) R4ToR5Loader(org.hl7.fhir.convertors.loaders.loaderR5.R4ToR5Loader) FileOutputStream(java.io.FileOutputStream) ValueSetComparer(org.hl7.fhir.r5.comparison.ValueSetComparer) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) CanonicalResource(org.hl7.fhir.r5.model.CanonicalResource) NullLoaderKnowledgeProviderR5(org.hl7.fhir.convertors.loaders.loaderR5.NullLoaderKnowledgeProviderR5) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 57 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class UTGVersionSorter method loadPackageR3.

private Map<String, CanonicalResource> loadPackageR3(String id) throws IOException {
    Map<String, CanonicalResource> res = new HashMap<>();
    if (pcm == null) {
        pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    }
    System.out.println("Load " + id);
    NpmPackage npm = pcm.loadPackage(id);
    for (PackageResourceInformation p : npm.listIndexedResources("CodeSystem", "ValueSet")) {
        CanonicalResource r = (CanonicalResource) VersionConvertorFactory_30_50.convertResource(new org.hl7.fhir.dstu3.formats.JsonParser().parse(npm.load(p)));
        res.put(r.getUrl(), r);
    }
    return res;
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) PackageResourceInformation(org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Example 58 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class UTGVersionSorter method execute.

private void execute(String source) throws IOException {
    List<CanonicalResourceAnalysis> list = new ArrayList<>();
    System.out.println("Loading UTG");
    loadFromSource(list, new File(source));
    Map<String, CanonicalResource> r2 = loadPackageR2("hl7.fhir.r2.core");
    Map<String, CanonicalResource> r3 = loadPackageR3("hl7.fhir.r3.core");
    Map<String, CanonicalResource> r4 = loadPackageR4("hl7.fhir.r4.core");
    System.out.println("Processing");
    for (CanonicalResourceAnalysis cr : list) {
        cr.analyse(r2, r3, r4);
    }
    Bundle b = (Bundle) new JsonParser().parse(new FileInputStream("C:\\work\\org.hl7.fhir.igs\\UTG\\input\\sourceOfTruth\\history\\utgrel1hx-1-0-6.json"));
    System.out.println("Summary");
    for (CanonicalResourceAnalysis cr : list) {
        System.out.println(cr.summary());
        Provenance p = new Provenance();
        b.addEntry().setResource(p).setFullUrl("http://terminology.hl7.org/fhir/Provenance/fhir-1.0.51-" + cr.getId());
        p.setId("hx-fhir-1.0.51-" + cr.getId());
        p.addTarget().setReference(cr.fhirType() + "/" + cr.getId());
        p.getOccurredPeriod().setEnd(runTime, TemporalPrecisionEnum.DAY);
        p.setRecorded(runTime);
        p.addAuthorization().getConcept().setText("Reset Version after migration to UTG").addCoding("http://terminology.hl7.org/CodeSystem/v3-ActReason", "METAMGT", null);
        p.getActivity().addCoding("http://terminology.hl7.org/CodeSystem/v3-DataOperation", "UPDATE", null);
        ProvenanceAgentComponent pa = p.addAgent();
        pa.getType().addCoding("http://terminology.hl7.org/CodeSystem/provenance-participant-type", "author", null);
        pa.getWho().setDisplay("Grahame Grieve");
        pa = p.addAgent();
        pa.getType().addCoding("http://terminology.hl7.org/CodeSystem/provenance-participant-type", "custodian", null);
        pa.getWho().setDisplay("Vocabulary WG");
        CanonicalResource res = cr.resource;
        res.setVersion(cr.recommendation);
        new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(cr.filename), res);
    }
    System.out.println();
    new JsonParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream("C:\\work\\org.hl7.fhir.igs\\UTG\\input\\sourceOfTruth\\history\\utgrel1hx-1-0-6.json"), b);
    System.out.println("Done");
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileInputStream(java.io.FileInputStream) ProvenanceAgentComponent(org.hl7.fhir.r5.model.Provenance.ProvenanceAgentComponent) FileOutputStream(java.io.FileOutputStream) File(java.io.File) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 59 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class UTGVersionSorter method loadPackageR4.

private Map<String, CanonicalResource> loadPackageR4(String id) throws IOException {
    Map<String, CanonicalResource> res = new HashMap<>();
    if (pcm == null) {
        pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    }
    System.out.println("Load " + id);
    NpmPackage npm = pcm.loadPackage(id);
    for (PackageResourceInformation p : npm.listIndexedResources("CodeSystem", "ValueSet")) {
        CanonicalResource r = (CanonicalResource) VersionConvertorFactory_40_50.convertResource(new org.hl7.fhir.r4.formats.JsonParser().parse(npm.load(p)));
        res.put(r.getUrl(), r);
    }
    return res;
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) PackageResourceInformation(org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Example 60 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class UTGVersionSorter method loadPackageR2.

private Map<String, CanonicalResource> loadPackageR2(String id) throws IOException {
    Map<String, CanonicalResource> res = new HashMap<>();
    if (pcm == null) {
        pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    }
    System.out.println("Load " + id);
    NpmPackage npm = pcm.loadPackage(id);
    for (PackageResourceInformation p : npm.listIndexedResources("CodeSystem", "ValueSet")) {
        CanonicalResource r = (CanonicalResource) VersionConvertorFactory_10_50.convertResource(new org.hl7.fhir.dstu2.formats.JsonParser().parse(npm.load(p)));
        res.put(r.getUrl(), r);
    }
    return res;
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) PackageResourceInformation(org.hl7.fhir.utilities.npm.NpmPackage.PackageResourceInformation) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)20 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)19 ArrayList (java.util.ArrayList)17 File (java.io.File)11 CanonicalResource (org.hl7.fhir.r4b.model.CanonicalResource)10 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)10 XmlParser (org.hl7.fhir.r5.formats.XmlParser)9 org.hl7.fhir.r5.model (org.hl7.fhir.r5.model)9 BundleEntryComponent (org.hl7.fhir.r5.model.Bundle.BundleEntryComponent)9 FileOutputStream (java.io.FileOutputStream)8 IOException (java.io.IOException)8 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)8 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)8 Resource (org.hl7.fhir.r5.model.Resource)8 ValueSet (org.hl7.fhir.r5.model.ValueSet)8 FileNotFoundException (java.io.FileNotFoundException)7 Resource (org.hl7.fhir.r4b.model.Resource)7 CodeSystem (org.hl7.fhir.r4b.model.CodeSystem)5 SearchParameter (org.hl7.fhir.r5.model.SearchParameter)5 FileInputStream (java.io.FileInputStream)4