workshop-smart-data-fabric

Downloads3
Subscribe
1
Bookmark
1
This application is not supported by InterSystems Corporation. Please be notified that you use it at your own responsibility.
Details
Releases
Reviews
Issues

What's new in this version

Initial Release

Learn the foundamentals to implement an Smart Data Fabric architect using InterSystems IRIS.

Learn the basics

👉 We will combine different features of InterSystems IRIS such as multi-model database, interoperability and analytics.

If you are not too familiar with InterSystems IRIS technology, you can get a hands-on overview with these resources:

What do you need to install?

Setup

Clone the GitHub repository to your local computer. This will allow you to acces the code and build the samples:

git clone https://github.com/intersystems-ib/workshop-smart-data-fabric

Build the image we will use during the workshop:

docker-compose build

Run the container:

docker-compose up -d

You should be able to access InterSystems IRIS Management Portal and login using superuser / SYS.

Environment

We are going to use an environment using Docker containers.

After running the environment, you can access to an interactive sesion on IRIS container using:

docker-compose exec -it iris bash

You can also have a look at the container logs using:

docker logs iris

Data model

Have a look at the main classes of our data model:

  • Patient will store patient definitions
  • Observation will store different kind of observations for the patients (e.g. diastolic bp, systolic bp, body temperature, etc.)

Our classes are persistent. That means that they can store data, and in InterSystems IRIS we will be able to work with them using objects as well as SQL automatically.

These classes also use Relationships and some Indexes. They can also contain methods and logic.

Go to System Explorer > SQL (SDF), locate the tables corresponding to our persistent classes and display them. They should be empty.

We manipulate data using SQL or Objects. Let's create some simple data using objects through the WebTerminal

First, create a patient object:

    set patientObj = ##class(sdf.data.Patient).%New()
    set patientObj.Identifier = "12345"
    set patientObj.FirstName = "John"
    set patientObj.LastName = "Doe"

Then, create an observation for the patient:

    set obxObj = ##class(sdf.data.Observation).%New()
    set obxObj.Code = "BodyTemp"
    set obxObj.ValueNM = "36"
    set obxObj.Units = "C"

Finally, insert the observation into the patient record and save it

    do patientObj.Observations.Insert(obxObj)
    set sc = patientObj.%Save(1)
    write !,"statusCode=",sc

After that, try to run SQL queries again. You can also take advantage of Implicit Joins (Arrow Syntax):

SELECT 
Patient->FirstName, Patient->LastName,Code, Units, ValueNM
FROM sdf_data.Observation

After your tests, delete all the data you have just created:

    write ##class(sdf.data.Observation).%KillExtent()
    write ##class(sdf.data.Patient).%KillExtent()

Ingestion

Data

cd data
tar -zxvf hl7files.tar.gz

DataPipe and DataPipeUI

  • You could implement data ingestion in a lot of different ways. In this example, we will be using a community tool called DataPipe that is already installed in the environment.
  • This will help us on enriching, normalizing and validating the incoming data using InterSystems IRIS interoperability features.
  • Also you can use an user interface DataPipeUI to have a look at the incoming data to the system and how it's being handled.
  • In a separate terminal in your system, clone the repo and run the DataPipeUI container user interface:
git clone https://github.com/intersystems-ib/iris-datapipeUI
cd iris-datapipeUI
docker-compose up -d

Try ingesting some data yourself

You can also copy all files using:

