EWD and the Art of Mobile Application Development

59
EWD Lite Rob Tweed M/Gateway Developments Ltd Twitter: @rtweed Email: [email protected] 1 Tuesday, 16 July 13

Transcript of EWD and the Art of Mobile Application Development

Page 1: EWD and the Art of Mobile Application Development

EWD Lite

Rob TweedM/Gateway Developments Ltd

Twitter: @rtweedEmail: [email protected]

1Tuesday, 16 July 13

Page 2: EWD and the Art of Mobile Application Development

EWD Lite

• Background, History and Aims• Underlying Technology & Architecture

– Comparison with “classic” EWD– Benefits

• How do you use it?– Examples

2

2Tuesday, 16 July 13

Page 3: EWD and the Art of Mobile Application Development

The backdrop

• How to make Mumps acceptable to the “mainstream”?

• How to recruit and retain new developers with the expertise to:– exploit the new and expanding possibilities of

browsers as the modern, ubiquitous UI platform– make VistA the healthcare Big Data visualisation

platform of choice– make Healthcare IT as exciting and cool as the

gaming and social media industries?

3Tuesday, 16 July 13

Page 4: EWD and the Art of Mobile Application Development

http://robtweed.wordpress.com

4Tuesday, 16 July 13

Page 5: EWD and the Art of Mobile Application Development

Mumps: a Dead End?• Not seen as a sensible career move by most of

the new generation of developers– Unlikely to want a Mumps development job– Unlikely to be retained very long

• Dwindling pool of Mumps skills, despite training efforts

• Significant brake on VistA uptake:– Seen as a risk by potential adopters:

• Old, obsolete technology• Shortage of developers

5Tuesday, 16 July 13

Page 6: EWD and the Art of Mobile Application Development

Step 1: remove the conflation

• Focus on Mumps, the database– the Mumps language is pilloried by the

mainstream, for founded and unfounded reasons

• attempting to change that opinion is futile– By Mumps being considered a language, the

Mumps database is dismissed by the mainstream

– It’s the database that is the unique and powerful part of the technology

6Tuesday, 16 July 13

Page 7: EWD and the Art of Mobile Application Development

Mumps: Universal NoSQL

7Tuesday, 16 July 13

Page 8: EWD and the Art of Mobile Application Development

Step 2: Replace the language

• A language that has similar good parts to Mumps

• Object oriented, but dynamic objects• High performance and scalability• Highly popular language that is likely to

stay that way• Similar intimate integration with the

Mumps database

8Tuesday, 16 July 13

Page 9: EWD and the Art of Mobile Application Development

JavaScript: ticks all the boxes

• A language that has similar good parts to Mumps

• Object oriented, but dynamic objects• High performance and scalability• Highly popular language

– Games, 3-d, social media industries– It’s not going to disappear– It’s the language new developers are learning

9Tuesday, 16 July 13

Page 10: EWD and the Art of Mobile Application Development

JavaScript runs in the browser, right?

• Yes, but now also on the server:– Node.js

10

10Tuesday, 16 July 13

Page 11: EWD and the Art of Mobile Application Development

Node.js• Server-side implementation of Javascript• Started as an open-source project by Ryan Dhal• Uses Google’s V8 Javascript engine• Designed for network programming

– Event-driven– Normally asynchronous I/O

• Very high performance and scalability• Runs on Linux, Windows & Mac OS X• Recently officially approved for use by the VA

11Tuesday, 16 July 13

Page 12: EWD and the Art of Mobile Application Development

Node.js

• Many open-source modules, in particular:– built-in Web server– Socket.io: web-sockets

12Tuesday, 16 July 13

Page 13: EWD and the Art of Mobile Application Development

InterSystems Node.js Interface• Initially introduced for their free Globals

database– Used their very low-level interface into the core global

database engine– Written by Chris Munt (M/Gateway Developments)– Very high performance

• Ported to Caché (2012.2)– Official standard interface– function() API added to invoke Mumps functions from

Javascript

13Tuesday, 16 July 13

Page 14: EWD and the Art of Mobile Application Development

Equivalent for GT.M?

• David Wicksell: NodeM– https://github.com/dlwicksell/nodem

– API-compatible reverse-engineer of InterSystems’ Node.js interface

• Behaves identically

14Tuesday, 16 July 13

Page 15: EWD and the Art of Mobile Application Development

Node.js Interface

15Tuesday, 16 July 13

Page 16: EWD and the Art of Mobile Application Development

Mumps, the JSON Database

• Important to present a Mumps database as something natural to a JavaScript developer

• JSON is their lingua-franca• Abstract Mumps Global storage into

