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 | 8 March 2017
|
28 |
|
29 | */
|
30 |
|
31 | var mpv = require('./mpv');
|
32 | var pas;
|
33 |
|
34 | function getPatientData(patientId, session, callback) {
|
35 | var patient = session.data.$(['patients', patientId]);
|
36 | var data = {
|
37 | id: patient.$('id').value,
|
38 | name: patient.$('name').value,
|
39 | address: patient.$('address').value,
|
40 | dateOfBirth: patient.$('dateOfBirth').value,
|
41 | gender: patient.$('gender').value,
|
42 | department: patient.$('department').value,
|
43 | nhsNumber: patientId
|
44 | };
|
45 | callback([data]);
|
46 | return;
|
47 | }
|
48 |
|
49 | function advancedSearch(args, callback) {
|
50 |
|
51 | var body = args.req.body;
|
52 | var session = args.session;
|
53 | var patients = session.data.$('patients');
|
54 | var q = this;
|
55 |
|
56 | if (body.nhsNumber && body.nhsNumber !== '') {
|
57 | var patientId = body.nhsNumber;
|
58 | // if the patient database hasn't yet been cached, go get it now...
|
59 |
|
60 | if (!patients.exists) {
|
61 | mpv.getPatients.call(this, args, function() {
|
62 | getPatientData(patientId, session, callback);
|
63 | });
|
64 | return;
|
65 | }
|
66 | getPatientData(patientId, session, callback);
|
67 | return;
|
68 | }
|
69 |
|
70 | console.log('** running advanced search for ' + JSON.stringify(body));
|
71 |
|
72 | if (!pas) pas = require('../' + this.userDefined.rippleUser.pasModule);
|
73 |
|
74 | if (!patients.exists) {
|
75 | mpv.getPatients.call(this, args, function() {
|
76 | pas.advancedSearch.call(q, body, callback);
|
77 | });
|
78 | return;
|
79 | }
|
80 |
|
81 | pas.advancedSearch.call(this, body, callback);
|
82 |
|
83 | //callback({error: 'Not yet implemented'});
|
84 | return;
|
85 |
|
86 | }
|
87 |
|
88 | module.exports = advancedSearch;
|