use of org.hl7.fhir.r4.model.Parameters in project kindling by HL7.
the class OldSpreadsheetParser method readOperations.
private void readOperations(List<Operation> oplist, Sheet sheet) throws Exception {
Map<String, Operation> ops = new HashMap<String, Operation>();
Map<String, OperationParameter> params = new HashMap<String, OperationParameter>();
if (sheet != null) {
for (int row = 0; row < sheet.rows.size(); row++) {
String name = sheet.getColumn(row, "Name");
String use = sheet.getColumn(row, "Use");
String doco = sheet.getColumn(row, "Documentation");
String type = sheet.getColumn(row, "Type");
List<OperationExample> examples = loadOperationExamples(sheet.getColumn(row, "Example.Request"), sheet.getColumn(row, "Example.Response"));
List<OperationExample> examples2 = loadOperationExamples(sheet.getColumn(row, "Example2.Request"), sheet.getColumn(row, "Example2.Response"));
if (name != null && !name.equals("") && !name.startsWith("!")) {
if (!name.contains(".")) {
if (!type.equals("operation"))
throw new Exception("Invalid type on operation " + type + " at " + getLocation(row));
if (!name.toLowerCase().equals(name))
throw new Exception("Invalid name on operation " + name + " - must be all lower case (use dashes) at " + getLocation(row));
params.clear();
boolean system = false;
boolean istype = false;
boolean instance = false;
for (String c : use.split("\\|")) {
c = c.trim();
if ("system".equalsIgnoreCase(c))
system = true;
else if ("resource".equalsIgnoreCase(c))
istype = true;
else if ("instance".equalsIgnoreCase(c))
instance = true;
else
throw new Exception("unknown operation use code " + c + " at " + getLocation(row));
}
Operation op = new Operation(name, system, istype, instance, sheet.getColumn(row, "Type"), sheet.getColumn(row, "Title"), doco, sheet.getColumn(row, "Footer"), examples, parseBoolean(sheet.getColumn(row, "Idempotent"), row, false));
op.setStandardsStatus(StandardsStatus.fromCode(sheet.getColumn(row, "Standards-Status")));
op.setNormativeVersion(sheet.getColumn(row, "Normative-Version"));
op.setFooter2(sheet.getColumn(row, "Footer2"));
op.setFmm(sheet.getColumn(row, "fmm"));
op.getExamples2().addAll(examples2);
oplist.add(op);
ops.put(name, op);
} else {
String context = name.substring(0, name.lastIndexOf('.'));
String pname = name.substring(name.lastIndexOf('.') + 1);
Operation operation;
List<OperationParameter> plist;
if (context.contains(".")) {
String opname = name.substring(0, name.indexOf('.'));
// inside of a tuple
if (!Utilities.noString(use))
throw new Exception("Tuple parameters: use must be blank at " + getLocation(row));
operation = ops.get(opname);
if (operation == null)
throw new Exception("Unknown Operation '" + opname + "' at " + getLocation(row));
OperationParameter param = params.get(context);
if (param == null)
throw new Exception("Tuple parameter '" + context + "' not found at " + getLocation(row));
if (!param.getFhirType().equals("Tuple"))
throw new Exception("Tuple parameter '" + context + "' type must be Tuple at " + getLocation(row));
plist = param.getParts();
} else {
if (!use.equals("in") && !use.equals("out"))
throw new Exception("Only allowed use is 'in' or 'out' at " + getLocation(row));
operation = ops.get(context);
if (operation == null)
throw new Exception("Unknown Operation '" + context + "' at " + getLocation(row));
plist = operation.getParameters();
}
String profile = sheet.getColumn(row, "Profile");
String min = sheet.getColumn(row, "Min");
String max = sheet.getColumn(row, "Max");
OperationParameter p = new OperationParameter(pname, use, doco, Integer.parseInt(min), max, type, sheet.getColumn(row, "Search Type"), profile);
String bs = sheet.getColumn(row, "Binding");
if (!Utilities.noString(bs))
p.setBs(bindings.get(bs));
plist.add(p);
params.put(name, p);
}
}
}
}
}
use of org.hl7.fhir.r4.model.Parameters in project kindling by HL7.
the class JsonLDDefinitionsGenerator method generate.
// private String genDate;
// private String version;
// private BuildWorkerContext workerContext;
public void generate(Definitions definitions, IniFile ini, String tmpResDir, String dstDir, String srcDir, FHIRVersion version, String genDate, BuildWorkerContext workerContext) throws Exception {
// this.genDate = genDate;
// this.version = version;
// this.workerContext = workerContext;
JsonObject defn = new JsonObject();
JsonObject context = new JsonObject();
defn.add("@context", context);
defn.addProperty("@id", "http://hl7.org/fhir/");
context.addProperty("fhir", "http://hl7.org/fhir/");
context.addProperty("xsd", "http://www.w3.org/2001/XMLSchema#");
// properties for primitives, helpers, format features
addProperty(context, "value", "fhir:value", "xsd:string");
addProperty(context, "decimal", "fhir:value", "xsd:decimal");
addProperty(context, "integer", "fhir:value", "xsd:integer");
if (!version.isR4B()) {
addProperty(context, "integer64", "fhir:value", "xsd:string");
}
addProperty(context, "boolean", "fhir:value", "xsd:boolean");
addProperty(context, "binary", "fhir:value", "xsd:base64Binary");
addProperty(context, "date", "fhir:value", "xsd:date");
addProperty(context, "dateTime", "fhir:value", "xsd:dateTime");
addProperty(context, "gYearMonth", "fhir:value", "xsd:gYearMonth");
addProperty(context, "gYear", "fhir:value", "xsd:gYear");
addProperty(context, "link", "fhir:link", "@id");
addProperty(context, "concept", "fhir:concept", "@id");
addProperty(context, "index", "fhir:index", "xsd:integer");
addProperty(context, "role", "fhir:nodeRole", "@id");
// elements defined in FHIR:
for (TypeRef tr : definitions.getKnownTypes()) {
if (!definitions.hasPrimitiveType(tr.getName()) && !tr.getName().equals("SimpleQuantity") && !tr.getName().equals("MoneyQuantity")) {
TypeDefn root = definitions.getElementDefn(tr.getName());
new JsonLDGenerator(definitions, workerContext, definitions.getKnownTypes()).generate(context, root, version, genDate);
}
}
List<String> names = new ArrayList<String>();
names.addAll(definitions.getResources().keySet());
names.addAll(definitions.getBaseResources().keySet());
names.add("Parameters");
Collections.sort(names);
for (String name : names) {
ResourceDefn root = definitions.getResourceByName(name);
new JsonLDGenerator(definitions, workerContext, definitions.getKnownTypes()).generate(context, root.getRoot(), version, genDate);
}
save(defn, dstDir + "fhir.jsonld");
}
use of org.hl7.fhir.r4.model.Parameters in project hl7v2-fhir-converter by LinuxForHealth.
the class Hl7DocumentReferenceFHIRConversionTest method doc_ref_has_all_fields_in_yaml.
// Note: All tests for MDM_T02 and MDM_T06 are the same. Use parameters.
@ParameterizedTest
@ValueSource(strings = { "MDM^T02", "MDM^T06" })
void doc_ref_has_all_fields_in_yaml(String segment) {
// every field covered in the yaml should be listed here
String documentReference = "MSH|^~\\&|HL7Soup|Instance1|MCM|Instance2|200911021022|Security|" + segment + "^MDM_T02|64322|P|2.6|123|456|ER|AL|USA|ASCII|en|2.6|56789^NID^UID|MCM||||\n" + "PID|1||000054321^^^MRN|||||||||||||M|CAT|||||N\n" + "PV1|1|I||||||||||||||||||||||||||||||||||||||||||\n" + "ORC|NW|||PGN001|SC|D|1|||MS|MS|||||\n" + "OBR|1||||||20170825010500|||||||||||||002|||||F||||||||\n" + "TXA|1|OP|TEXT|20180117144200|5566^PAPLast^PAPFirst^J^^MD|20180117144200|201801180346||<PHYSID>|<PHYSID>|MODL|<MESSAGEID>|4466^TRANSCLast^TRANSCFirst^J||<MESSAGEID>|This segment is for description|PA|R|AV|||||\n" + "OBX|1|SN|||||||||X";
DocumentReference report = ResourceUtils.getDocumentReference(ftv, documentReference);
assertThat(report.hasAuthenticator()).isTrue();
assertThat(report.hasAuthor()).isTrue();
assertThat(report.hasContent()).isTrue();
assertThat(report.hasContext()).isTrue();
assertThat(report.hasDate()).isTrue();
assertThat(report.hasDescription()).isTrue();
assertThat(report.hasDocStatus()).isTrue();
assertThat(report.hasId()).isTrue();
assertThat(report.hasIdentifier()).isTrue();
assertThat(report.hasMasterIdentifier()).isTrue();
assertThat(report.hasSecurityLabel()).isTrue();
assertThat(report.hasStatus()).isTrue();
assertThat(report.hasSubject()).isTrue();
assertThat(report.hasType()).isTrue();
}
use of org.hl7.fhir.r4.model.Parameters in project health-patterns by LinuxForHealth.
the class TerminologyService method translateResource.
/**
* Translates the given single FHIR resource represented as a {@link JsonNode}.
*
* @param resource the FHIR resource to translate
* @returns true if there was something to translate, false otherwise
* @throws DeIdentifierException if there is an error in the de-identification REST API or parsing the JSON
* @throws IllegalArgumentException if the given JSON does not have a 'resource' object
*/
private boolean translateResource(JsonNode resource) {
boolean translatedSomething = false;
String resourceType = getResourceType(resource);
boolean isTranslatable = StringUtils.equalsAny(resourceType, TRANSLATABLE_FHIR_TYPES);
if (!isTranslatable) {
return translatedSomething;
}
ArrayNode extensions = (ArrayNode) resource.get(EXTENSION_OBJECT);
if (extensions == null) {
return translatedSomething;
}
for (int i = 0; i < extensions.size(); i++) {
JsonNode extension = extensions.get(i);
JsonNode urlJson = extension.get(URL_OBJECT);
JsonNode valueCodeJson = extension.get(VALUE_CODE_OBJECT);
if (urlJson == null || valueCodeJson == null) {
// In order to do a translation we need both the url and the valueCode
continue;
}
// The resource's extension URL is the URL for the StructureDefinition, so we resolve a ValueSet if known
String structureDefinitionURL = urlJson.asText();
String valueSetURL = valueSetForStructureDefinition.get(structureDefinitionURL);
// and if known we check the FHIR Server's known ConceptMaps to see if there is a corresponding one
// http://4603f72b-us-south.lb.appdomain.cloud/fhir-server/api/v4/ConceptMap?_format=json&source-uri=http://hl7.org/fhir/us/core/ValueSet/birthsex
Bundle bundle = fhirClient.search().forResource(ConceptMap.class).where(ConceptMap.SOURCE_URI.hasId(valueSetURL)).returnBundle(Bundle.class).execute();
String conceptMapId;
if (!bundle.getEntry().isEmpty()) {
Resource conceptMap = bundle.getEntry().get(0).getResource();
if (bundle.getEntry().size() > 1) {
System.err.println("Found multiple ConceptMaps that will map " + valueSetURL + " for this StructureDefinition, will use the first one " + conceptMap.getId());
} else {
System.out.println("Found ConceptMap for " + valueSetURL + ": " + conceptMap.getId() + " !!");
}
conceptMapId = conceptMap.getIdElement().getIdPart();
} else {
System.out.println("Did not find ConceptMap for " + valueSetURL + "!!");
continue;
}
// "POST ${FHIR_URL}/${conceptMapID}/$translate?code=${code}&system=${valueSet}&_format=json
String valueCode = valueCodeJson.asText();
String url = String.format("%s/ConceptMap/%s/$translate?code=%s&system=%s&_format=json", fhirClient.getServerBase(), conceptMapId, valueCode, valueSetURL);
Parameters translationResponse = fhirClient.fetchResourceFromUrl(Parameters.class, url);
// This is what comes back from the server
// {
// "resourceType": "Parameters",
// "parameter": [
// {
// "name": "result",
// "valueBoolean": true
// },
// {
// "name": "match",
// "part": [
// {
// "name": "equivalence",
// "valueCode": "equivalent"
// },
// {
// "name": "concept",
// "valueCoding": {
// "system": "http://ibm.com/fhir/cdm/ValueSet/sex-assigned-at-birth",
// "code": "male",
// "display": "Male"
// }
// }
// ]
// }
// ]
// }
Coding translatedCode = null;
List<ParametersParameterComponent> parameters = translationResponse.getParameter();
for (ParametersParameterComponent parameter : parameters) {
if (parameter.getName().equals(MATCH_VALUE)) {
List<ParametersParameterComponent> parts = parameter.getPart();
for (ParametersParameterComponent part : parts) {
if (part.getName().equals(CONCEPT_VALUE)) {
try {
translatedCode = (Coding) part.getValue();
} catch (ClassCastException e) {
String jsonResponse = fhirClient.getFhirContext().newJsonParser().encodeResourceToString(translationResponse);
System.err.println("Found a ConceptMap that will map " + valueSetURL + " for this StructureDefinition, but the FHIR server returned an unknown $translate response (expected a 'valueCoding' part): " + jsonResponse);
}
}
}
}
}
if (translatedCode == null) {
String jsonResponse = fhirClient.getFhirContext().newJsonParser().encodeResourceToString(translationResponse);
System.err.println("Found a ConceptMap that will map " + valueSetURL + " for this StructureDefinition, but the FHIR server returned an unknown $translate response: " + jsonResponse);
continue;
}
System.out.printf("Found ConceptMap %s which translates (valueCode, system) = (%s, %s) for StructureDefinition %s to (valueCode, system) = (%s, %s) %n", conceptMapId, valueCode, valueSetURL, structureDefinitionURL, translatedCode.getCode(), translatedCode.getSystem());
String translatedStructuredData = valueSetForStructureDefinition.get(translatedCode.getSystem());
if (translatedStructuredData == null) {
System.err.printf("Cannot find the mapping from ValueSet '%s' to its corresponding StructureData for this translation, make sure the corresponding mappings configuration file has it.%n", translatedCode.getSystem());
continue;
}
((ObjectNode) extension).set(URL_OBJECT, JsonNodeFactory.instance.textNode(translatedStructuredData));
((ObjectNode) extension).set(VALUE_CODE_OBJECT, JsonNodeFactory.instance.textNode(translatedCode.getCode()));
translatedSomething = true;
}
return translatedSomething;
}
use of org.hl7.fhir.r4.model.Parameters in project cqf-ruler by DBCG.
the class CqlExecutionProvider method evaluate.
/**
* Evaluates a CQL expression and returns the results as a Parameters resource.
*
* @param theRequestDetails the {@link RequestDetails RequestDetails}
* @param subject ***Only Patient is supported as of now*** Subject
* for which the expression will be
* evaluated. This corresponds to the context in
* which the expression will be evaluated and is
* represented as a relative FHIR id (e.g.
* Patient/123), which establishes both the context
* and context value for the evaluation
* @param expression Expression to be evaluated. Note that this is an
* expression of CQL, not the text of a library with
* definition statements.
* @param parameters Any input parameters for the expression.
* {@link Parameters} Parameters defined in this
* input will be made available by name to the CQL
* expression. Parameter types are mapped to CQL as
* specified in the Using CQL section of the CPG
* Implementation guide. If a parameter appears more
* than once in the input Parameters resource, it is
* represented with a List in the input CQL. If a
* parameter has parts, it is represented as a Tuple
* in the input CQL.
* @param library A library to be included. The {@link Library}
* library is resolved by url and made available by
* name within the expression to be evaluated.
* @param useServerData Whether to use data from the server performing the
* evaluation. If this parameter is true (the
* default), then the operation will use data first
* from any bundles provided as parameters (through
* the data and prefetch parameters), second data
* from the server performing the operation, and
* third, data from the dataEndpoint parameter (if
* provided). If this parameter is false, the
* operation will use data first from the bundles
* provided in the data or prefetch parameters, and
* second from the dataEndpoint parameter (if
* provided).
* @param data Data to be made available to the library
* evaluation. This parameter is exclusive with the
* prefetchData parameter (i.e. either provide all
* data as a single bundle, or provide data using
* multiple bundles with prefetch descriptions).
* @param prefetchData ***Not Yet Implemented***
* @param dataEndpoint An {@link Endpoint} endpoint to use to access data
* referenced by retrieve operations in the library.
* If provided, this endpoint is used after the data
* or prefetchData bundles, and the server, if the
* useServerData parameter is true.
* @param contentEndpoint An {@link Endpoint} endpoint to use to access
* content (i.e. libraries) referenced by the
* library. If no content endpoint is supplied, the
* evaluation will attempt to retrieve content from
* the server on which the operation is being
* performed.
* @param terminologyEndpoint An {@link Endpoint} endpoint to use to access
* terminology (i.e. valuesets, codesystems, and
* membership testing) referenced by the library. If
* no terminology endpoint is supplied, the
* evaluation will attempt to use the server on which
* the operation is being performed as the
* terminology server.
* @return The result of evaluating the given expression, returned as a FHIR
* type, either a {@link Resource} resource, or a FHIR-defined type
* corresponding to the CQL return type, as defined in the Using CQL
* section of the CPG Implementation guide. If the result is a List of
* resources, the result will be a {@link Bundle} Bundle . If the result
* is a CQL system-defined or FHIR-defined type, the result is returned
* as a {@link Parameters} Parameters resource
*/
@Operation(name = "$cql")
@Description(shortDefinition = "$cql", value = "Evaluates a CQL expression and returns the results as a Parameters resource. Defined: http://build.fhir.org/ig/HL7/cqf-recommendations/OperationDefinition-cpg-cql.html", example = "$cql?expression=5*5")
public Parameters evaluate(RequestDetails theRequestDetails, @OperationParam(name = "subject", max = 1) String subject, @OperationParam(name = "expression", min = 1, max = 1) String expression, @OperationParam(name = "parameters", max = 1) Parameters parameters, @OperationParam(name = "library") List<Parameters> library, @OperationParam(name = "useServerData", max = 1) BooleanType useServerData, @OperationParam(name = "data", max = 1) Bundle data, @OperationParam(name = "prefetchData") List<Parameters> prefetchData, @OperationParam(name = "dataEndpoint", max = 1) Endpoint dataEndpoint, @OperationParam(name = "contentEndpoint", max = 1) Endpoint contentEndpoint, @OperationParam(name = "terminologyEndpoint", max = 1) Endpoint terminologyEndpoint) {
if (prefetchData != null) {
throw new NotImplementedException("prefetchData is not yet supported.");
}
if (useServerData == null) {
useServerData = new BooleanType(true);
}
List<LibraryParameter> libraryParameters = new ArrayList<>();
if (library != null) {
for (Parameters libraryParameter : library) {
String url = null;
String name = null;
for (ParametersParameterComponent param : libraryParameter.getParameter()) {
switch(param.getName()) {
case "url":
url = ((StringType) param.getValue()).asStringValue();
break;
case "name":
name = ((StringType) param.getValue()).asStringValue();
break;
default:
throw new IllegalArgumentException("Only url and name parts are allowed for Parameter: library");
}
}
if (url == null) {
throw new IllegalArgumentException("If library parameter must provide a url parameter part.");
}
libraryParameters.add(new LibraryParameter().withUrl(url).withName(name));
}
// Remove LocalLibrary from cache first...
}
VersionedIdentifier localLibraryIdentifier = new VersionedIdentifier().withId("LocalLibrary").withVersion("1.0.0");
globalLibraryCache.remove(localLibraryIdentifier);
CqlEngine engine = setupEngine(localLibraryIdentifier, expression, libraryParameters, subject, parameters, contentEndpoint, dataEndpoint, terminologyEndpoint, data, useServerData.booleanValue(), theRequestDetails);
Map<String, Object> resolvedParameters = new HashMap<String, Object>();
if (parameters != null) {
for (Parameters.ParametersParameterComponent pc : parameters.getParameter()) {
resolvedParameters.put(pc.getName(), pc.getValue());
}
}
String contextType = subject != null ? subject.substring(0, subject.lastIndexOf("/") - 1) : null;
String subjectId = subject != null ? subject.substring(0, subject.lastIndexOf("/") - 1) : null;
EvaluationResult evalResult = engine.evaluate(localLibraryIdentifier, null, Pair.of(contextType != null ? contextType : "Unspecified", subjectId == null ? "null" : subject), resolvedParameters, this.getDebugMap());
if (evalResult != null && evalResult.expressionResults != null) {
if (evalResult.expressionResults.size() > 1) {
logger.debug("Evaluation resulted in more than one expression result. ");
}
Parameters result = new Parameters();
resolveResult(theRequestDetails, evalResult, result);
return result;
}
return null;
}
Aggregations