persistent JavaScript Objects– similar level of “intimacy” as between the

Mumps language and database

16

16Tuesday, 16 July 13

Page 17: EWD and the Art of Mobile Application Development

Dynamic OO Global Abstraction

• Underlying concept: any object and its properties can be easily modelled as a corresponding Mumps Global node, eg:

– patient.address.town– patient.address.zip– patient.name

– ^patient(id,”address”,”town”)=“New York”– ^patient(id,”address”,”zip”)=123456– ^patient(id,”name”)=“John Smith”

17Tuesday, 16 July 13

Page 18: EWD and the Art of Mobile Application Development

Document Storage

• Physical Global Nodes projected as GlobalNode objects in JavaScript

• GlobalNode objects have two key methods:– _setDocument()

• Maps a JSON document into an equivalent global as a sub-tree

– getDocument()• Maps a GlobalNode’s sub-tree into a JSON object

18Tuesday, 16 July 13

Page 19: EWD and the Art of Mobile Application Development

var gridData = [ 0: {col1: 1, col2: 1, name: ‘rec1’}, 1: {col1: 4, col2: 4, name: ‘rec4’} ]; session.$('newGridData')._setDocument(gridData);

JavaScript Document Storage

19Tuesday, 16 July 13

Page 20: EWD and the Art of Mobile Application Development

JavaScript Document Storage

^%zewdSession("session",4020,"newGridData",0,"col1")=1^%zewdSession("session",4020,"newGridData",0,"col2")=1^%zewdSession("session",4020,"newGridData",0,"name")="rec1"^%zewdSession("session",4020,"newGridData",1,"col1")=4^%zewdSession("session",4020,"newGridData",1,"col2")=4^%zewdSession("session",4020,"newGridData",1,"name")="rec4"

var gridData = [ 0: {col1: 1, col2: 1, name: ‘rec1’}, 1: {col1: 4, col2: 4, name: ‘rec4’} ]; session.$('newGridData')._setDocument(gridData);

20Tuesday, 16 July 13

Page 21: EWD and the Art of Mobile Application Development

The key ingredients

• Mumps as one of the most powerful and proven NoSQL databases available:– high scalability, high performance

• Projected as a JSON database• Accessible via JavaScript

– using Node.js to provide server-side environment

– using native interface in Cache

21

21Tuesday, 16 July 13

Page 22: EWD and the Art of Mobile Application Development

One more key piece of magic

• WebSockets– HTML5 standard– bi-directional, event-driven socket connection

• between browser & back-end– JSON messaging between browser and back-

end– generally being found to be faster than HTTP/

Ajax– No polling!

22

22Tuesday, 16 July 13

Page 23: EWD and the Art of Mobile Application Development

And so to EWD Lite

• 100% JavaScript/JSON framework– JSON-based WebSocket messaging between

browser & back-end• no more HTTP/Ajax

– JavaScript for browser-side and back-end logic

– Mumps as a Native JSON database

• EWD Lite packages this all up and makes it easy to use

23

23Tuesday, 16 July 13

Page 24: EWD and the Art of Mobile Application Development

EWD Lite Architecture

24

24Tuesday, 16 July 13

Page 25: EWD and the Art of Mobile Application Development

EWD Lite Architecture

25

Note: WebSockets connect browsersto Node.js Master Process, not toCaché or GT.M

25Tuesday, 16 July 13

Page 26: EWD and the Art of Mobile Application Development

EWD Development

26

100%JavaScript

26Tuesday, 16 July 13

Page 27: EWD and the Art of Mobile Application Development

EWD Lite Messaging

27

EventOccurs

27Tuesday, 16 July 13

Page 28: EWD and the Art of Mobile Application Development

EWD Lite Messaging

28

JSONMessageCreated

28Tuesday, 16 July 13

Page 29: EWD and the Art of Mobile Application Development

EWD Lite Messaging

29

MessageSent

29Tuesday, 16 July 13

Page 30: EWD and the Art of Mobile Application Development

EWD Lite Messaging

30

MessageReceived

atback-end

30Tuesday, 16 July 13

Page 31: EWD and the Art of Mobile Application Development

EWD Lite Messaging

31

MessageHandler

fired

31Tuesday, 16 July 13

Page 32: EWD and the Art of Mobile Application Development

EWD Lite Messaging

32

_setDocument()

32Tuesday, 16 July 13

Page 33: EWD and the Art of Mobile Application Development

EWD Lite Messaging

33

_getDocument()

33Tuesday, 16 July 13

Page 34: EWD and the Art of Mobile Application Development

EWD Lite Messaging

34

Messagesentby

back-end

