Article
· 11 hr ago 4m read

Creating FHIR responses with IRIS Interoperability productionContestant

When we create a FHIR repository in IRIS, we have an endpoint to access information, create new resources, etc. But there are some resources in FHIR that probably we wont have in our repository, for example, Binary resource (this resource returns a document, like PDF for example).

I have created an example that when a Binary resource is requested, FHIR endpoint returns a response, like it exists in the repository. 

First of all, we need a Namespace and a FHIR endpoint. After this, we need to configure an Interoperability production that will be connected to the FHIR endpoint. This production must have this items:

  • Business Operations:
    • HS.Util.Trace.Operations (in fact this is optional, but can be very useful)
    • HS.FHIRServer.Interop.Operation, with TraceOperations property set to *FULL*
  • Business Service:
    • HS.FHIRServer.Interop.Service, with TraceOperations property set to *FULL* and Target Config Name set to HS.FHIRServer.Interop.Operation name

This is how production looks like:

After creating this production, we need to connect it with the FHIR endpoint. So edit FHIR endpoint and set the parameter Service Config Name with the name of the Business Service:

Now, if we start to send requests to FHIR repository, we will see all the traces in Message Viewer:

Now we can have a Business Process to control what to do with specific paths.

In this example we have a Business Process that receives every request (now the Business Service it's connected to this Business Process, instead of the Business Operation) and 2 new Business Operation that makes another actions that will be explained later:

Let's take a look to the Business Process called FHIRRouter:

If we take a look, we will see that, if RequestPath contains "Binary/", then we will do something with this request: generate our custom Binary response. Otherwise, we will send the request to FHIR Repository directly.

Let't take a look at the sequence called "Generate Binary":

First of all, we create a new instance of HS.FHIRServer.Interop.Response. And we get the document ID from the Request Path. How? Every time someone want's a Binary resource, it must be requested with the ID of the document in the URL path, something like this: ..../fhir/r4/Binary/XXXXX. So we extract the document ID from the Request Path with this expression:

$Replace(request.Request.RequestPath,"Binary/","")

(It's not very elegant, but it works).

If we have a document ID, then we make a call to a Business Operation called Find to find the filename associated to that document ID:

In fact, this Business Operation Find always returns the same filename:

It's an example of what we can do.

If we have a filename, then, we call another Business Operation called File to get this file content, encoded in base64:

And finally, we can return 2 kind of responses:

  • If we don't have file content (because we don't have a document ID or we don't find it's associated filename or content), we return a 404 response, with this custom response:
 set json = {
    "resourceType": "OperationOutcome",
    "issue": [
        {
            "severity": "error",
            "code": "not-found",
            "diagnostics": "<HSFHIRErr>ResourceNotFound",
            "details": {
                "text": "No resource with type 'Binary'"
            }
        }
    ]
 }
 set json.issue.%Get(0).details.text = json.issue.%Get(0).details.text_" and id '"_context.docId_"'"
 set qs = ##class(HS.SDA3.QuickStream).%New()
 do qs.Write(json.%ToJSON())
 set response.QuickStreamId = qs.%Id()
 set response.ContentType = "application/fhir+json"
 set response.CharSet = "UTF-8"
  • If we have file content, then we return a 200 response with this custom response:
 set json = {
  "resourceType": "Binary",
  "id": "",
  "contentType": "application/pdf",
  "securityContext": {
    "reference": "DocumentReference/"
  },
  "data": ""
 }
 set json.id = context.docId
 set json.securityContext.reference = json.securityContext.reference_json.id
 set json.data = context.content.Read(context.content.Size)
 
 set qs = ##class(HS.SDA3.QuickStream).%New()
 do qs.Write(json.%ToJSON())
 set response.QuickStreamId = qs.%Id()
 set response.ContentType = "application/fhir+json"
 set response.CharSet = "UTF-8"

The key here is to create a HS.SDA3.QuickStream, that contains the JSON object. And add this QuickStream to the response.

And now, if we test our endpoint, if we request of a Binary document, we will see the response:

And if we request a Binary document that doesn't exist (you can test it passing no document ID), we will see 404 response:

In summary, connecting our FHIR endpoint with interoperability we can do whatever we want, with all the capabilities of InterSystems IRIS.

Discussion (0)0
Log in or sign up to continue