use of org.hl7.fhir.dstu2016may.model.OperationOutcome in project cqf-ruler by DBCG.
the class ProcessMessageProvider method processMessageBundle.
@Operation(name = "$process-message-bundle", idempotent = false)
public Bundle processMessageBundle(HttpServletRequest theServletRequest, RequestDetails theRequestDetails, @OperationParam(name = "content", min = 1, max = 1) @Description(formalDefinition = "The message to process (or, if using asynchronous messaging, it may be a response message to accept)") Bundle theMessageToProcess) {
logger.info("Validating the Bundle");
Bundle bundle = theMessageToProcess;
Boolean errorExists = false;
OperationOutcome outcome = validateBundle(errorExists, bundle);
if (!errorExists) {
IVersionSpecificBundleFactory bundleFactory = this.getFhirContext().newBundleFactory();
bundle.setId(getUUID());
bundleFactory.initializeWithBundleResource(bundle);
Bundle dafBundle = (Bundle) bundleFactory.getResourceBundle();
dafBundle.setTimestamp(new Date());
this.getDaoRegistry().getResourceDao(Bundle.class).create(dafBundle);
MessageHeader messageHeader = null;
String patientId = null;
String commId = null;
List<MessageHeader> headers = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, MessageHeader.class);
for (MessageHeader mh : headers) {
messageHeader = mh;
messageHeader.setId(getUUID());
Meta meta = messageHeader.getMeta();
meta.setLastUpdated(new Date());
messageHeader.setMeta(meta);
}
List<IBaseResource> resources = new ArrayList<>();
List<Patient> patients = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, Patient.class);
for (Patient p : patients) {
patientId = p.getId();
p.setId(p.getIdElement().toVersionless());
resources.add(p);
}
List<Bundle> bundles = BundleUtil.toListOfResourcesOfType(this.getFhirContext(), bundle, Bundle.class);
for (Bundle b : bundles) {
patientId = this.processBundle(b, theRequestDetails);
b.setId(b.getIdElement().toVersionless());
resources.add(b);
}
for (BundleEntryComponent e : bundle.getEntry()) {
Resource r = e.getResource();
if (r == null) {
continue;
}
if (r.fhirType().equals("Bundle") || r.fhirType().equals("MessageHeader") || r.fhirType().equals("Patient")) {
continue;
}
r.setId(r.getIdElement().toVersionless());
resources.add(r);
}
if (patientId != null) {
commId = constructAndSaveCommunication(patientId);
}
if (messageHeader == null) {
messageHeader = constructMessageHeaderResource();
BundleEntryComponent entryComp = new BundleEntryComponent();
entryComp.setResource(messageHeader);
dafBundle.addEntry(entryComp);
}
if (commId != null) {
List<Reference> referenceList = new ArrayList<>();
Reference commRef = new Reference();
commRef.setReference("Communication/" + commId);
referenceList.add(commRef);
messageHeader.setFocus(referenceList);
}
IVersionSpecificBundleFactory newBundleFactory = this.getFhirContext().newBundleFactory();
newBundleFactory.addResourcesToBundle(resources, BundleTypeEnum.TRANSACTION, theRequestDetails.getFhirServerBase(), null, null);
Bundle transactionBundle = (Bundle) newBundleFactory.getResourceBundle();
for (BundleEntryComponent entry : transactionBundle.getEntry()) {
UriType uri = new UriType(theRequestDetails.getFhirServerBase() + "/" + entry.getResource().fhirType() + "/" + entry.getResource().getIdElement().getIdPart());
Enumeration<HTTPVerb> method = new Enumeration<>(new HTTPVerbEnumFactory());
method.setValue(HTTPVerb.PUT);
entry.setRequest(new BundleEntryRequestComponent(method, uri));
}
@SuppressWarnings("unchecked") IFhirSystemDao<Bundle, Meta> fhirSystemDao = this.getDaoRegistry().getSystemDao();
fhirSystemDao.transaction(theRequestDetails, transactionBundle);
return dafBundle;
} else {
BundleEntryComponent entryComp = new BundleEntryComponent();
entryComp.setResource(outcome);
bundle.addEntry(entryComp);
return bundle;
}
}
use of org.hl7.fhir.dstu2016may.model.OperationOutcome in project cqf-ruler by DBCG.
the class HelloWorldProvider method hello_world.
/**
* Implements the $hello-world operation found in the
* <a href="https://www.hl7.org/fhir/clinicalreasoning-module.html">FHIR CR
* Module</a>
*
* @return a greeting
*/
@Description(shortDefinition = "returns a greeting", value = "Implements the $hello-world operation found in the <a href=\"https://www.hl7.org/fhir/clinicalreasoning-module.html\">FHIR CR Module</a>")
@Operation(idempotent = true, name = "$hello-world")
public OperationOutcome hello_world() {
OperationOutcome outcome = new OperationOutcome();
outcome.addIssue().setDiagnostics(helloWorldProperties.getMessage());
return outcome;
}
use of org.hl7.fhir.dstu2016may.model.OperationOutcome in project cqf-ruler by DBCG.
the class HelloWorldProviderIT method testHelloWorldConfig.
@Test
public void testHelloWorldConfig() {
OperationOutcome outcome = getClient().operation().onServer().named("$hello-world").withNoParameters(Parameters.class).returnResourceType(OperationOutcome.class).execute();
assertNotNull(outcome);
assertEquals("Howdy", outcome.getIssueFirstRep().getDiagnostics());
}
use of org.hl7.fhir.dstu2016may.model.OperationOutcome in project cqf-ruler by DBCG.
the class CacheValueSetsProvider method cacheValuesets.
/**
* Using basic authentication this {@link Operation Operation} will update
* any {@link ValueSet Valueset} listed given the {@link Endpoint Endpoint}
* provided.
* Any Valuesets that require expansion will be expanded.
*
* @param details the {@link RequestDetails RequestDetails}
* @param endpointId the {@link Endpoint Endpoint} id
* @param valuesets the {@link StringAndListParam list} of {@link ValueSet
* Valueset} ids
* @param userName the userName
* @param password the password
* @return the {@link OperationOutcome OperationOutcome} or the resulting
* {@link Bundle Bundle}
*/
@Description(shortDefinition = "$cache-valuesets", value = "Using basic authentication this Operation will update any Valueset listed given the Endpoint provided. Any Valuesets that require expansion will be expanded.", example = "Endpoint/example-id/$cache-valuesets?valuesets=valuesetId1&valuesets=valuesetId2&user=user&password=password")
@Operation(name = "$cache-valuesets", idempotent = true, type = Endpoint.class)
public Resource cacheValuesets(RequestDetails details, @IdParam IdType endpointId, @OperationParam(name = "valuesets") StringAndListParam valuesets, @OperationParam(name = "user") String userName, @OperationParam(name = "pass") String password) {
Endpoint endpoint = null;
try {
endpoint = this.endpointDao.read(endpointId);
if (endpoint == null) {
return createErrorOutcome("Could not find Endpoint/" + endpointId);
}
} catch (Exception e) {
return createErrorOutcome("Could not find Endpoint/" + endpointId + "\n" + e);
}
IGenericClient client = Clients.forEndpoint(ourCtx, endpoint);
if (userName != null || password != null) {
if (userName == null) {
return createErrorOutcome("Password was provided, but not a user name.");
} else if (password == null) {
return createErrorOutcome("User name was provided, but not a password.");
}
BasicAuthInterceptor basicAuth = new BasicAuthInterceptor(userName, password);
client.registerInterceptor(basicAuth);
// TODO - more advanced security like bearer tokens, etc...
}
try {
Bundle bundleToPost = new Bundle();
for (StringOrListParam params : valuesets.getValuesAsQueryTokens()) {
for (StringParam valuesetId : params.getValuesAsQueryTokens()) {
bundleToPost.addEntry().setRequest(new Bundle.BundleEntryRequestComponent().setMethod(Bundle.HTTPVerb.PUT).setUrl("ValueSet/" + valuesetId.getValue())).setResource(resolveValueSet(client, valuesetId.getValue()));
}
}
return (Resource) systemDao.transaction(details, bundleToPost);
} catch (Exception e) {
return createErrorOutcome(e.getMessage());
}
}
use of org.hl7.fhir.dstu2016may.model.OperationOutcome in project cqf-ruler by DBCG.
the class CodeSystemUpdateProvider method performCodeSystemUpdate.
public OperationOutcome performCodeSystemUpdate(List<ValueSet> valueSets) {
OperationOutcome response = new OperationOutcome();
List<String> codeSystems = new ArrayList<>();
// Possible for this to run out of memory with really large ValueSets and
// CodeSystems.
Map<String, Set<String>> codesBySystem = new HashMap<>();
for (ValueSet vs : valueSets) {
if (vs.hasCompose() && vs.getCompose().hasInclude()) {
for (ValueSet.ConceptSetComponent csc : vs.getCompose().getInclude()) {
if (!csc.hasSystem() || !csc.hasConcept()) {
continue;
}
String system = csc.getSystem();
if (!codesBySystem.containsKey(system)) {
codesBySystem.put(system, new HashSet<>());
}
Set<String> codes = codesBySystem.get(system);
codes.addAll(csc.getConcept().stream().map(ValueSet.ConceptReferenceComponent::getCode).collect(Collectors.toList()));
}
}
}
for (Map.Entry<String, Set<String>> entry : codesBySystem.entrySet()) {
String system = entry.getKey();
CodeSystem codeSystem = getCodeSystemByUrl(system);
updateCodeSystem(codeSystem.setUrl(system), getUnionDistinctCodes(entry.getValue(), codeSystem));
codeSystems.add(codeSystem.getUrl());
}
if (codeSystems.size() > 0) {
return buildIssue(response, "information", "informational", "Successfully updated the following CodeSystems: " + String.join(", ", codeSystems));
} else {
return buildIssue(response, "information", "informational", "No code systems were updated");
}
}
Aggregations