MedMij Nodejs library
Nodejs implementation of the MedMij OpenPGO building blocks.
Version Guidance
This library follows Semantic Versioning.
The versions of the Afspraken set are mapped to the versions of the library as follows:
Installation
npm install node-medmij
Design
The MedMij implementation for lists consists of four classes. First, there is a generic List class that takes care of downloading XML and schema files from URLs, validating XML's against schema and translating XML into Javascript objects. Three classes specialise the List class: they inherit from the generic List class and add specific methods for Whitelist, Zorgaanbiederslijst and OAuth client list.
It is assumed that XML Schema's are on the local filesystem, and that XML files are retrieved from a URL. Locations are configurable in a settings file.
Whitelist
On creation the whitelist object downloads the whitelist schema, the whitelist itself and then validates the whitelist against the schema.
var medmij = require('node-medmij');
new medmij.Whitelist(function(error, whitelist) {
});
Settings are in src/settings.js
. Following settings are relevant for whitelist parsing:
{
...
"whitelistSchemaPath": "./src/xsd/MedMij_Whitelist.xsd",
"whitelistURL": "https://afsprakenstelsel.medmij.nl/download/...",
...
}
To get the complete whitelist:
console.log(whitelist.getList());
To validate a hostname:
console.log(whitelist.isMedMijNode('iets'));
Zorgaanbiederslijst
On creation the ZAL object downloads the Zorgaanbiederslijst schema, the Zorgaanbiederslijst itself and then validates the list against the schema.
var medmij = require('node-medmij');
new medmij.ZAL(function(error, zal) {
});
Settings are in src/settings.js
. Following settings are relevant for the Zorgaanbiederslijst:
{
...
"zalSchemaPath" : "./src/xsd/MedMij_Zorgaanbiederslijst.xsd",
"zalURL" : "https://afsprakenstelsel.medmij.nl/download/...",
...
}
To get the complete Zorgaanbiederslijst:
console.log(zal.getList());
To get a zorgaanbieder by name:
console.log(zal.getZorgaanbieder('umcharderwijk@medmij'));
The name is matched with Zorgaanbiedernaam
.
OpenAuth Client list
On creation the OCL object downloads the OAuth Client List schema, the client list itself and then validates the list against the schema.
var medmij = require('node-medmij');
new medmij.OCL(function(error, ocl) {
});
Settings are in src/settings.js
. Following settings are relevant for the client list:
{
...
"oclSchemaPath": "./src/xsd/MedMij_OAuthclientlist.xsd",
"oclURL": "https://afsprakenstelsel.medmij.nl/download/..."
}
To get the complete client list:
console.log(ocl.getList());
To get a OAuth client by name:
console.log(ocl.getClient('De Enige Echte PGO'));
The name is matched with OAuthclientOrganisatienaam
.
Getting zorgaanbieder OAuth URL
To obtain the URL to which to redirect a zorggebruiker for authentication:
const zao = new medmij.ZAOAuth();
console.log(zao.makeRedirectURI("https://pgo.example.com/oauth", "abc", "xyz"));
Obtaining access tokens
Getting the URL at which to request an access token:
const PGOOAuth = medmij.PGOOAuth;
const ZAL = medmij.ZAL;
const OCL = medmij.OCL;
new OCL(function (error, ocl) {
if (error) {
console.log(`Error instantiating OCL: ${error}`);
} else {
new ZAL(function (error, zal) {
if (error) {
console.log(`Error instantiating ZAL: ${error}`);
} else {
const za = zal.getZorgaanbieder("umcharderwijk@medmij");
const geg = za.Gegevensdiensten[0].Gegevensdienst[0];
const authEndpoint = geg.AuthorizationEndpoint[0].AuthorizationEndpointuri[0];
const zorgaanbieder = "umcharderwijk";
const gegID = geg.GegevensdienstId[0];
const oc = ocl.getClient("De Enige Echte PGO");
console.log(pgoGlobal.makeAuthURL(authEndpoint, zorgaanbieder, gegID, oc.Hostname[0], "https://pgo.example.com/oauth", "abcd").href);
}
});
}
});
Requesting the access token at the obtained URL:
new ZAL(function (error, zal) {
if (error) {
console.log(`Error instantiating ZAL: ${error}`);
} else {
const za = zal.getZorgaanbieder("umcharderwijk@medmij");
const geg = za.Gegevensdiensten[0].Gegevensdienst[0];
const tokenEndpoint = geg.TokenEndpoint[0].TokenEndpointuri[0];
const zorgaanbieder = "umcharderwijk";
const gegID = geg.GegevensdienstId[0];
pgoGlobal.getAccessToken(tokenEndpoint, "xyz", "https://pgo.example.com/oauth", function(token, error) {
if (error) {
console.log(`Error obtaining access token: ${error}`);
} else {
console.log(token);
}
});
}
});
Gegevensdienstnamenlijst
On creation the GNL object downloads the Gegevensdienstnamenlijst schema, the Gegevensdienstnamenlijst itself and then validates the list against the schema.
var medmij = require('node-medmij');
new medmij.GNL(function(error, gnl) {
});
Settings are in src/settings.js
. Following settings are relevant for the Gegevensdienstnamenlijst:
{
...
"gnlSchemaPath" : "./src/xsd/MedMij_Gegevensdienstnamenlijst.xsd",
"gnlURL" : "https://afsprakenstelsel.medmij.nl/download/...",
...
}
To get the complete Gegevensdienstnamenlijst:
console.log(gnl.getList());
To get a map from id to gegevensdienstnaam use the following:
console.log(gnl.getMapIdToName());
Testing
Unit tests are written using jasmine-node. These can be started as follows:
npm test
or
jasmine-node ./test
Settings
Current settings for schema and example files follow the MedMij Afsprakenstelsel.
Dependencies
jasmine-node
: for unit testingnode-xmllint
: for validating XML files against schemasxml2js
: for translating XML files to Javascript objects
Licenses
Source code: GNU AFFERO GENERAL PUBLIC LICENSE Version 3
Content: Creative Commons Attribution Sharealike 4.0 International