Search in sources :

Example 61 with SearchParameter

use of org.hl7.fhir.r4.model.SearchParameter in project org.hl7.fhir.core by hapifhir.

the class BaseWorkerContext method fetchResourceWithException.

@SuppressWarnings("unchecked")
public <T extends Resource> T fetchResourceWithException(Class<T> class_, String uri, String version, CanonicalResource source) throws FHIRException {
    if (uri == null) {
        return null;
    }
    if (class_ == StructureDefinition.class) {
        uri = ProfileUtilities.sdNs(uri, getOverrideVersionNs());
    }
    synchronized (lock) {
        if (uri.contains("|")) {
            version = uri.substring(uri.lastIndexOf("|") + 1);
            uri = uri.substring(0, uri.lastIndexOf("|"));
        }
        if (uri.contains("#")) {
            uri = uri.substring(0, uri.indexOf("#"));
        }
        if (class_ == Resource.class || class_ == null) {
            if (structures.has(uri)) {
                return (T) structures.get(uri, version);
            }
            if (guides.has(uri)) {
                return (T) guides.get(uri, version);
            }
            if (capstmts.has(uri)) {
                return (T) capstmts.get(uri, version);
            }
            if (measures.has(uri)) {
                return (T) measures.get(uri, version);
            }
            if (libraries.has(uri)) {
                return (T) libraries.get(uri, version);
            }
            if (valueSets.has(uri)) {
                return (T) valueSets.get(uri, version);
            }
            if (codeSystems.has(uri)) {
                return (T) codeSystems.get(uri, version);
            }
            if (operations.has(uri)) {
                return (T) operations.get(uri, version);
            }
            if (searchParameters.has(uri)) {
                return (T) searchParameters.get(uri, version);
            }
            if (plans.has(uri)) {
                return (T) plans.get(uri, version);
            }
            if (maps.has(uri)) {
                return (T) maps.get(uri, version);
            }
            if (transforms.has(uri)) {
                return (T) transforms.get(uri, version);
            }
            if (questionnaires.has(uri)) {
                return (T) questionnaires.get(uri, version);
            }
            if (uri.matches(Constants.URI_REGEX) && !uri.contains("ValueSet")) {
                return null;
            }
            // it might be a special URL.
            if (Utilities.isAbsoluteUrl(uri) || uri.startsWith("ValueSet/")) {
                // findTxValueSet(uri);
                Resource res = null;
                if (res != null) {
                    return (T) res;
                }
            }
            for (Map<String, ResourceProxy> rt : allResourcesById.values()) {
                for (ResourceProxy r : rt.values()) {
                    if (uri.equals(r.getUrl())) {
                        if (version == null || version == r.getResource().getMeta().getVersionId()) {
                            return (T) r.getResource();
                        }
                    }
                }
            }
            return null;
        } else if (class_ == ImplementationGuide.class) {
            return (T) guides.get(uri, version);
        } else if (class_ == CapabilityStatement.class) {
            return (T) capstmts.get(uri, version);
        } else if (class_ == Measure.class) {
            return (T) measures.get(uri, version);
        } else if (class_ == Library.class) {
            return (T) libraries.get(uri, version);
        } else if (class_ == StructureDefinition.class) {
            return (T) structures.get(uri, version);
        } else if (class_ == StructureMap.class) {
            return (T) transforms.get(uri, version);
        } else if (class_ == ValueSet.class) {
            return (T) valueSets.get(uri, version);
        } else if (class_ == CodeSystem.class) {
            return (T) codeSystems.get(uri, version);
        } else if (class_ == ConceptMap.class) {
            return (T) maps.get(uri, version);
        } else if (class_ == PlanDefinition.class) {
            return (T) plans.get(uri, version);
        } else if (class_ == OperationDefinition.class) {
            OperationDefinition od = operations.get(uri, version);
            return (T) od;
        } else if (class_ == Questionnaire.class) {
            return (T) questionnaires.get(uri, version);
        } else if (class_ == SearchParameter.class) {
            SearchParameter res = searchParameters.get(uri, version);
            return (T) res;
        }
        if (class_ == CodeSystem.class && codeSystems.has(uri)) {
            return (T) codeSystems.get(uri, version);
        }
        if (class_ == ValueSet.class && valueSets.has(uri)) {
            return (T) valueSets.get(uri, version);
        }
        if (class_ == Questionnaire.class) {
            return (T) questionnaires.get(uri, version);
        }
        if (supportedCodeSystems.contains(uri)) {
            return null;
        }
        throw new FHIRException(formatMessage(I18nConstants.NOT_DONE_YET_CANT_FETCH_, uri));
    }
}
Also used : ImplementationGuide(org.hl7.fhir.r4b.model.ImplementationGuide) CanonicalResource(org.hl7.fhir.r4b.model.CanonicalResource) Resource(org.hl7.fhir.r4b.model.Resource) CodeSystem(org.hl7.fhir.r4b.model.CodeSystem) FHIRException(org.hl7.fhir.exceptions.FHIRException) CanonicalResourceProxy(org.hl7.fhir.r4b.context.CanonicalResourceManager.CanonicalResourceProxy) ResourceProxy(org.hl7.fhir.r4b.context.BaseWorkerContext.ResourceProxy) StructureDefinition(org.hl7.fhir.r4b.model.StructureDefinition) Measure(org.hl7.fhir.r4b.model.Measure) ConceptMap(org.hl7.fhir.r4b.model.ConceptMap) SearchParameter(org.hl7.fhir.r4b.model.SearchParameter) ValueSet(org.hl7.fhir.r4b.model.ValueSet) OperationDefinition(org.hl7.fhir.r4b.model.OperationDefinition)

