Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bot] Fast-forward for 23.11.7 #511

Merged
merged 3 commits into from
Feb 6, 2024
Merged
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
171 changes: 171 additions & 0 deletions WNPRC_EHR/resources/queries/study/blood.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
/*
* Copyright (c) 2018-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0
*/

require("ehr/triggers").initScript(this);
var LABKEY = require("labkey");

EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.AFTER_BECOME_PUBLIC, 'study', 'blood', function(errors, helper, row, oldRow){
if (row && row.additionalServices){
helper.getJavaHelper().createRequestsForBloodAdditionalServices(row.Id, row.date, row.project, row.account, row.performedby, row.additionalServices, (row.requestid||null));
}
});

var tube_types = {}

function onInit(event, helper){

// Grab all of the blood draws and weights being submitted in this transaction (packaged separately by the ExtJS
// client store so that we can use those values too for validation purposes, not just what's in the DB already
helper.decodeExtraContextProperty('bloodInTransaction');
helper.decodeExtraContextProperty('weightInTransaction');

helper.registerRowProcessor(function(helper, row){
if (!row)
return;

if (!row.Id || !row.quantity){
return;
}

var bloodInTransaction = helper.getProperty('bloodInTransaction');
bloodInTransaction = bloodInTransaction || {};
bloodInTransaction[row.Id] = bloodInTransaction[row.Id] || [];

var shouldAdd = true;
if (row.objectid){
LABKEY.ExtAdapter.each(bloodInTransaction[row.Id], function(r){
if (r.objectid == row.objectid){
if (r.quantity != row.quantity){
r.quantity = row.quantity;
}
else {
shouldAdd = false;
return false;
}
}
}, this);
}

if (shouldAdd){
bloodInTransaction[row.Id].push({
objectid: row.objectid,
date: row.date,
qcstate: row.QCState,
quantity: row.quantity
});
}

helper.setProperty('bloodInTransaction', bloodInTransaction);
});

LABKEY.Query.selectRows({
schemaName: 'ehr_lookups',
queryName: 'blood_tube_volumes',
success: function(res) {
for (var i = 0; i < res.rows.length; i++){
tube_types[res.rows[i].volume] = res.rows[i].tube_types
}
}
})

}

EHR.Server.TriggerManager.registerHandlerForQuery(EHR.Server.TriggerManager.Events.BEFORE_UPSERT, 'study', 'blood', function (helper, scriptErrors, row, oldRow) {
if (!helper.isETL() && row.date && !row.daterequested){
if (!oldRow || !oldRow.daterequested){
row.daterequested = row.date;
}
}

if (row.quantity === 0){
EHR.Server.Utils.addError(scriptErrors, 'quantity', 'This field is required', 'WARN');
}

if (!helper.isETL()){
if (row.date && !row.requestdate)
row.requestdate = row.date;

if (!row.quantity && row.num_tubes && row.tube_vol){
row.quantity = row.num_tubes * row.tube_vol;
}

if (!!tube_types && !!row.tube_type && !!row.tube_vol) {
//if the instructions are blank and tube type does not match the volume, force user to add a special instruction
var badTubeVol = false;
if (!row.instructions) {
if (tube_types[row.tube_vol] === undefined) {
badTubeVol = true;
} else {
if (tube_types[row.tube_vol].indexOf(row.tube_type) === -1) {
badTubeVol = true
}
}
if (badTubeVol){
EHR.Server.Utils.addError(scriptErrors, 'instructions', 'Tube volume "' + row.tube_vol + '" does not exist for tube type "' + row.tube_type + '". Please provide instructions for the custom volume and tube type combination.')
}
}
}

if (row.additionalServices) {
if (row.tube_type || row.tube_vol){
var tubeType = row.tube_type || null;
var quantity = row.quantity || 0;
var msgs = helper.getJavaHelper().validateBloodAdditionalServices(row.additionalServices, tubeType, quantity);
if (msgs && msgs.length){
LABKEY.ExtAdapter.each(msgs, function(msg){
EHR.Server.Utils.addError(scriptErrors, 'additionalServices', msg, 'INFO');
}, this);
}
}
}

if (row.quantity && row.tube_vol){
if (row.quantity != (row.num_tubes * row.tube_vol)){
EHR.Server.Utils.addError(scriptErrors, 'quantity', 'Quantity does not match Tube Volume X # Tubes', 'INFO');
EHR.Server.Utils.addError(scriptErrors, 'num_tubes', '# Tubes does not match Quantity / Tube Volume', 'INFO');
}
}

EHR.Server.Validation.checkRestraint(row, scriptErrors);

if (row.Id && row.date && row.quantity){
// volume is handled differently for requests vs actual draws
var volumeErrorSeverity;
if (EHR.Server.Security.getQCStateByLabel(row.QCStateLabel)['isRequest'] && !row.taskid)
volumeErrorSeverity = 'ERROR';
else
volumeErrorSeverity = 'INFO';

var map = helper.getProperty('bloodInTransaction');
var draws = [];
if (map && map[row.Id]){
draws = map[row.Id];
}

var weightMap = helper.getProperty('weightInTransaction');
var weights = [];
if (weightMap && weightMap[row.Id]){
weights = weightMap[row.Id];
}

if (row.objectid) {
var msg = helper.getJavaHelper().verifyBloodVolume(row.id, row.date, draws, weights, row.objectid || null, row.quantity);
if (msg != null) {
if (msg.toLowerCase().indexOf('unknown weight') > -1) {
volumeErrorSeverity = helper.getErrorSeverityForBloodDrawsWithoutWeight();
}

//TODO: change all future bloods draws to review required, if submitted for medical purpose.
EHR.Server.Utils.addError(scriptErrors, 'num_tubes', msg, volumeErrorSeverity);
EHR.Server.Utils.addError(scriptErrors, 'quantity', msg, volumeErrorSeverity);
}
}
else {
console.warn('objectid not provided for blood draw, cannot calculate allowable blood volume. this probably indicates an error with the form submitting these data')
}
}
}
});
42 changes: 33 additions & 9 deletions WNPRC_EHR/resources/web/wnprc_ehr/datasetButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,12 @@ WNPRC_EHR.DatasetButtons = new function(){
}, this)
},
failure: function(error){
console.log('failure');
console.log(error);
Ext4.Msg.hide();
Ext4.Msg.show({
title: "Error",
msg: error.message,
buttons: Ext4.MessageBox.OK,
icon: Ext4.MessageBox.ERROR
});
}
}

