use of org.hl7.fhir.r4b.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));
}
}
use of org.hl7.fhir.r4b.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());
}
}
use of org.hl7.fhir.r4b.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
}
}
}
use of org.hl7.fhir.r4b.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");
}
use of org.hl7.fhir.r4b.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"));
}
Aggregations