34Tuesday, 16 July 13

Page 35: EWD and the Art of Mobile Application Development

EWD Lite Messaging

35

MessageReceived

bybrowser

35Tuesday, 16 July 13

Page 36: EWD and the Art of Mobile Application Development

EWD Lite Messaging

36

JSONMessage

EventHandler

Fires

36Tuesday, 16 July 13

Page 37: EWD and the Art of Mobile Application Development

EWD Lite Messaging

37

ModifyUI

37Tuesday, 16 July 13

Page 38: EWD and the Art of Mobile Application Development

Send message from browser

38

EWD.sockets.sendMessage({ type: "sendHelloWorld", params: { text: 'Hello World!', sender: 'Rob', date: new Date().toUTCString() } });

38Tuesday, 16 July 13

Page 39: EWD and the Art of Mobile Application Development

Send message from browser

39

EWD.sockets.sendMessage({ type: "sendHelloWorld", params: { text: 'Hello World!', sender: 'Rob', date: new Date().toUTCString() } });

User-defined type39Tuesday, 16 July 13

Page 40: EWD and the Art of Mobile Application Development

Send message from browser

40

EWD.sockets.sendMessage({ type: "sendHelloWorld", params: { text: 'Hello World!', sender: 'Rob', date: new Date().toUTCString() } });

JSON payload40Tuesday, 16 July 13

Page 41: EWD and the Art of Mobile Application Development

Back-end Module

41

module.exports = { onSocketMessage: function(ewd) { var wsMsg = ewd.webSocketMessage; var type = wsMsg.type; var params = wsMsg.params; var sessid = ewd.session.$('ewd_sessid')._value; }};

41Tuesday, 16 July 13

Page 42: EWD and the Art of Mobile Application Development

Back-end Module

42

module.exports = { onSocketMessage: function(ewd) { var wsMsg = ewd.webSocketMessage; var type = wsMsg.type; var params = wsMsg.params; var sessid = ewd.session.$('ewd_sessid')._value; }};

Message Handler: fires whenevera message is received

42Tuesday, 16 July 13

Page 43: EWD and the Art of Mobile Application Development

Back-end Module

43