Example 62 with SearchParameter

use of org.hl7.fhir.r4.model.SearchParameter 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 63 with SearchParameter

use of org.hl7.fhir.r4.model.SearchParameter in project org.hl7.fhir.core by hapifhir.

the class SearchParameterValidator method validateSearchParameter.

public void validateSearchParameter(List<ValidationMessage> errors, Element cs, NodeStack stack) {
    String url = cs.getNamedChildValue("url");
    String master = cs.getNamedChildValue("derivedFrom");
    if (!Utilities.noString(master)) {
        SearchParameter sp = context.fetchResource(SearchParameter.class, master);
        if (warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), sp != null, I18nConstants.SEARCHPARAMETER_NOTFOUND, master)) {
            // base must be in the master list of base
            List<Element> bl = cs.getChildren("base");
            for (Element b : bl) {
                rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), sp.hasBase(b.primitiveValue()) || sp.hasBase("Resource"), I18nConstants.SEARCHPARAMETER_BASE_WRONG, master, b.primitiveValue());
            }
            rule(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), !cs.hasChild("type") || sp.getType().toCode().equals(cs.getNamedChildValue("type")), I18nConstants.SEARCHPARAMETER_TYPE_WRONG, master, sp.getType().toCode(), cs.getNamedChildValue("type"));
            if (sp.hasExpression() && cs.hasChild("expression") && !sp.getExpression().equals(cs.getNamedChildValue("expression"))) {
                List<String> bases = new ArrayList<>();
                for (Element b : cs.getChildren("base")) {
                    bases.add(b.primitiveValue());
                }
                String expThis = canonicalise(cs.getNamedChildValue("expression"), bases);
                String expOther = canonicalise(sp.getExpression(), bases);
                warning(errors, IssueType.BUSINESSRULE, stack.getLiteralPath(), expThis.equals(expOther), I18nConstants.SEARCHPARAMETER_EXP_WRONG, master, sp.getExpression(), cs.getNamedChildValue("expression"));
            }
        // todo: check compositions
        }
    }
}
Also used : Element(org.hl7.fhir.r5.elementmodel.Element) ArrayList(java.util.ArrayList) SearchParameter(org.hl7.fhir.r5.model.SearchParameter)

Example 64 with SearchParameter

use of org.hl7.fhir.r4.model.SearchParameter in project org.hl7.fhir.core by hapifhir.

the class GraphQLSchemaGenerator method generateConnectionAccess.

private void generateConnectionAccess(BufferedWriter writer, List<SearchParameter> parameters, String name) throws IOException {
    writer.write("type " + name + "ConnectionType {\r\n");
    writer.write("  " + name + "Conection(");
    param(writer, "_filter", "String", false, false);
    for (SearchParameter sp : parameters) param(writer, sp.getName().replace("-", "_"), getGqlname(sp.getType().toCode()), true, true);
    param(writer, "_sort", "String", false, true);
    param(writer, "_count", "Int", false, true);
    param(writer, "_cursor", "String", false, true);
    writer.write(") : " + name + "Connection\r\n");
    writer.write("}\r\n");
    writer.write("\r\n");
    writer.write("type " + name + "Connection {\r\n");
    writer.write("  count : Int\r\n");
    writer.write("  offset : Int\r\n");
    writer.write("  pagesize : Int\r\n");
    writer.write("  first : ID\r\n");
    writer.write("  previous : ID\r\n");
    writer.write("  next : ID\r\n");
    writer.write("  last : ID\r\n");
    writer.write("  edges : [" + name + "Edge]\r\n");
    writer.write("}\r\n");
    writer.write("\r\n");
    writer.write("type " + name + "Edge {\r\n");
    writer.write("  mode : String\r\n");
    writer.write("  score : Float\r\n");
    writer.write("  resource : " + name + "\r\n");
    writer.write("}\r\n");
    writer.write("\r\n");
}
Also used : SearchParameter(org.hl7.fhir.r4.model.SearchParameter)

Example 65 with SearchParameter

use of org.hl7.fhir.r4.model.SearchParameter in project org.hl7.fhir.core by hapifhir.

the class TurtleTests method test_searchparameter_example_extension.

@Test
public void test_searchparameter_example_extension() throws FileNotFoundException, IOException, Exception {
    System.out.println("searchparameter-example-extension.ttl");
    new Turtle().parse(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\searchparameter-example-extension.ttl"));
}
Also used : Turtle(org.hl7.fhir.dstu3.utils.formats.Turtle) Test(org.junit.jupiter.api.Test)

Aggregations

SearchParameter (org.hl7.fhir.r5.model.SearchParameter)32 FHIRException (org.hl7.fhir.exceptions.FHIRException)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)13 ArrayList (java.util.ArrayList)12 File (java.io.File)9 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)9 SearchParameter (org.hl7.fhir.r4b.model.SearchParameter)9 CodeType (org.hl7.fhir.r5.model.CodeType)9 HashSet (java.util.HashSet)8 FileOutputStream (java.io.FileOutputStream)7 XmlParser (org.hl7.fhir.r5.formats.XmlParser)7 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 SearchParameterDefn (org.hl7.fhir.definitions.model.SearchParameterDefn)6 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)6 ContactPoint (org.hl7.fhir.r5.model.ContactPoint)6 ImplementationGuide (org.hl7.fhir.r5.model.ImplementationGuide)6 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)6 ConstraintStructure (org.hl7.fhir.definitions.model.ConstraintStructure)5 Example (org.hl7.fhir.definitions.model.Example)5