Category Archives: MUMPS

Intersystems Cache Fitbit Client API Demo

My Fitbit watch is my internet of things.

It keeps track of my steps, bpm, calories burned, activity and stationary periods.

The code attached to this blog is prototype software, but its intention is to not only retrieve your Fitbit data, but to demonstrate the processes and technologies that underpin OAuth 2.0.

More information about the Fitbit API can be found here:
https://dev.fitbit.com/uk

More information about Cache can be found here:
https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=GIC

A free version of Cache can be downloaded from here:
http://www.intersystems.com/library/software-downloads/

In order to run the demo, you’ll need to do the following:

1. You’ll need to Register an application using https://dev.fitbit.com/apps/new
Make sure the Callback URL uses port 2000.
For example: http://localhost:2000/csp/pstest/

2. After registering your app, the Fitbit web site will generate a Client ID and Client Secret (used in step 5).

3. Install cURL (if its not installed on your computer).
A copy of cURL for Windows can be downloaded from http://www.confusedbycode.com/curl/.
The official curl web site is https://curl.haxx.se/.

4. Download the code by clicking on the Code link at the bottom of this blog.
Extract the FB.xml file from the MS Word document, and copy it to C:\TEMP\.
Then, in a Cache Terminal:
ZN “USER” Write $SYSTEM.OBJ.Load(“C:\TEMP\FB.xml”,”ck”)

5. Execute the following code in the USER namespace, but replace YOUR-CLIENTID and YOUR-SECRET-QUESTION with your Fitbit credentials.
Set ^Fitbit.Config(“client_id”)=”YOUR-CLIENTID”
Set ^Fitbit.Config(“secret_question”)=”YOUR-SECRET-QUESTION”
Set ^Fitbit.Config(“redirect_uri”)=”http%3A%2F%2F127.0.0.1%3A57728%2Fcsp%2pstest%2″

6. Do ^FB in a Terminal session, which should launch IE and then write out your Fitbit profile in the terminal session.