Expand Down Expand Up @@ -801,22 +804,43 @@ WNPRC_EHR.DatasetButtons = new function(){
toUpdate[rec['dataset/Label']].push(obj)
}, this);

for(var i in toUpdate){
let failure = false;
let errors;
for (const i in toUpdate){
multi.add(LABKEY.Query.updateRows, {
schemaName: 'study',
queryName: i,
rows: toUpdate[i],
scope: this,
failure: EHR.Utils.onError
success: function() {
},
failure: function(error) {
failure = true;
errors = error.errors;
}
});
}

multi.send(function(){
Ext4.Msg.hide();
dataRegion.selectNone();
if (!failure) {
Ext4.Msg.hide();
dataRegion.selectNone();

o.ownerCt.ownerCt.close();
dataRegion.refresh();
o.ownerCt.ownerCt.close();
dataRegion.refresh();
} else {
Ext4.Msg.hide();
let errorMsg = '';
for (let k = 0; k < errors.length; k++) {
errorMsg += errors[k].exception + ' for animal ' + errors[k].row.Id + '. '
}
Ext4.Msg.show({
title: "Error",
msg: errorMsg,
buttons: Ext4.MessageBox.OK,
icon: Ext4.MessageBox.WARNING
});
}
}, this);
}
},{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ private int getEventCode() {
public enum Species {
Rhesus (0),
Cynomolgus (1),
Marmoset (2)
Marmoset (2),
Pigtail (3)
;

private int _speciesCode;
Expand Down Expand Up @@ -96,6 +97,7 @@ public static PopulationChangeEvent newEvent(String Id, Date date, Date timestam
case "cynomolgus": species = Species.Cynomolgus; break;
case "rhesus": species = Species.Rhesus; break;
case "marmoset": species = Species.Marmoset; break;
case "pigtail": species = Species.Pigtail; break;
default:
throw new IllegalArgumentException(speciesString + " is not a valid species.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
<span>Marmoset <span class="badge">{{population.marmoset}}</span></span>
<strong> | </strong>
<span>Cynomolgus <span class="badge">{{population.cynomolgus}}</span></span>
<strong> | </strong>
<span>Pigtail <span class="badge">{{population.pigtail}}</span></span>
</span>
</div>
</div>
Expand All @@ -44,6 +46,9 @@
<li role="presentation">
<a href="#cynomolgus-tab" role="tab" data-toggle="tab">Cynomolgus</a>
</li>
<li role="presentation">
<a href="#pigtail-tab" role="tab" data-toggle="tab">Pigtail</a>
</li>
</ul>

<div class="tab-content">
Expand All @@ -56,6 +61,9 @@
<div role="tabpanel" class="tab-pane" id="cynomolgus-tab">
<species-tab params="species: 'Cynomolgus'"></species-tab>
</div>
<div role="tabpanel" class="tab-pane" id="pigtail-tab">
<species-tab params="species: 'Pigtail'"></species-tab>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -90,6 +98,9 @@
<li role="presentation">
<a href="#cynomolgus-details-tab" role="tab" data-toggle="tab">Cynomolgus</a>
</li>
<li role="presentation">
<a href="#pigtail-details-tab" role="tab" data-toggle="tab">Pigtail</a>
</li>
</ul>

<div class="col-xs-12" style="height: 20px"></div>
Expand All @@ -104,6 +115,9 @@
<div role="tabpanel" class="tab-pane" id="cynomolgus-details-tab">
<species-details-tab params="species: 'Cynomolgus'"></species-details-tab>
</div>
<div role="tabpanel" class="tab-pane" id="pigtail-details-tab">
<species-details-tab params="species: 'Pigtail'"></species-details-tab>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -509,7 +523,8 @@
WebUtils.VM.population = {
rhesus: getPopulationObject('Rhesus').pops.pop(),
marmoset: getPopulationObject('Marmoset').pops.pop(),
cynomolgus: getPopulationObject('Cynomolgus').pops.pop()
cynomolgus: getPopulationObject('Cynomolgus').pops.pop(),
pigtail: getPopulationObject('Pigtail').pops.pop()
}
})();
</script>
Expand Down
Loading