use of org.hl7.cql.model.SearchType in project kindling by HL7.
the class OldSpreadsheetParser method readSearchParams.
private void readSearchParams(ResourceDefn root2, Sheet sheet, boolean forProfile) throws Exception {
if (sheet != null) {
for (int row = 0; row < sheet.rows.size(); row++) {
if (!sheet.hasColumn(row, "Name"))
throw new Exception("Search Param has no name " + getLocation(row));
String n = sheet.getColumn(row, "Name");
if (!n.startsWith("!")) {
if (!sheet.hasColumn(row, "Type"))
throw new Exception("Search Param " + root2.getName() + "/" + n + " has no type " + getLocation(row));
if (n.endsWith("-before") || n.endsWith("-after"))
throw new Exception("Search Param " + root2.getName() + "/" + n + " includes relative time " + getLocation(row));
if (root2.getSearchParams().containsKey(n))
throw new Exception("Search Param " + root2.getName() + "/" + n + ": duplicate name " + getLocation(row));
String d = sheet.getColumn(row, "Description");
SearchType t = readSearchType(sheet.getColumn(row, "Type"), row);
SearchParameter.XPathUsageType pu = readSearchXPathUsage(sheet.getColumn(row, "Path Usage"), row);
if (Utilities.noString(sheet.getColumn(row, "Path")) && !root2.getName().equals("Resource") && !root2.getName().equals("DomainResource"))
throw new Exception("Search Param " + root2.getName() + "/" + n + " has no path at " + getLocation(row));
SearchParameterDefn sp = null;
if (t == SearchType.composite) {
List<CompositeDefinition> pn = new ArrayList<CompositeDefinition>();
if (Utilities.noString(d))
throw new Exception("Search Param " + root2.getName() + "/" + n + " has no description " + getLocation(row));
String[] pl = sheet.getColumn(row, "Path").split("\\&");
String[] pe = sheet.getColumn(row, "Expression").split("\\;");
if (pe.length != pl.length + 1)
throw new Exception("Composite Search Param " + root2.getName() + "/" + n + " needs expressions " + getLocation(row));
int i = 0;
for (String pi : pl) {
String p = pi.trim();
i++;
String e = pe[i].trim();
if (!root2.getSearchParams().containsKey(p)) {
boolean found = false;
if (p.endsWith("[x]"))
for (String pan : root2.getSearchParams().keySet()) {
if (pan.startsWith(p.substring(0, p.length() - 3)))
found = true;
}
if (!found)
throw new Exception("Composite Search Param " + root2.getName() + "/" + n + " refers to an unknown component " + p + " at " + getLocation(row));
}
pn.add(new CompositeDefinition(p, e));
}
StandardsStatus ss = root2.getStatus();
if (!Utilities.noString(sheet.getColumn(row, "Standards-Status")))
ss = StandardsStatus.fromCode(sheet.getColumn(row, "Standards-Status"));
sp = new SearchParameterDefn(n, d, t, pu, ss);
sp.setExpression(pe[0].trim());
sp.getComposites().addAll(pn);
} else {
List<String> pn = new ArrayList<String>();
String xp = sheet.getColumn(row, "XPath");
String[] pl = sheet.getColumn(row, "Path").split("\\|");
boolean hierarchy = false;
for (String pi : pl) {
String p = pi.trim();
ElementDefn e = null;
if (!Utilities.noString(p) && !p.startsWith("!") && !p.startsWith("Extension{") && definitions != null) {
e = root2.getRoot().getElementForPath(trimIndexes(p), definitions, "search param", true, true);
}
if (e != null && e.hasHierarchy() && e.getHierarchy())
hierarchy = true;
if (Utilities.noString(d) && e != null)
d = e.getShortDefn();
if (p.startsWith("Extension(")) {
String url = extractExtensionUrl(p);
StructureDefinition ex = context.fetchResource(StructureDefinition.class, url);
if (ex == null)
throw new Exception("Search Param " + root2.getName() + "/" + n + " refers to unknown extension '" + url + "' " + getLocation(row));
if (Utilities.noString(d))
d = ex.getDescription();
pn.add(p);
}
if (d == null)
throw new Exception("Search Param " + root2.getName() + "/" + n + " has no description " + getLocation(row));
if (e != null)
pn.add(p);
if (t == SearchType.reference) {
if (e == null && !forProfile && !sheet.hasColumn(row, "Target Types"))
throw new Exception("Search Param " + root2.getName() + "/" + n + " of type reference has wrong path '" + p + "' at " + getLocation(row));
if (!forProfile && e != null && (!e.hasType("Reference")) && (!e.hasType("canonical")) && (!e.hasType("Resource")))
throw new Exception("Search Param " + root2.getName() + "/" + n + " wrong type. The search type is reference, but the element type is " + e.typeCode());
} else {
if (e != null && e.hasOnlyType("Reference"))
throw new Exception("Search Param " + root2.getName() + "/" + n + " wrong type. The search type is " + t.toString() + ", but the element type is " + e.typeCode());
if (t == SearchType.uri) {
if (e != null && !(e.typeCode().equals("uri") || e.typeCode().equals("url") || e.typeCode().equals("oid") || e.typeCode().startsWith("canonical(")))
throw new Exception("Search Param " + root2.getName() + "/" + n + " wrong type. The search type is " + t.toString() + ", but the element type is " + e.typeCode());
} else {
if (e != null && e.typeCode().equals("uri"))
throw new Exception("Search Param " + root2.getName() + "/" + n + " wrong type. The search type is " + t.toString() + ", but the element type is " + e.typeCode());
}
}
}
if (!forProfile && t == SearchType.reference && pn.size() == 0 && !sheet.hasColumn(row, "Target Types"))
throw new Exception("Search Param " + root2.getName() + "/" + n + " of type reference has no path(s) " + getLocation(row));
StandardsStatus ss = root2.getStatus();
if (!Utilities.noString(sheet.getColumn(row, "Standards-Status")))
ss = StandardsStatus.fromCode(sheet.getColumn(row, "Standards-Status"));
sp = new SearchParameterDefn(n, d, t, pu, ss);
sp.getPaths().addAll(pn);
if (!Utilities.noString(xp))
sp.setXPath(xp);
if (!Utilities.noString(sheet.getColumn(row, "Expression")))
sp.setExpression(sheet.getColumn(row, "Expression"));
if (!Utilities.noString(sheet.getColumn(row, "Target Types"))) {
sp.setManualTypes(sheet.getColumn(row, "Target Types").split("\\,"));
}
sp.setHierarchy(hierarchy);
CommonSearchParameter csp = definitions.getCommonSearchParameters().get(root2.getName() + "::" + n);
if (csp != null)
for (String s : csp.getResources()) {
if (!root2.getName().equals(s))
sp.getOtherResources().add(s);
}
}
root2.getSearchParams().put(n, sp);
}
}
}
}
use of org.hl7.cql.model.SearchType in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeOperationDefinitionOperationDefinitionParameterComponent.
protected void composeOperationDefinitionOperationDefinitionParameterComponent(Complex parent, String parentType, String name, OperationDefinition.OperationDefinitionParameterComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "parameter", name, element, index);
if (element.hasNameElement())
composeCode(t, "OperationDefinition", "name", element.getNameElement(), -1);
if (element.hasUseElement())
composeEnum(t, "OperationDefinition", "use", element.getUseElement(), -1);
if (element.hasMinElement())
composeInteger(t, "OperationDefinition", "min", element.getMinElement(), -1);
if (element.hasMaxElement())
composeString(t, "OperationDefinition", "max", element.getMaxElement(), -1);
if (element.hasDocumentationElement())
composeString(t, "OperationDefinition", "documentation", element.getDocumentationElement(), -1);
if (element.hasTypeElement())
composeCode(t, "OperationDefinition", "type", element.getTypeElement(), -1);
if (element.hasSearchTypeElement())
composeEnum(t, "OperationDefinition", "searchType", element.getSearchTypeElement(), -1);
if (element.hasProfile())
composeReference(t, "OperationDefinition", "profile", element.getProfile(), -1);
if (element.hasBinding())
composeOperationDefinitionOperationDefinitionParameterBindingComponent(t, "OperationDefinition", "binding", element.getBinding(), -1);
for (int i = 0; i < element.getPart().size(); i++) composeOperationDefinitionOperationDefinitionParameterComponent(t, "OperationDefinition", "part", element.getPart().get(i), i);
}
use of org.hl7.cql.model.SearchType in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeOperationDefinitionOperationDefinitionParameterComponent.
protected void composeOperationDefinitionOperationDefinitionParameterComponent(Complex parent, String parentType, String name, OperationDefinition.OperationDefinitionParameterComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "parameter", name, element, index);
if (element.hasNameElement())
composeCode(t, "OperationDefinition", "name", element.getNameElement(), -1);
if (element.hasUseElement())
composeEnum(t, "OperationDefinition", "use", element.getUseElement(), -1);
if (element.hasMinElement())
composeInteger(t, "OperationDefinition", "min", element.getMinElement(), -1);
if (element.hasMaxElement())
composeString(t, "OperationDefinition", "max", element.getMaxElement(), -1);
if (element.hasDocumentationElement())
composeString(t, "OperationDefinition", "documentation", element.getDocumentationElement(), -1);
if (element.hasTypeElement())
composeCode(t, "OperationDefinition", "type", element.getTypeElement(), -1);
for (int i = 0; i < element.getTargetProfile().size(); i++) composeCanonical(t, "OperationDefinition", "targetProfile", element.getTargetProfile().get(i), i);
if (element.hasSearchTypeElement())
composeEnum(t, "OperationDefinition", "searchType", element.getSearchTypeElement(), -1);
if (element.hasBinding())
composeOperationDefinitionOperationDefinitionParameterBindingComponent(t, "OperationDefinition", "binding", element.getBinding(), -1);
for (int i = 0; i < element.getReferencedFrom().size(); i++) composeOperationDefinitionOperationDefinitionParameterReferencedFromComponent(t, "OperationDefinition", "referencedFrom", element.getReferencedFrom().get(i), i);
for (int i = 0; i < element.getPart().size(); i++) composeOperationDefinitionOperationDefinitionParameterComponent(t, "OperationDefinition", "part", element.getPart().get(i), i);
}
use of org.hl7.cql.model.SearchType in project clinical_quality_language by cqframework.
the class ElmDataRequirement method applyJoinRequirementTo.
private void applyJoinRequirementTo(ElmJoinRequirement joinRequirement, Retrieve retrieve, ElmRequirementsContext context, ElmQueryRequirement queryRequirements) {
ElmDataRequirement leftRequirement = queryRequirements.getDataRequirement(joinRequirement.getLeftProperty().getSource());
ElmDataRequirement rightRequirement = queryRequirements.getDataRequirement(joinRequirement.getRightProperty().getSource());
if (leftRequirement != null && rightRequirement != null) {
Retrieve leftRetrieve = leftRequirement.getRetrieve();
Retrieve rightRetrieve = rightRequirement.getRetrieve();
// Only report include possibility if the retrieves can both be tied to the data model
if (leftRetrieve.getDataType() != null && rightRetrieve.getDataType() != null) {
ClassType leftRetrieveType = getRetrieveType(context, leftRetrieve);
ClassType rightRetrieveType = getRetrieveType(context, rightRetrieve);
if (leftRetrieveType != null && rightRetrieveType != null) {
SearchType leftSearch;
SearchType rightSearch;
for (SearchType search : leftRetrieveType.getSearches()) {
if (joinRequirement.getLeftProperty().getProperty().getPath().startsWith(search.getPath())) {
if (search.getType().isCompatibleWith(rightRetrieveType)) {
leftSearch = search;
break;
}
}
}
for (SearchType search : rightRetrieveType.getSearches()) {
if (joinRequirement.getRightProperty().getProperty().getPath().startsWith(search.getPath())) {
if (search.getType().isCompatibleWith(leftRetrieveType)) {
rightSearch = search;
break;
}
}
}
// Search from the model info should be used to inform the selection, but will in general resolve to multiple choices
// May be a choice better left to the capabilityStatement-informed planning phase anyway
}
// In the absence of search information, either of these formulations is correct, favor primary query sources over withs
if (leftRetrieve.getLocalId() == null) {
leftRetrieve.setLocalId(context.generateLocalId());
}
if (rightRetrieve.getLocalId() == null) {
rightRetrieve.setLocalId(context.generateLocalId());
}
if (rightRequirement.getQuerySource() instanceof With) {
leftRetrieve.getInclude().add(new IncludeElement().withIncludeFrom(rightRetrieve.getLocalId()).withRelatedDataType(rightRetrieve.getDataType()).withRelatedProperty(joinRequirement.getLeftProperty().getProperty().getPath()).withIsReverse(false));
rightRetrieve.setIncludedIn(leftRetrieve.getLocalId());
} else {
rightRetrieve.getInclude().add(new IncludeElement().withIncludeFrom(leftRetrieve.getLocalId()).withRelatedDataType(leftRetrieve.getDataType()).withRelatedProperty(joinRequirement.getRightProperty().getProperty().getPath()).withIsReverse(false));
leftRetrieve.setIncludedIn(rightRetrieve.getLocalId());
}
}
}
}
use of org.hl7.cql.model.SearchType in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeOperationDefinitionOperationDefinitionParameterComponent.
protected void composeOperationDefinitionOperationDefinitionParameterComponent(Complex parent, String parentType, String name, OperationDefinition.OperationDefinitionParameterComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "parameter", name, element, index);
if (element.hasNameElement())
composeCode(t, "OperationDefinition", "name", element.getNameElement(), -1);
if (element.hasUseElement())
composeEnum(t, "OperationDefinition", "use", element.getUseElement(), -1);
if (element.hasMinElement())
composeInteger(t, "OperationDefinition", "min", element.getMinElement(), -1);
if (element.hasMaxElement())
composeString(t, "OperationDefinition", "max", element.getMaxElement(), -1);
if (element.hasDocumentationElement())
composeString(t, "OperationDefinition", "documentation", element.getDocumentationElement(), -1);
if (element.hasTypeElement())
composeCode(t, "OperationDefinition", "type", element.getTypeElement(), -1);
if (element.hasSearchTypeElement())
composeEnum(t, "OperationDefinition", "searchType", element.getSearchTypeElement(), -1);
if (element.hasProfile())
composeReference(t, "OperationDefinition", "profile", element.getProfile(), -1);
if (element.hasBinding())
composeOperationDefinitionOperationDefinitionParameterBindingComponent(t, "OperationDefinition", "binding", element.getBinding(), -1);
for (int i = 0; i < element.getPart().size(); i++) composeOperationDefinitionOperationDefinitionParameterComponent(t, "OperationDefinition", "part", element.getPart().get(i), i);
}
Aggregations