qewd-ripple: the ripple osi middle tier
TRANSCRIPT
Copyright © 2016 M/Gateway Developments Ltd
qewd-ripple
The Ripple OSI Middle Tier
Rob TweedDirector, M/Gateway Developments Ltd
Twitter: @rtweed
Copyright © 2016 M/Gateway Developments Ltd
What is qewd-ripple?
• Demonstration version of the Node.js-based middle tier for the Ripple OSI Application– http://rippleosi.org/
• Built using the QEWD framework– http://www.mgateway.com
• Integrates multiple OpenEHR Servers– Ripple's UI presents a unified interface
• REST-based
Copyright © 2016 M/Gateway Developments Ltd
Installing qewd-ripple
• See instructions at:– https://github.com/RippleOSI/Qewd-Ripple
• The built-in installer script creates a fully-working system– Ubuntu 16.04– Raspberrry Pi
• Could be easily adapted for use with other flavours of Linux
Copyright © 2016 M/Gateway Developments Ltd
qewd-ripple
• Linux installation: components installed include:– Node.js 6.x– QEWD– Redis or GT.M: "Global Storage" NoSQL
database– MySQL– Ripple UI:
• HTML, JavaScript, CSS files
Copyright © 2016 M/Gateway Developments Ltd
QEWD• Node.js-based module• Used as the REST platform for qewd-ripple• Provides an outward-facing HTTP/REST
interface– Courtesy of Express, the standard Node.js web server
• Provides the run-time environment for Ripple's REST API handler functions– Written in JavaScript
• Acts as a proxy to and integrates multiple OpenEHR (and potentially other) servers
Copyright © 2016 M/Gateway Developments Ltd
GT.M
• Used by QEWD as an embedded, in-process, persistent JSON store and Document Database, for:– Session management– OpenEHR data cacheing
• On a per-user basis
Copyright © 2016 M/Gateway Developments Ltd
Redis
• Redis– High-performance key/value store– ewd-redis-globals module:
• Gives Global Storage functionality to Redis– Used by the Raspberry Pi version of qewd-
ripple– Alternative to GT.M for Linux version of qewd-
ripple• Behaves identically to GT.M as far as qewd-ripple
is concerned
Copyright © 2016 M/Gateway Developments Ltd
MySQL
• Used in the Ripple OSI Demonstrator for PAS functionality
Copyright © 2016 M/Gateway Developments Ltd
Starting qewd-ripple
• cd ~/qewd• Demo-mode:
– node ripple-demo• Secure mode
– node ripple-secure
Copyright © 2016 M/Gateway Developments Ltd
Running Ripple OSI
• Point a browser at the IP address or host name of the server running qewd-ripple, eg:
– http://192.168.1.100
Copyright © 2016 M/Gateway Developments Ltd
Ripple Demo Mode
• Simulates a user with full access to all patient data– IDCR mode
Copyright © 2016 M/Gateway Developments Ltd
Ripple Secure Mode
• User identity management taken care of by a 3rd party service– The qewd-ripple demonstrator uses Auth0
• Users can have two alternative modes of access:– IDCR: clinical user, with full access to all
patient data– PHR: an individual patient, with read access
to his/her own data only
Copyright © 2016 M/Gateway Developments Ltd
qewd-ripple architecture
• Extends QEWD• Uses it for REST access only• Implements handlers for the Ripple OSI
REST APIs
Copyright © 2016 M/Gateway Developments Ltd
QEWD (using Redis/GT.M)
Node.js Worker Process
Master Node.js Process
Queue
Queueprocessor/dispatcher
qewd
ewd-qoper8-gtm
Redis/GT.M
ewd-document-store
GlobalStorage
ewd-session
Express
HTTP(S)Interface
RES
T C
lient
Custom WorkerModule
ewd-qoper8
Constructed from a number of EWD 3 modules
Copyright © 2016 M/Gateway Developments Ltd
QEWD's Architecture
• Master Process– Handles all incoming REST requests
• Via Express• Queues and dispatches requests to worker
processes
• Worker Processes– You define how large a pool of workers you
require– Each worker handles just one request
Copyright © 2016 M/Gateway Developments Ltd
Master Node.js Process
Queue
Queueprocessor/dispatcher
Ripple RESTRequest
QEWD Architecture
Every incoming requestis passed from Expressand placed in a queue
No further processingof requests occurs inthe master process
Copyright © 2016 M/Gateway Developments Ltd
QEWD ArchitectureMaster Node.js Process
Queue
Queueprocessor/dispatcher
Queue dispatcher isinvoked whenever arequest is added tothe queue
Copyright © 2016 M/Gateway Developments Ltd
QEWD Architecture
Node.js Worker Process
Master Node.js Process
Queue
Queueprocessor/dispatcher
Worker processstarted if none
available
Copyright © 2016 M/Gateway Developments Ltd
QEWD Architecture
Node.js Worker Process
Master Node.js Process
Queue
Queueprocessor/dispatcher
qewd-rippleHandler module
Redis/GT.M
QEWD &qewd-ripple-specific
Modules loaded
and connected todatabase:
Redis or GT.M
Copyright © 2016 M/Gateway Developments Ltd
QEWD Architecture
Node.js Worker Process
Master Node.js Process
Queue
Queueprocessor/dispatcher
CustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
Request passedto worker
Copyright © 2016 M/Gateway Developments Ltd
QEWD Architecture
Node.js Worker Process
Master Node.js Process
Queue
Queueprocessor/dispatcher
CustomWorkerModule
Worker flagged as Unavailable
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
Begin processing message
Copyright © 2016 M/Gateway Developments Ltd
QEWD ArchitectureMaster Node.js Process
Queue
Queueprocessor/dispatcher
Unavailable / processingAnother incomingRippleREST request
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
Copyright © 2016 M/Gateway Developments Ltd
QEWD Architecture
Node.js Worker Process
Master Node.js Process
Queue
Queueprocessor/dispatcher
CustomWorkerModule
Unavailable / processing
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
If worker pool size not exceeded,another worker is startedand request passed to it
Copyright © 2016 M/Gateway Developments Ltd
QEWD ArchitectureMaster Node.js Process
Queue
Queueprocessor/dispatcher
Unavailable / processing
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
If entire Worker Pool is busy:
Unavailable / processing
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
Unavailable / processing
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
Copyright © 2016 M/Gateway Developments Ltd
QEWD ArchitectureMaster Node.js Process
Queue
Queueprocessor/dispatcher
Unavailable / processing
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
If entire Worker Pool is busy:
Unavailable / processing
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
Unavailable / processing
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
New requests remain
in queue
Copyright © 2016 M/Gateway Developments Ltd
QEWD ArchitectureMaster Node.js Process
Queue
Queueprocessor/dispatcher
Unavailable / processing
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
As soon as a worker is available again,a queued message can be passed to it
Unavailable / processing
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
Available
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
Copyright © 2016 M/Gateway Developments Ltd
QEWD ArchitectureMaster Node.js Process
Queue
Queueprocessor/dispatcher
Finished
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
A user's handler function signalscompletion using the function:
finished(responseObject);
This returns the responseobject to the master
process
Copyright © 2016 M/Gateway Developments Ltd
QEWD ArchitectureMaster Node.js Process
Queue
Queueprocessor/dispatcher
Finished
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
And the response ispassed to Express which
returns it to the clientthat sent the original request
Copyright © 2016 M/Gateway Developments Ltd
QEWD ArchitectureMaster Node.js Process
Queue
Queueprocessor/dispatcher
Available
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
The finished() functionalso automatically returnsthe worker process back
to the available pool
So it can now handlethe next queued request
Copyright © 2016 M/Gateway Developments Ltd
QEWD ArchitectureMaster Node.js Process
Queue
Queueprocessor/dispatcher
Available
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
Worker processes, once started, are persistent
No start-up / tear-down cost
Workers will automatically close themselves down if they are
inactive for more than a pre-setthreshold time period
Copyright © 2016 M/Gateway Developments Ltd
QEWD ArchitectureMaster Node.js Process
Queue
Queueprocessor/dispatcher
Available
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
Worker processes only handlea single request at a time
Completely isolated run-timeenvironment for handler functions
No need for concerns aboutNode.js concurrency, so
synchronous APIs can be used
Copyright © 2016 M/Gateway Developments Ltd
QEWD ArchitectureMaster Node.js Process
Queue
Queueprocessor/dispatcher
Available
Node.js Worker ProcessCustomWorkerModule
Redis/GT.M
Long-running or CPU-intensivelogic has no direct impact on
other worker processes
Copyright © 2016 M/Gateway Developments Ltd
QEWD ArchitectureMaster Node.js Process
Queue
Queueprocessor/dispatcher
Node.js concurrency is handledby the master process.
100% asynchronous logic
The master process doesalmost nothing
No CPU-intensive or long-running tasks, so very
high-performance
All the work happens in theisolated worker processes
MultipleConcurrentIncoming
REST requests
Copyright © 2016 M/Gateway Developments Ltd
qewd-ripple Session Management
• Everything begins with receipt of /api/initialise request, sent from the Ripple UI
Copyright © 2016 M/Gateway Developments Ltd
The /api/initialise API
• If:– qewd-ripple is running in demo mode; and– this is the first time the browser has connected
• Then:– the middle tier starts a new QEWD Session which creates a
token• The token is a random uuid-formatted string
– A hard-coded set of user credentials are stored in the Session (an IDCR-mode user)
– The Session token is returned in the response to the UI• The UI stores this as a cookie named JSESSIONID
– All subsequent requests will include this cookie
Copyright © 2016 M/Gateway Developments Ltd
qewd-ripple Session Management
• If:– qewd-ripple is running in secure mode; and– this is the first time the browser has connected
• Then:– the middle tier passes control to Auth0– User logs in via Auth0– If successful, the credentials are passed back to qewd-ripple– qewd-ripple creates a new QEWD Session and saves the
credentials in the user's Session– The Session token is returned in the response to the UI
• The UI stores this as a cookie named JSESSIONID
Copyright © 2016 M/Gateway Developments Ltd
The /api/initialise API
• If:– The request includes a JSESSIONID cookie containing a
currently valid, unexpired QEWD Session token• Then:
– the middle tier returns an OK response that also tells the UI the user's mode:
• IDCR or PHR
Copyright © 2016 M/Gateway Developments Ltd
qewd-ripple Session Management
• On successful receipt of the /api/initialiseresponse, the UI issues an /api/user request– This request will now include the JSESSIONID cookie
• So qewd-ripple can identify the user's Session
• The middle tier retrieves the user's credentials from the Session and returns them to the UI
• The UI can now display the user's details
Copyright © 2016 M/Gateway Developments Ltd
qewd-ripple Session Management
• The UI can now start issuing its REST APIs to the middle tier
• Every request will include the JSESSIONID cookie which contains the user's QEWD Session token, allowing the request's handler to access the user's QEWD Session:– To retrieve data– To cache data
Copyright © 2016 M/Gateway Developments Ltd
Accessing OpenEHR ServersBrowser QEWD
GT.M orRedis
ewd-qoper8queue
qewd-rippleModule
Express
Worker
Puls
eTile
UI REST/
HTTP
Incoming request for somepatient heading data
eg Allergies
Copyright © 2016 M/Gateway Developments Ltd
Accessing OpenEHR ServersBrowser QEWD
GT.M orRedis
ewd-session
ewd-qoper8queue
qewd-rippleModule
Express
Worker
Puls
eTile
UI
Is the allergies data in the user'sQEWD Session storage?
Copyright © 2016 M/Gateway Developments Ltd
Accessing OpenEHR ServersBrowser QEWD
GT.M orRedis
ewd-session
ewd-qoper8queue
qewd-rippleModule
Express
Worker
Puls
eTile
UI
Is the allergies data in the user'sQEWD Session storage?
No
Copyright © 2016 M/Gateway Developments Ltd
Accessing OpenEHR ServersBrowser QEWD
GT.M orRedis
ewd-qoper8queue
qewd-rippleModule
Express
OpenEHRServer
AQL overHTTP(S)
Worker
Puls
eTile
UI
OpenEHRServer
Fetch the allergies datafrom the OpenEHR
servers
Copyright © 2016 M/Gateway Developments Ltd
Accessing OpenEHR ServersBrowser QEWD
GT.M orRedis
ewd-qoper8queue
qewd-rippleModule
Express
OpenEHRServer
HTTP(S)
Worker
Puls
eTile
UI
OpenEHRServer
And save it in theuser's QEWD
Session storage
ewd-session
Copyright © 2016 M/Gateway Developments Ltd
Accessing OpenEHR ServersBrowser QEWD
GT.M orRedis
ewd-session
ewd-qoper8queue
qewd-rippleModule
Express
Worker
Puls
eTile
UI
Repeat the logic…
Is the allergies data in the user'sQEWD Session storage?
Copyright © 2016 M/Gateway Developments Ltd
Accessing OpenEHR ServersBrowser QEWD
GT.M orRedis
ewd-session
ewd-qoper8queue
qewd-rippleModule
Express
Worker
Puls
eTile
UI
Repeat the logic…
Is the allergies data in the user'sQEWD Session storage?
Yes
Copyright © 2016 M/Gateway Developments Ltd
Accessing OpenEHR ServersBrowser QEWD
GT.M orRedis
ewd-session
ewd-qoper8queue
qewd-rippleModule
Express
Worker
Puls
eTile
UI
Return it to theBrowser that made
The request
Map OpenEHRfield-names toUI field-names
Copyright © 2016 M/Gateway Developments Ltd
Accessing OpenEHR ServersBrowser QEWD
GT.M orRedis
ewd-qoper8queue
qewd-rippleModule
Express
Worker
Puls
eTile
UI REST/
HTTP
If a later request arrivesfrom this user for
Allergies data
Copyright © 2016 M/Gateway Developments Ltd
Accessing OpenEHR ServersBrowser QEWD
GT.M orRedis
ewd-session
ewd-qoper8queue
qewd-rippleModule
Express
Worker
Puls
eTile
UI
Is the allergies data in the user'sQEWD Session storage?
Yes
Copyright © 2016 M/Gateway Developments Ltd
Accessing OpenEHR ServersBrowser QEWD
GT.M orRedis
ewd-session
ewd-qoper8queue
qewd-rippleModule
Express
Worker
Puls
eTile
UI
Return it to theBrowser that made
The request
Map OpenEHRfield-names toUI field-names
Copyright © 2016 M/Gateway Developments Ltd
QEWD Session = Headings Cache
• Each user's QEWD Session acts as a high-performance cache of headings data– Minimises "round-trips" to OpenEHR servers
• QEWD Session storage:– Persistent JSON storage– Document database– GT.M and Redis behave identically as far as
qewd-ripple is concerned