UNPKG

3.75 kBJavaScriptView Raw
1/*
2
3 ----------------------------------------------------------------------------
4 | qewd-ripple: QEWD-based Middle Tier for Ripple OSI |
5 | |
6 | Copyright (c) 2016-17 Ripple Foundation Community Interest Company |
7 | All rights reserved. |
8 | |
9 | http://rippleosi.org |
10 | Email: code.custodian@rippleosi.org |
11 | |
12 | Author: Rob Tweed, M/Gateway Developments Ltd |
13 | |
14 | Licensed under the Apache License, Version 2.0 (the "License"); |
15 | you may not use this file except in compliance with the License. |
16 | You may obtain a copy of the License at |
17 | |
18 | http://www.apache.org/licenses/LICENSE-2.0 |
19 | |
20 | Unless required by applicable law or agreed to in writing, software |
21 | distributed under the License is distributed on an "AS IS" BASIS, |
22 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
23 | See the License for the specific language governing permissions and |
24 | limitations under the License. |
25 ----------------------------------------------------------------------------
26
27 10 March 2017
28
29*/
30
31var pas;
32
33module.exports = {
34
35 init: function() {
36 console.log('pasModule: ' + this.userDefined.rippleUser.pasModule);
37 pas = require('../' + this.userDefined.rippleUser.pasModule);
38 if (pas.init) pas.init.call(this);
39 },
40
41 getPatients: function(args, callback) {
42 var session = args.session;
43 var patientCache = session.data.$('patients');
44 //var patientCache = new this.documentStore.DocumentNode('ripplePatients');
45
46 // Have we already fetched the patients from the PAS and cached them?
47
48 if (patientCache.exists) {
49 var patients = {};
50 patientCache.forEachChild(function(no, patient) {
51 var record = patient.getDocument();
52 if (!record.nhsNumber) {
53 // something wrong with the cache - need to clear it up...
54 patientCache.delete();
55 return true; // abort the forEach loop and let it drop through to build the cache again
56 }
57
58 //console.log('**** record for ' + no + ' = ' + JSON.stringify(record));
59 //console.log('********************************');
60 delete record.headings;
61 delete record.headingIndex;
62 delete record.clinicalStatements;
63 record.nhsNumber = record.nhsNumber.toString();
64 record.id = record.id.toString();
65 record.dateOfBirth = parseInt(record.dateOfBirth);
66 if (record.pasNo) record.pasNo = record.pasNo.toString();
67 //patients.push(record);
68 patients[record.id] = record;
69 });
70 if (patientCache.exists) {
71 if (callback) callback(patients);
72 return;
73 }
74 }
75 pas.getPatients.call(this, function(patients) {
76 if (patients.error) {
77 callback(patients);
78 }
79 else {
80 patientCache.delete();
81 patientCache.setDocument(patients);
82 if (callback) callback(patients);
83 }
84 });
85 }
86};