From 69f8dbded15ca15cddc3aa9f605af0857a36e51b Mon Sep 17 00:00:00 2001 From: ZuzooVn Date: Tue, 27 Jun 2017 17:17:51 +0700 Subject: [PATCH] Add Paging for VitalSign --- lib/headings/headings.js | 19 +++++-- lib/headings/vitalsignspaging.js | 82 +++++++++++++++++++++++++++++ lib/headings/vitalsignspaging.sql | 31 +++++++++++ lib/patients/patientHeadingTable.js | 21 ++++++-- lib/patients/spv.js | 2 +- 5 files changed, 147 insertions(+), 8 deletions(-) create mode 100755 lib/headings/vitalsignspaging.js create mode 100755 lib/headings/vitalsignspaging.sql diff --git a/lib/headings/headings.js b/lib/headings/headings.js index 4f32bfa..8697b57 100644 --- a/lib/headings/headings.js +++ b/lib/headings/headings.js @@ -49,6 +49,7 @@ var headings = { personalnotes: require(path + 'personalnotes'), vaccinations: require(path + 'vaccinations'), vitalsigns: require(path + 'vitalsigns'), + vitalsignspaging: require(path + 'vitalsignspaging'), clinicalnotes: require(path + 'clinicalnotes'), counts: require(path + 'counts'), transfers: { @@ -136,8 +137,8 @@ function getHeading(nhsNo, heading, session, openEHRSessions, callback) { else { if (!heading.query[queryType]) queryType = 'aql'; query = heading.query[queryType]; - //console.log('**** host = ' + host + '; queryType = ' + queryType + ': heading = ' + heading.name + '; query = ' + JSON.stringify(query)); - if (query.length === 0) { + // console.log('**** host = ' + host + '; queryType = ' + queryType + ': heading = ' + heading.name + '; query = ' + JSON.stringify(query)); + if (!query || query.length === 0) { params.hostSpecific[host]['qs'][queryType] = ''; params.dontAsk[host] = true; console.log('**** dontAsk set to true for ' + host); @@ -151,7 +152,9 @@ function getHeading(nhsNo, heading, session, openEHRSessions, callback) { if (typeof query === 'string') { var subs = { patientId: patientId, - ehrId: openEHR.getEhrId(patientId, host) + ehrId: openEHR.getEhrId(patientId, host), + offset: session.offset, + fetch: session.fetch } params.hostSpecific[host]['qs'][queryType] = template.replace(query, subs); } @@ -174,7 +177,15 @@ function getHeading(nhsNo, heading, session, openEHRSessions, callback) { if (body && body.resultSet) { //console.log('setting patientHeading global for ' + heading.name + ' / host ' + host); var patient = session.data.$(['patients', nhsNo]); - var patientHeading = patient.$(['headings', heading.name, host]); + var headingName; + if (session.offset && session.offset.length > 0 && session.fetch && session.fetch.length > 0){ + // paging + headingName = heading.name + "?offset=" + session.offset + "&fetch=" + session.fetch; + }else { + // none paging + headingName = heading.name; + } + var patientHeading = patient.$(['headings', headingName, host]); //var patientHeading = new q.documentStore.DocumentNode('ripplePatients', [nhsNo, "headings", heading.name, host]); if (body.resultSet.length === 0) { patientHeading.value = 'empty'; diff --git a/lib/headings/vitalsignspaging.js b/lib/headings/vitalsignspaging.js new file mode 100755 index 0000000..5e7d8a0 --- /dev/null +++ b/lib/headings/vitalsignspaging.js @@ -0,0 +1,82 @@ +/* + + ---------------------------------------------------------------------------- + | qewd-ripple: QEWD-based Middle Tier for Ripple OSI | + | | + | Copyright (c) 2016-17 Ripple Foundation Community Interest Company | + | All rights reserved. | + | | + | http://rippleosi.org | + | Email: code.custodian@rippleosi.org | + | | + | Author: Dinesh Patel - Leidos | + | | + | Licensed under the Apache License, Version 2.0 (the "License"); | + | you may not use this file except in compliance with the License. | + | You may obtain a copy of the License at | + | | + | http://www.apache.org/licenses/LICENSE-2.0 | + | | + | Unless required by applicable law or agreed to in writing, software | + | distributed under the License is distributed on an "AS IS" BASIS, | + | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | + | See the License for the specific language governing permissions and | + | limitations under the License. | + ---------------------------------------------------------------------------- + + 8 June 2017 + +*/ + +var heading = { + name: 'vitalsignspaging', + textFieldName: 'author', + headingTableFields: ['author', 'dateCreated', 'newsScore', 'respirationRate', 'oxygenSupplemental', + 'heartRate', 'temperature', 'levelOfConsciousness', 'systolicBP', 'diastolicBP', 'oxygenSaturation'], + get: { + + helperFunctions: { + getOnAir: function(onAir) { + var oppBool = (onAir !== 'true'); + return oppBool.toString(); + }, + getLevelOfConsciousness: function(levelOfConsciousnessCode) { + switch (levelOfConsciousnessCode) { + case "at0005": + return "Alert"; + break; + case "at0006": + return "Voice"; + break; + case "at0007": + return "Pain"; + break; + case "at0008": + return "Unresponsive"; + break; + default: + return 'Not known' + } + } + }, + + transformTemplate: { + respirationRate: '{{respiratoryrate}}', + oxygenSupplemental: '=> getOnAir(onair)', + heartRate: '{{heartrate}}', + temperature: '{{temperature}}', + levelOfConsciousness: '=> getLevelOfConsciousness(levelofconsciousnesscode)', + systolicBP: '{{systolic}}', + diastolicBP: '{{diastolic}}', + oxygenSaturation: '{{oxygensats}}', + newsScore: '{{newsscore}}', + author: '{{author}}', + dateCreated: '=> getRippleTime(date_created)', + source: '=> getSource()', + sourceId: '=> getUid(uid)' + } + + } +}; + +module.exports = heading; diff --git a/lib/headings/vitalsignspaging.sql b/lib/headings/vitalsignspaging.sql new file mode 100755 index 0000000..31394e2 --- /dev/null +++ b/lib/headings/vitalsignspaging.sql @@ -0,0 +1,31 @@ +SELECT + ehr.entry.composition_id as uid, + ehr.event_context.start_time as date_created, + ehr.party_identified.name as author, + ehr.entry.entry #>> '{/composition[openEHR-EHR-COMPOSITION.encounter.v1 and name/value=''Vital Signs Observations''],/content[openEHR-EHR-SECTION.vital_signs.v1],0,/items[openEHR-EHR-OBSERVATION.respiration.v1],0,/data[at0001],/events,/events[at0002],0,/state[at0022],/items[openEHR-EHR-CLUSTER.ambient_oxygen.v0],0,/items[at0057],0,/value,value}' + as onAir, + ehr.entry.entry #>> '{/composition[openEHR-EHR-COMPOSITION.encounter.v1 and name/value=''Vital Signs Observations''],/content[openEHR-EHR-SECTION.vital_signs.v1],0,/items[openEHR-EHR-OBSERVATION.respiration.v1],0,/data[at0001],/events,/events[at0002],0,/data[at0003],/items[at0004],0,/value,magnitude}' + as respiratoryRate, + ehr.entry.entry #>> '{/composition[openEHR-EHR-COMPOSITION.encounter.v1 and name/value=''Vital Signs Observations''],/content[openEHR-EHR-SECTION.vital_signs.v1],0,/items[openEHR-EHR-OBSERVATION.pulse.v1],0,/data[at0002],/events,/events[at0003],0,/data[at0001],/items[at0004],0,/value,magnitude}' + as heartRate, + ehr.entry.entry #>> '{/composition[openEHR-EHR-COMPOSITION.encounter.v1 and name/value=''Vital Signs Observations''],/content[openEHR-EHR-SECTION.vital_signs.v1],0,/items[openEHR-EHR-OBSERVATION.body_temperature.v1],0,/data[at0002],/events,/events[at0003],0,/data[at0001],/items[at0004],0,/value,magnitude}' + as temperature, + ehr.entry.entry #>> '{/composition[openEHR-EHR-COMPOSITION.encounter.v1 and name/value=''Vital Signs Observations''],/content[openEHR-EHR-SECTION.vital_signs.v1],0,/items[openEHR-EHR-OBSERVATION.avpu.v1],0,/data[at0001],/events,/events[at0002],0,/data[at0003],/items[at0004],0,/value,definingCode,codeString}' + as levelOfConsciousnessCode, + ehr.entry.entry #>> '{/composition[openEHR-EHR-COMPOSITION.encounter.v1 and name/value=''Vital Signs Observations''],/content[openEHR-EHR-SECTION.vital_signs.v1],0,/items[openEHR-EHR-OBSERVATION.blood_pressure.v1],0,/data[at0001],/events,/events[at0006],0,/data[at0003],/items[at0004],0,/value,magnitude}' + as systolic, + ehr.entry.entry #>> '{/composition[openEHR-EHR-COMPOSITION.encounter.v1 and name/value=''Vital Signs Observations''],/content[openEHR-EHR-SECTION.vital_signs.v1],0,/items[openEHR-EHR-OBSERVATION.blood_pressure.v1],0,/data[at0001],/events,/events[at0006],0,/data[at0003],/items[at0005],0,/value,magnitude}' + as diastolic, + ehr.entry.entry #>> '{/composition[openEHR-EHR-COMPOSITION.encounter.v1 and name/value=''Vital Signs Observations''],/content[openEHR-EHR-SECTION.vital_signs.v1],0,/items[openEHR-EHR-OBSERVATION.indirect_oximetry.v1],0,/data[at0001],/events,/events[at0002],0,/data[at0003],/items[at0006],0,/value,numerator}' + as oxygenSats, + ehr.entry.entry #>> '{/composition[openEHR-EHR-COMPOSITION.encounter.v1 and name/value=''Vital Signs Observations''],/content[openEHR-EHR-SECTION.vital_signs.v1],0,/items[openEHR-EHR-OBSERVATION.news_uk_rcp.v1],0,/data[at0001],/events,/events[at0002],0,/data[at0003],/items[at0028],0,/value,magnitude}' + as newsScore + + FROM ehr.entry + INNER JOIN ehr.composition ON ehr.composition.id=ehr.entry.composition_id + INNER JOIN ehr.event_context ON ehr.event_context.composition_id=ehr.entry.composition_id + INNER JOIN ehr.party_identified ON ehr.composition.composer=ehr.party_identified.id + WHERE (ehr.composition.ehr_id = '{{ehrId}}') + AND (ehr.entry.template_id = 'IDCR - Vital Signs Encounter.v1') + ORDER BY date_created DESC + offset {{offset}} rows FETCH NEXT {{fetch}} rows only \ No newline at end of file diff --git a/lib/patients/patientHeadingTable.js b/lib/patients/patientHeadingTable.js index 9d1d468..b99e0ba 100644 --- a/lib/patients/patientHeadingTable.js +++ b/lib/patients/patientHeadingTable.js @@ -55,9 +55,22 @@ var headings = headingsLib.headings; */ -function getHeadingTable(patientId, heading, session, callback) { +function getHeadingTable(args, patientId, heading, session, callback) { var q = this; + // Paging heading + var paging = false; + if (args.req && args.req.query) { + var offset = args.req.query.offset; + var fetch = args.req.query.fetch; + if (offset && offset.length !== 0 && fetch && fetch.length !== 0 ) { + if(heading.indexOf('paging') == -1) heading += 'paging'; + paging = true; + session.offset = offset; + session.fetch = fetch; + } + } + var patient = session.data.$(['patients', patientId]); //var patient = new this.documentStore.DocumentNode('ripplePatients', [patientId]); var nhsNo = patientId; @@ -70,7 +83,9 @@ function getHeadingTable(patientId, heading, session, callback) { return; } - var patientHeading = patient.$(['headings', headings[heading].name]); + //customize heading name + var endHeading = paging ? '?offset=' + offset + '&fetch=' + fetch : ''; + var patientHeading = patient.$(['headings', headings[heading].name + endHeading]); //var patientHeading = new this.documentStore.DocumentNode('ripplePatients', [patientId, 'headings', headings[heading].name]); if (!patientHeading.exists) { // fetch it and cache it in the QEWD session @@ -92,7 +107,7 @@ function getHeadingTable(patientId, heading, session, callback) { //console.log('**** trying again!'); // Now the headings are in cache, re-run to retrieve and transform them - getHeadingTable.call(q, patientId, heading, session, callback); + getHeadingTable.call(q, args, patientId, heading, session, callback); } }); }); diff --git a/lib/patients/spv.js b/lib/patients/spv.js index 7f2a7a2..a529582 100644 --- a/lib/patients/spv.js +++ b/lib/patients/spv.js @@ -65,7 +65,7 @@ module.exports = { return; } - patientHeadingTable.call(this, args.patientId, args.heading, args.session, callback) + patientHeadingTable.call(this, args, args.patientId, args.heading, args.session, callback) }, postHeading: function(args, callback) {