module.exports = { onSocketMessage: function(ewd) { var wsMsg = ewd.webSocketMessage; var type = wsMsg.type; var payload = wsMsg.params; var sessid = ewd.session.$('ewd_sessid')._value; if (type === 'sendHelloWorld') { // do whatever is required with payload return {received: true}; } }}; Handle the message we

sent from browser

43Tuesday, 16 July 13

Page 44: EWD and the Art of Mobile Application Development

Back-end Module

44

module.exports = { onSocketMessage: function(ewd) { var wsMsg = ewd.webSocketMessage; var type = wsMsg.type; if (type === 'sendHelloWorld') { var savedMsg = new ewd.mumps.GlobalNode('myMessage', []); savedMsg._setDocument(wsMsg); return {savedInto: ‘^myMessage'}; } }};

Saves the entire messageinto ^myMessage

44Tuesday, 16 July 13

Page 45: EWD and the Art of Mobile Application Development

Back-end Module

45

module.exports = { onSocketMessage: function(ewd) { var wsMsg = ewd.webSocketMessage; var type = wsMsg.type; if (type === 'sendHelloWorld') { var savedMsg = new ewd.mumps.GlobalNode('myMessage', []); savedMsg._setDocument(wsMsg); return {savedInto: ‘^myMessage'}; } }};

Returns a sendHelloWorldmessage back to browser

45Tuesday, 16 July 13

Page 46: EWD and the Art of Mobile Application Development

Browser-side Handler

46

EWD.onSocketMessage = function(messageObj) { if (messageObj.type === 'sendHelloWorld') { var text = 'Your message was successfully saved into ' + messageObj.message.savedInto; document.getElementById('response').innerHTML = text; setTimeout(function() { document.getElementById('response').innerHTML = ''; },2000); } };

Built-in Event Handler function

46Tuesday, 16 July 13

Page 47: EWD and the Art of Mobile Application Development

Browser-side Handler

47

EWD.onSocketMessage = function(messageObj) { if (messageObj.type === 'sendHelloWorld') { var text = 'Your message was successfully saved into ' + messageObj.message.savedInto; document.getElementById('response').innerHTML = text; setTimeout(function() { document.getElementById('response').innerHTML = ''; },2000); } };

Just like at the back-end!

47Tuesday, 16 July 13

Page 48: EWD and the Art of Mobile Application Development

Browser-side Handler

48

EWD.onSocketMessage = function(messageObj) { if (messageObj.type === 'sendHelloWorld') { var text = 'Your message was successfully saved into ' + messageObj.message.savedInto; document.getElementById('response').innerHTML = text; setTimeout(function() { document.getElementById('response').innerHTML = ''; },2000); } };

Modify the UI

48Tuesday, 16 July 13

Page 49: EWD and the Art of Mobile Application Development

No Polling!

• With WebSockets, the back-end can send a message at any time to:– a specific browser– all browsers running a specific EWD Lite

application– all currently-connected browsers

49

49Tuesday, 16 July 13

Page 50: EWD and the Art of Mobile Application Development

Back-end sending a message

50

var savedMsg = new ewd.mumps.GlobalNode('myMessage', []); ewd.sendWebSocketMsg({ type: 'savedMessage', message: savedMsg._getDocument() });

50Tuesday, 16 July 13

Page 51: EWD and the Art of Mobile Application Development

Invoking legacy Mumps code

• Can invoke functions from within the back-end JavaScript module:

51

var result = ewd.mumps.function('getPatientVitals^MyEHR', params.patientId, params.date);

This is the equivalent of the Mumps code:

set result=$$getPatientVitals^MyEHR(patientId,date)

51Tuesday, 16 July 13

Page 52: EWD and the Art of Mobile Application Development

Built-in Secure Web Services

• JSON-based web service interface– HTTP(S) request– application/json response

• Secured using HMAC-SHA-based signatures– based on Amazon Web Services– registered users must have an Access Id and

Secret Key

52

52Tuesday, 16 July 13

Page 53: EWD and the Art of Mobile Application Development

Example Web Service

53

webServiceExample: function(ewd) { var patient = new ewd.mumps.GlobalNode('CLPPats', [ewd.query.id]); if (!patient._exists) return {error: 'Patient ' + ewd.query.id + ' does not exist'}; return patient._getDocument(); }

https://192.168.1.89:8080/json/demo/webServiceExample? id=1233& accessId=rob12kjh1i23& timestamp=Wed, 19 Jun 2013 14:14:35 GMT& signature=P0bIakNehj2TkuadxbKRsIgJCGIhY1EvntJdSce5XvQ=

Node.js EWD Lite Web Service client:npm install ewdliteclient

53Tuesday, 16 July 13

Page 54: EWD and the Art of Mobile Application Development

Example Web Service

54

webServiceExample: function(ewd) { var patient = new ewd.mumps.GlobalNode('CLPPats', [ewd.query.id]); if (!patient._exists) return {error: 'Patient ' + ewd.query.id + ' does not exist'}; return patient._getDocument(); }

https://192.168.1.89:8080/json/demo/webServiceExample? id=1233& accessId=rob12kjh1i23& timestamp=Wed, 19 Jun 2013 14:14:35 GMT& signature=P0bIakNehj2TkuadxbKRsIgJCGIhY1EvntJdSce5XvQ=

Node.js EWD Lite Web Service client:npm install ewdliteclient

The perfect architecture tosupport VSA

54Tuesday, 16 July 13

Page 55: EWD and the Art of Mobile Application Development

EWD Lite v “classic” EWD• 100% JavaScript

– no direct use of Mumps code– no Mumps routines to install and configure– works with InterSystems’ GlobalsDB

• Static pages of HTML and JavaScript– not an “server pages” technology– no compilation stage

• Not a tag-based development environment• Works with any and all JavaScript frameworks,

or hand-crafted HTML• No HTTP / Ajax

55

55Tuesday, 16 July 13

Page 56: EWD and the Art of Mobile Application Development

EWD Lite requirements

• Ideally browsers that support HTML5 WebSockets– however, EWD Lite uses Node.js socket.io

library• emulates websockets using other techniques if not

available• even works with old versions of Internet Explorer!

56

56Tuesday, 16 July 13

Page 57: EWD and the Art of Mobile Application Development

Licensing & Availability

• Apache 2

• https://github.com/robtweed/ewdGateway2

• Installing on Node.js:– npm install ewdgateway2

57

57Tuesday, 16 July 13

Page 58: EWD and the Art of Mobile Application Development

Getting Started• http://gradvs1.mgateway.com/download/EWDLite.pdf

• Mike Clayton’s Ubuntu Installer– Node.js– EWD Lite– GlobalsDB

• Training Course: – VistA Expo, Seattle: October 19-21– http://www.vistaexpo.net/class_ewd.html

58

58Tuesday, 16 July 13

Page 59: EWD and the Art of Mobile Application Development

EWD Lite

Rob TweedM/Gateway Developments Ltd

Twitter: @rtweedEmail: [email protected]

59Tuesday, 16 July 13