cd data
cp hl7files/*.hl7 hl7in

DataPipe Model

DataPipe allows you to define an interoperability model with the properties that you need, and then decide how are you going to normalize and validate it. You have to implement a few methods.

In this case, we are using R01Model.cls:

  • It defines the properties we need for processing incoming ORU^R01 HL7 messages with observations.
  • Implements Serialize and Deserialize methods to serialize and deserialize using JSON format.
  • To Normalize, it calls R01Normalize data transformation.
  • To Validate, implements some checks on the incoming data.
  • Finally, in RunOperation implements what are we going to do with the ingested data. In this example it is storing data in sdf.data.* classes.

DataPipe Production

  • The production that is ingesting data, have some elements you should review:
  • HL7 In - built-in HL7 file Business Service that reads HL7 files from a directory.
  • HL7 Ingestion - Business Process that:
  • HL7 Staging is a DataPipe business process (DataPipe.Staging.BP.StagingManager) that handles the normalization and validation of your DataPipe model.
  • HL7 Oper is another DataPipe business process (DataPipe.Oper.BP.OperManager) that handles running your DataPipe model operation.

Services

Let's create a REST service to interact with your sdf.data.* classes. But first, we can start by working with JSON.

JSON

%JSON.Adaptor

Your sdf.data.* classes already extends from %JSON.Adaptor. It provides some nice features for importing and exporting your objects to and from JSON.

Open a WebTerminal session and try the following:

Open an object and export to JSON:

    // open an object from a persistent class
    set patient = ##class(sdf.data.Patient).%OpenId(1)
    // directly, export to json to current device
    do patient.%JSONExport()

Now, let's try to format the JSON for our object:

    // export patient object to a json string
    do patient.%JSONExportToString(.json)
    // instantiate a json formatter
    set formatter = ##class(%JSON.Formatter).%New()
    do formatter.FormatToString(json, .formattedJson)
    // print formatted json
    write formattedJson

In your sdf.data.Patient class, change the %JSONREFERENCE attribute from ID to OBJECT or viceversa and try again the following:

    // delete previous in-memory object definition
    kill patient
    // re-open object (so it can load your change on %JSONREFERENCE)
    set patient = ##class(sdf.data.Patient).%OpenId(1)
    // export to a formatted json string
    do patient.%JSONExportToString(.json)
    do formatter.FormatToString(json, .formattedJson)
    // print your json string
    write formattedJson

Can you tell the difference between using ID or OBJECT?

⚠️ Important! Before going on, be sure your sdf.data.Patient class has (%JSONREFERENCE = "ID") defined.

%JSON.Adaptor has a lot of nice features that allows you to export and import and customize those behaviours. We'll use them in the REST service we will implement.

%JSON.Adaptor is a nice approach if you have already defined classes that you want to serialize or deserialize to JSON format.

%DynamicObjects

%DynamicObjects allows you to work with JSON structures without having a previous definition (dynamically).

In your WebTerminal session try the following:

    set dynamicObject = {"prop1":"a string value"}
    write dynamicObject.prop1
<span class="pl-k">set</span> <span class="pl-v">dynamicArray</span> = [[<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">3</span>],{<span class="pl-s"><span class="pl-pds">"</span>A<span class="pl-pds">"</span></span>:<span class="pl-c1">33</span>,<span class="pl-s"><span class="pl-pds">"</span>a<span class="pl-pds">"</span></span>:<span class="pl-s"><span class="pl-pds">"</span>lower case<span class="pl-pds">"</span></span>},<span class="pl-c1">1</span>.<span class="pl-e">23456789012345678901234</span>,<span class="pl-v">true</span>,<span class="pl-v">false</span>,<span class="pl-v">null</span>,<span class="pl-c1">0</span>,<span class="pl-c1">1</span>,<span class="pl-s"><span class="pl-pds">"</span><span class="pl-pds">"</span></span>]
<span class="pl-k">write</span> <span class="pl-v">dynamicArray</span>.<span class="pl-e">%ToJSON</span>()</pre></div>

Have a look at the documentation section Using JSON in ObjectScript to have an overview of all the options you have available with %JSON.Adaptor or %DynamicObjects.

REST Service

There are different ways of implement REST services in InterSystems IRIS. We will implement a %CSP.REST service. Don't forget to check the documentation section Introduction to Creating REST Services to have a full view.

Open https://github.com/intersystems-ib/workshop-smart-data-fabric/blob/main/sdf.connectors.api.DataEndpoint. This will be our service for accesing some of our sdf.data.* classes.

Review the different methods that are implemeted and try to figure out what are they doing.

REST services needs a web application that forwards HTTP requests to them, in this case we have the /sdf/api web application.

Also, in https://github.com/intersystems-ib/workshop-smart-data-fabric/blob/main/iris.script you will find how this web application is imported during the container image build for the environment.

Finally, try your service using Postman. Import the https://github.com/intersystems-ib/workshop-smart-data-fabric/blob/main/workshop-smart-data-fabric.postman_collection.json included in the repository and try the different requests:

Embedded Python

Embedded Python allows you to use Python to program InterSystems IRIS applications. You can even mix ObjectScript methods and Python methods and refer to objects created in either language! And of course you could use any Python libraries on your implementation. Check the documentation section Using Embedded Python to have a full view on this topic.

We are going to use Embedded Python to implement in our REST service an operation that will return an Excel file with the observations for an specific patient. We will take advantage of openpyxl Python library to create Excel files:

You can test it accessing to http://localhost:52773/sdf/api/patient/2/observations/xls in your browser.

Interoperability

We are going to create a Telegram bot and use it to send some notifications about our Smart Data Fabric.

Telegram bot setup

/newbot

Write down your Telegram Bot token.

  • Open a new Telegram chat with your brand new Telegram bot. Write some dummy messages.
  • Usually, you will process incoming messages to your bot using a WebHook or the getUpdates Telegram API. In this example, we will only focus on sending messages.
  • You will need a chat id and your token to send messages.
  • Grab your chat id by accesing https://api.telegram.org/bot<your_token>/getUpdates. You should get a JSON response from Telegram. Look for something like:
...
"chat":{"id":<your_chatId>
...

Business operation settings

You can now test your Telegram Business Operation:

Calling your Business operation

Ingestion

You can call your Telegram business operation from the ingestion layer using your Data Pipe model, try to add the following in R01Model:

    $$$AddLog(log, "Transaction Commited")

// you can send messages to other production components (while you are not on an open transaction)
if $isobject(bOperation) {
set req = ##class(sdf.connectors.interop.msg.TelegramMsgReq).%New()
set req.text = "Patient ("..PatientId") ingested! 🌡️ "$number(..ObxValues.GetAt("BodyTemp"),2)" "_..ObxUnits.GetAt("BodyTemp")
$$$ThrowOnError(bOperation.SendRequestAsync("TelegramSendMessage", req))
}

Services

You can also call interoperability components from your REST service context.

Let's call the Telegram business operation from the REST service:

  • Service will handle requests to /summary to send a summary of the sdf.
  • This will be implemented in DataEndpoint:GetSummary.
  • In the method, we will call interoperability components. For that you need to start your call instatiating a Business Service that will init the interoperability context.
  • We will instantiate TelegramFromService business service. It will simply send a message to our Telegram business operation.

Enabling FHIR using FHIR Façade Architecture

HL7 FHIR (Fast Healthcare Interoperability Resources) has become the top standard for the exchange of patient data across healthcare systems.

However, not all applications can be completely re-written to exchange data using the FHIR standard, and facilities may not be able to deploy a full FHIR repository.

You can use InterSystems IRIS For Health to to create an architecture that acts as a façade for a FHIR repository, allowing you to avoid complete rework while reaping the benefits of using FHIR data in your existing applications.

You can find more information in FHIR Façade Architecture Overview.

Let's say that you want to implement an architecture that enables FHIR for our classes in sdf.data.* package.

You will now implement a FHIR Façade.

Create a FHIR Server

You will now create a FHIR Server and use your own InteractionsStrategy that implements a FHIR Façade on top of your sdf.data.* package:

Create a FHIR server in Health > SDF > FHIR Configuration > Server Configuration > Add Endpoint

  • Core FHIR package: hl7.fhir.r4.core@4.0.1
  • URL: /csp/healthshare/sdf/fhir/r4
  • Interactions Strategy Class: sdf.fhirserver.InteractionsStrategy

Now, edit the FHIR endpoint you have just created:

  • Enable New Service Instance. This is useful in case you want to change InteractionsStrategy class during development and test the new behaviour immediately.

FHIR Façade implementation

In this case these are the main involved classes:

Try it out

Using the included Postman collection, try some requests that are already prepared:

  • metadata: retrieve your FHIR Façade Capability Statement
  • Get Patient: retrieve a particular patient as a FHIR resource
  • Get Patients. Female. Paginated: search female patients and retrieve a paginated bundle.

Analytics

There multiple ways in which you can leverage analytics & data science using InterSystems IRIS:

  • IRIS Business Intelligence - Allows you to embed business intelligence into your applications. You can have a first look at it in workshop-iris-bi-intro
  • Adaptive Analytics - an optional extension that provides a business-oriented, virtual data model layer between InterSystems IRIS and popular Business Intelligence (BI) and Artificial Intelligence (AI) client tools. You can checkout this Spanish Webinar Self-Service Analytics y Reporting.

We will focus on IRIS BI on our first example.

BI. Defining a Cube

Open Management Portal > Analytics > SDF > Architect > Open Observations Cube and go through the different dimensions and measures defined for a cube based on the observations persistent class.

These dimensions and measures define what kind of analysis can be done using this cube.

Click on Build to build the cube based on the data you have loaded previously.

BI. Analyzer

Then, open Management Portal > Analytics > SDF > Analyzer > Open Observations Cube and try different combinations for rows & columns on your analysis pivot table.

You can also open a pre-defined pivot. In your VS Code Import & Compile AvgObservationsByAge.pivot.dfi.

BI. User portal

Finally, you can create dashboards and build widgets based on your analysis pivot tables. In your VS code Import & Compile AvgObservationsByCode.dashboard.dfi.

Then, open Management Portal > Analytics > SDF > User Portal > Open Avg Values by Sex, Age Dashboard

BI. DSW

In Open Exchange you can find awesome applicatiosn like DSW that enables a whole new great looking UI for your IRIS BI.

You can checkout in your example accessing http://localhost:52773/dsw/index.html#/SDF

Machine Learning. IntegratedML

Again, there are different ways you can add Machine Learning features on your InterSystems IRIS Applications:

  • IntegratedML - is an InterSystems IRIS features that allows you to leverage automated machine learning functions directly from SQL.
  • PMML - Predictive Modeling Markup Language is an XML-based standard that expresses analytical models. You can express a model using PMML and deploy it in InterSystems IRIS.
  • Python libraries - and of course, taking advantage of Embedded Python, you can use Python libraries such as pandas, scikit-learn, tensorflow, etc directly with your IRIS data to implement your ML models.

We will focus on a simple example of IntegratedML.

We are still using a dataset inspired on Maternal Health Risk Data dataset from Kaggle.

"Inspired" in this particular case means that we won't have all the data available, so the accuracy of our ML model could be better.

In any case, if you are interested on using the whole dataset check out workshop-integratedml-intro.

Now, in our example check the following:

Go to Management Portal > Explorer > SQL > SDF and run the following:

Create a model for predicting the RiskLevel column based on your training data:

CREATE MODEL MaternalModel PREDICTING (RiskLevel) FROM sdf_data.MaternalRiskTrain

Train your model using your training data:

TRAIN MODEL MaternalModel

Now, validate your model using your test data:

VALIDATE MODEL MaternalModel FROM sdf_data.MaternalRiskTest

You can check the validation metrics for your model:

SELECT * FROM INFORMATION_SCHEMA.ML_VALIDATION_METRICS

And finally, you can use your model to get predictions:

SELECT *, PREDICT(MaternalModel) AS PredictedRisk FROM sdf_data.MaternalRiskTest

Jupyter Notebooks

In https://github.com/intersystems-ib/workshop-smart-data-fabric/blob/main/docker-compose.yml has been added a jupyter notebook service so we can connect to IRIS using IRIS Native SDK for Python.

Try the following:

Try it! Think about all the available Python ML libraries you could use to analyze your IRIS data from a pure Python context. You can run queries or directly call your IRIS objects methods.

Appendix. Generating data

During the workshop you have been working with already created HL7 files inspired on Maternal Health Risk Data dataset from Kaggle.

Here is how these HL7 files have been created:

Load train data into a temporary table in IRIS:

do ##class(community.csvgen).Generate("/app/data/maternalRisk/maternal_health_risk.csv",",","temp.MaternalHealthRisk")

Then use a simple tool to generate HL7 files:

do ##class(sdf.tools.HL7Generator).GenerateFilesHL7()

Your files will be generated in data/maternalRisk/hl7gen.

Rating
5 (1)
Category
Technology Example
Works with
InterSystems IRISInterSystems IRIS for HealthInterSystems IRIS BIInterSystems FHIR
Tags
Info
Version
1.0.0
Last updated
2023-04-26
Repository
Open
Documentation
Open
License
Link