use of org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.
the class ParametersRenderer method params.
private void params(XhtmlNode tbl, List<ParametersParameterComponent> list, int indent) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome {
for (ParametersParameterComponent p : list) {
XhtmlNode tr = tbl.tr();
XhtmlNode td = tr.td();
for (int i = 0; i < indent; i++) {
td.tx(XhtmlNode.NBSP);
}
td.tx(p.getName());
if (p.hasValue()) {
render(tr.td(), p.getValue());
} else if (p.hasResource()) {
Resource r = p.getResource();
td = tr.td();
XhtmlNode para = td.para();
para.tx(r.fhirType() + "/" + r.getId());
para.an(r.fhirType() + "_" + r.getId()).tx(" ");
ResourceRenderer rr = RendererFactory.factory(r, context);
rr.render(td, r);
} else if (p.hasPart()) {
tr.td();
params(tbl, p.getPart(), 1);
}
}
}
use of org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.
the class Parameters method copy.
public Parameters copy() {
Parameters dst = new Parameters();
copyValues(dst);
if (parameter != null) {
dst.parameter = new ArrayList<ParametersParameterComponent>();
for (ParametersParameterComponent i : parameter) dst.parameter.add(i.copy());
}
;
return dst;
}
use of org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.
the class FHIRToolingClient method operateType.
public <T extends Resource> Parameters operateType(Class<T> resourceClass, String name, Parameters params) {
boolean complex = false;
for (ParametersParameterComponent p : params.getParameter()) complex = complex || !(p.getValue() instanceof PrimitiveType);
String ps = "";
try {
if (!complex)
for (ParametersParameterComponent p : params.getParameter()) if (p.getValue() instanceof PrimitiveType)
ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue()) + "&";
ResourceRequest<T> result;
URI url = resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps);
if (complex) {
byte[] body = ByteUtils.resourceToByteArray(params, false, isJson(getPreferredResourceFormat()));
result = client.issuePostRequest(url, body, getPreferredResourceFormat(), generateHeaders(), "POST " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
} else {
result = client.issueGetResourceRequest(url, getPreferredResourceFormat(), generateHeaders(), "GET " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
}
if (result.isUnsuccessfulRequest()) {
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload());
}
if (result.getPayload() instanceof Parameters) {
return (Parameters) result.getPayload();
} else {
Parameters p_out = new Parameters();
p_out.addParameter().setName("return").setResource(result.getPayload());
return p_out;
}
} catch (Exception e) {
handleException("Error performing tx4 operation '" + name + ": " + e.getMessage() + "' (parameters = \"" + ps + "\")", e);
}
return null;
}
use of org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent in project org.hl7.fhir.core by hapifhir.
the class ParametersRenderer method params.
private void params(XhtmlNode tbl, List<ParametersParameterComponent> list, int indent) throws FHIRFormatError, DefinitionException, FHIRException, IOException, EOperationOutcome {
for (ParametersParameterComponent p : list) {
XhtmlNode tr = tbl.tr();
XhtmlNode td = tr.td();
for (int i = 0; i < indent; i++) {
td.tx(XhtmlNode.NBSP);
}
td.tx(p.getName());
if (p.hasValue()) {
render(tr.td(), p.getValue());
} else if (p.hasResource()) {
Resource r = p.getResource();
td = tr.td();
XhtmlNode para = td.para();
para.tx(r.fhirType() + "/" + r.getId());
para.an(r.fhirType() + "_" + r.getId()).tx(" ");
ResourceRenderer rr = RendererFactory.factory(r, context);
rr.render(td, r);
} else if (p.hasPart()) {
tr.td();
params(tbl, p.getPart(), 1);
}
}
}
use of org.hl7.fhir.r4b.model.Parameters.ParametersParameterComponent in project CRD by HL7-DaVinci.
the class QuestionnairePackageOperation method execute.
/*
* Do the work retrieving all of the Questionnaire, Library and Valueset Resources.
*/
public String execute(String resourceString) {
Parameters outputParameters = new Parameters();
IBaseResource resource = null;
try {
resource = org.hl7.davinci.r4.Utilities.parseFhirData(resourceString);
} catch (DataFormatException exception) {
logger.error("Failed to process input parameters: " + exception.getMessage());
return null;
}
if (resource.fhirType().equalsIgnoreCase("Parameters")) {
Parameters parameters = (Parameters) resource;
// TODO: handle multiple FHIR Coverage Resources
Coverage coverage = (Coverage) getResource(parameters, "coverage");
// list of all of the orders
Bundle orders = getAllResources(parameters, "order");
if (coverage == null || orders.isEmpty()) {
logger.error("Failed to find order or coverage within parameters");
return null;
}
// create a single new bundle for all of the resources
Bundle completeBundle = new Bundle();
// list of items in bundle to avoid duplicates
List<String> bundleContents = new ArrayList<>();
// process the orders to find the topics
FhirBundleProcessor fhirBundleProcessor = new FhirBundleProcessor(fileStore, baseUrl);
fhirBundleProcessor.processDeviceRequests(orders);
fhirBundleProcessor.processMedicationRequests(orders);
fhirBundleProcessor.processServiceRequests(orders);
fhirBundleProcessor.processMedicationDispenses(orders);
List<String> topics = createTopicList(fhirBundleProcessor);
for (String topic : topics) {
logger.info("--> process topic: " + topic);
// get all of the Quesionnaires for the topic
Bundle bundle = fileStore.getFhirResourcesByTopicAsFhirBundle("R4", "Questionnaire", topic.toLowerCase(), baseUrl);
List<BundleEntryComponent> bundleEntries = bundle.getEntry();
for (BundleEntryComponent entry : bundleEntries) {
addResourceToBundle(entry.getResource(), bundleContents, completeBundle);
if (entry.getResource().fhirType().equalsIgnoreCase("Questionnaire")) {
Questionnaire questionnaire = (Questionnaire) entry.getResource();
List<Extension> extensions = questionnaire.getExtension();
for (Extension extension : extensions) {
if (extension.getUrl().endsWith("cqf-library")) {
CanonicalType data = (CanonicalType) extension.getValue();
String url = data.asStringValue();
Resource libraryResource = null;
// look in the map and retrieve it instead of looking it up on disk if found
if (resources.containsKey(url)) {
libraryResource = resources.get(url);
} else {
libraryResource = fileStore.getFhirResourceByUrlAsFhirResource("R4", "Library", url, baseUrl);
resources.put(url, libraryResource);
}
if (addResourceToBundle(libraryResource, bundleContents, completeBundle)) {
// recursively add the depends-on libraries if added to bundle
addLibraryDependencies((Library) libraryResource, bundleContents, completeBundle);
}
}
}
}
}
// Questionnaires
}
// add the bundle to the output parameters if it contains any resources
if (!completeBundle.isEmpty()) {
ParametersParameterComponent parameter = new ParametersParameterComponent();
parameter.setName("return");
parameter.setResource(completeBundle);
outputParameters.addParameter(parameter);
} else {
logger.info("No matching Questionnaires found");
}
}
// if none found return null
if (outputParameters.isEmpty()) {
return null;
}
// convert the outputParameters to a string
FhirContext ctx = new org.hl7.davinci.r4.FhirComponents().getFhirContext();
IParser parser = ctx.newJsonParser().setPrettyPrint(true);
return parser.encodeResourceToString(outputParameters);
}
Aggregations