Skip to content
This repository has been archived by the owner on Sep 11, 2019. It is now read-only.

Add Paging for VitalSign #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions lib/headings/headings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
Expand All @@ -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';
Expand Down
82 changes: 82 additions & 0 deletions lib/headings/vitalsignspaging.js
Original file line number Diff line number Diff line change
@@ -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: [email protected] |
| |
| 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;
31 changes: 31 additions & 0 deletions lib/headings/vitalsignspaging.sql
Original file line number Diff line number Diff line change
@@ -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
21 changes: 18 additions & 3 deletions lib/patients/patientHeadingTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/patients/spv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down