USER>Do ^FB
Scanning for authorization code
GET /csp/pstest/?code=919056c646d9b5767a0798f6c6fdf5bc11ea89d8 HTTP/1.1
Accept: text/html, application/xhtml+xml, image/jxr, */*
Accept-Language: en-GB,en-US;q=0.7,en;q=0.3
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; LCJB; rv:11.0) like Gecko
Accept-Encoding: gzip, deflate
Host: localhost:2000
Connection: Keep-Alive
Cookie: state-9AD096D1-66A0-49EF-BB58-E1BE668C6139=DEEPSEE%3A; Username=_SYSTEM; nsstate.false.HSACCESS=; state-3013AF90-9846-4700-A77A-5DFF76B22D58=ENS%3A0; state-1F02C113-F836-4C97-A2C3-92FAE6C43E6F=SYSADM%3A0%2C0; state-0C5A7E6C-71EC-4605-9A63-3F4EBC41E404=XENS%3A; state-970DC7BC-04DF-4185-A672-5A744437CBA1=SYSEXP%3A; state-73C156CE-8D33-4FCD-B224-2F5108C53999=ENS%3A0; nsstate.false.HSPD=; state-B2A4AB48-DABD-4297-8ECD-60D4D31DCCB6=ENS%3A0

Paul Simon
Urban Boot (15,000 steps in a day)
15,000 steps in a day
Congrats on earning your first Urban Boot badge!

London Underground (250 lifetime miles)
250 lifetime miles
Whoa! You’ve earned the London Underground badge!

Castle (200 floors in a day)
200 floors in a day
Congrats on earning your first Castle badge!

Hot Air Balloon (2,000 lifetime floors)
2,000 lifetime floors
Yipee! You’ve earned the Hot Air Balloon badge!

Code

Enjoy!

How to implement an Intersystems Cache/Angular JS app, in less than 10 minutes!

Download and install TryCache from intersystems.com.

Create a new namespace called ANG.

Download the code by clicking on the code link at the bottom of this blog.

Use %GIF in a Cache Terminal window to restore the globals (J2.phonecat.GOF & JPHONE.GOF).

Import CacheCode.xml using Cache Studio.

Unzip the Angular JS code (angular-phonecat.7z) to C:\TEMP\angular-phonecat\.

You may need to modify a couple of lines of code in controllers.js, to reflect the web port in your Cache instance (the Angular JS code is currently using 57773).

Launch the Management Portal, and add two Web Applications,
System Administration >> Security >> Applications >> Web Applications

Angular

REST

Make sure each Web Application has an Application Role of %All.

Launch a browser and navigate to (57773 is the web port my local system is listening on),
http://localhost:57773/csp/ang/index.csp#/phones

code

All the Angular JS code has been taken from the official Angular tuitorial, which can be found at https://docs.angularjs.org/tutorial/.

Enjoy!

Standalone SMS (Spine Mini Services) client written in Cache

Developing NHS SPINE applications without any sand pit access is pretty much impossible.
I recently experienced this when I was asked to find out how the ITK works in Intersystems Ensemble.
However, after some head scratching and googling, I came across something called the TKW.
HSCIC use the Toolkit Workbench (TKW) to accredit suppliers, but more importantly, from a developers point of view, it simulates SPINE.
The code that I’ve attached to this blog is an example Spine Mini Services client written in Cache.
Before runnng the code, you’ll need to make sure that two instances of the TKW are running.
One of the instances needs to simulate the SMS middle ware, the other needs to simulate SPINE.
A copy of the TKW can be downloaded from http://developer.nhs.uk/testcentre/itk-testbench/.

1. Install Java-7 (the TKW is not compatible with Java-8).
2. You’ll need to install a version of the TKW that simulates SPINE, and a version that simulates the Spine Mini Services.
3. Restore the attached code using Cache Studio.
4. Run the following commands at a cmd prompt (the paths need to mirror your TKW installation directories).
java -jar C:\TKW-SMSP\TKW\tkw.jar -simulator C:\TKW-SMSP\TKW\config\SMSP_provider_MODULE\tk11111w_for_MTH.properties
java -jar C:\SpineTKW\TKW\tkw.jar -simulator C:\SpineTKW\TKW\config\SPINE_MTH_20111121\tkw.properties
5. *Launch tcptrace, listen on port 4847, destination port needs to be 4000.
6. In a terminal window D ##class(SMS.Client).Test()

You should then see this menu :-

1 – getPatientDetails_success
2 – verifyNHSNumber_success
3 – getNHSNumber_success
4 – getPatientDetailsBySearch_Simple_Trace_success
5 – getPatientDetailsBySearch_Advanced_Trace_success
6 – getPatientDetailsByNHSNumber_success
7 – verifyNHSNumber_MCCI
8 – verifyNHSNumber_SoapFault

“Exit” to quit

Enter (1-6):

After selecting a PDS interaction, the software will call the TKW and display the response.
Each option populates a PDS request that contains the test pack information that’s shipped with the TKW.

The message specifications for each client request can be downloaded from the TRUD (https://isd.hscic.gov.uk/trud3/user/guest/group/0/home).

*A copy of tcptrace can be downloaded from http://www.pocketsoap.com/tcptrace/.
If you don’t have Intersystems Cache installed, then you can download a copy of TryCache from http://www.intersystems.com/library/software-downloads/.

If you have any questions, please don’t hesitate to get in touch!

Click here to download the code.

Enjoy!

MUMPS/Cache HL7 To XML converter

In my quest to learn HL7 v2, I decided to write an HL7 to XML converter.
This seemed to be a good idea as I know XML.

The code is based on a C# code project article I found on the internet.

The C# code can be found here:
http://www.codeproject.com/Articles/29670/Converting-HL7-to-XML
I’ve attached two versions of the code, a Cache Object Script version, and a MUMPS version.
The MUMPS version was coded in MSM (Micronetics Standard MUMPS).
In order to make the MSM code run in say GTM or MV1, all you’ll need to do is change the way the code reads and writes the documents to the OS.

To run the MUMPS code:

D ^HL7TOXML.

To run the COS code:

D ##class(J2.HL7ToXml.HL7ToXML).Go(“C:\TEMP\Test1.hl7”)

The code I’ve written is not perfect, it was primarily written to provide me with a better understanding of HL7 v2.

Click here to download the code and example HL7 files.

Enjoy!

A web-interface to GT.M, or Less is More

It’s taken me a while to work out a way of communicating with GTM rather than using NodeM, but I recently stumbled across a web page that offered an alternative, http://71.174.62.16/demo/TestCGI.htm.

The web page was written by a guy called Ed de Moel.

The first thing to do is to write and compile some C code.

I’ve attached some C source code that will need tweaking before you have a go at compiling it.

You’ll probably need to change the gtmdir, appdir, gtmdb variables to mirror your GTM configuration.

Copy the C source code into a directory, and then run the following command in order to compile the code.

gcc hello.c -o gtm3 (this makes an application called gtm3).

The next thing to do is to install apache2, at a terminal prompt do this,

sudo apt-get install apache2

The gtm3 application will then need copying to /usr/local/apache2/cgi-bin/.

I used the following Linux commands to do the copy,

cd /usr/lib/cgi-bin (this is the default location for cgi scripts).

sudo cp /home/vista/tmp/gtm3 gtm3

If you look at the C code it executes a MUMPS routine called TestCGI2.

One important bit of configuration was to make sure that mumps.dat permissions were set to read/write, otherwise the C code will fall over whilst trying to run the MUMPS code.

To demonstrate how cool this is, I wrote some MUMPS code to display 5,000 HTML cells – it renders fast!

http://192.168.2.15/cgi-bin/gtm3?mumps=^FRED2

TestCGI2, hello, FRED2

Thanks Ed!

MUMPS.NET for Dummies

A while ago I decided to take a look at ASP.NET, so I bought a book called ASP.NET for Dummies (ISBN 0764508660).

I did not particularly care which ASP.NET language I used, I was more interested in how .NET worked in an internet browser.

I read the book, did one or two examples and then proceeded to have a go at changing some of the books VB.NET code to connect to a MUMPS database.

I modified the Classy Classified example that’s in chapters 18, 19 and 21 to read or write to a MUMPS DB using an assembly which I wrote in C#.

The software uses MSM Activate to communicate with Cache, therefore you’ll need to make sure that Activate is configured before running the MUMPS Classifieds web application.

To configure MSM Activate all you’ll need to do is to right click on the Cache cube which sits in the windows system tray, click on the Management Portal >> Security >> Services >> %Service MSMActivate, and then finally click on the “Service Enabled” check box >> Save.

The Classy Classified VB ASP.NET code was compiled using Visual Web Developer 2010 Express, which is free to download.

Use the %RI and %GI utilities in a cache terminal window to restore the MUMPS routine and global attached to this blog.

The VB.NET code connects to a namespace called PAU, you’ll obviously need to change the connection details in the VB code if you restore the routine and global into a different namespace.

Click on the MUMPS.Net for Dummies link in order to download the code.

Enjoy!

MUMPS.Net for Dummies

MUMPS_Classifieds

MUMPS and Node.

I’d like to share some Node JS and MUMPS code to demonstrate how easy it is to write a web application using these two technologies.  I’m using Node JS and Micronetics Standard MUMPS, running on MS Windows.

Download a copy of Node from nodejs.org and install it.

The node code listens on port 8080 and proxies the request onto port 4012.

To run the node code, cd to the folder where TCPPROXY.txt is stored, and type node TCPPROXY.txt.

Restore the MUMPS code into an MSM database, and then job HTTPSRV using the MUMPS job command.

The Football League sample application serves up HTML which allows users to run a league.

There’s no web page that allows a user to setup leagues and clubs, but this can be easily done by using the following MUMPS.

Season/League.

S ^LALIGA(“L”,”4″)=”2012/2013″
S ^LALIGA(“L”,4,2)=”HARROGATE AND DISTRICT JFL (U14) – DIV 2″

Football Club.

S ^LALIGA(“C”,1)=”PANNAL SPORTS”
S ^LALIGA(“C”,2)=”KNARESBOROUGH”

Once these globals have been setup, you can then use a browser to enter the football league data.

http://192.168.2.10:8080/fix?mumps=FIXFRED3&season=4&league=2&date=28.10.2012

The above URL will allow a user to setup fixtures for 28.10.2012.

http://192.168.2.10:8080/ires2?mumps=IRES2FRED3&season=4&league=2&date=62758

The above URL will allow a user to enter the results for 28.10.2012.

http://192.168.2.10:8080/table?mumps=TABLEFRED3&season=4&league=2

The above URL will allow a user to view a league table.

Here’s some example global data.

^LALIGA(“C”,1)=”PANNAL SPORTS”
^LALIGA(“C”,2)=”KNARESBOROUGH”
^LALIGA(“C”,3)=”WIGTON MOOR”
^LALIGA(“F”,4,2)=”1″
^LALIGA(“F”,4,2,62758,1)=”1~2″
^LALIGA(“L”,4)=”2012/2013″
^LALIGA(“L”,4,2)=”HARROGATE AND DISTRICT JFL (U14) – DIV 2″
^LALIGA(“L”,4,2,62758,1)=”1~2~1~1″

Use the link below to download the code.

code

Enjoy!