|
| 1 | +/* |
| 2 | + * Copyright (c) 2014 LabKey Corporation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +//Created: 2-4-2021 R.Blasa |
| 8 | + |
| 9 | +Ext4.define('ONPRC_EHR.panel.ExamCasesHousingDataEntryPanel', { |
| 10 | + extend: 'EHR.panel.TaskDataEntryPanel', |
| 11 | + |
| 12 | + |
| 13 | + onBeforeSubmit: function(btn){ |
| 14 | + if (!btn || !btn.targetQC || ['Completed', 'Review Required'].indexOf(btn.targetQC) == -1){ |
| 15 | + return; |
| 16 | + } |
| 17 | + |
| 18 | + var store = this.storeCollection.getClientStoreByName('Clinical Remarks'); |
| 19 | + LDK.Assert.assertNotEmpty('Unable to find clinical remarks store', store); |
| 20 | + |
| 21 | + var ids = []; |
| 22 | + store.each(function(r){ |
| 23 | + if (r.get('Id')) |
| 24 | + ids.push(r.get('Id')) |
| 25 | + }, this); |
| 26 | + ids = Ext4.unique(ids); |
| 27 | + |
| 28 | + if (!ids.length) |
| 29 | + return; |
| 30 | + |
| 31 | + EHR.DemographicsCache.getDemographics(ids, function(ids, idMap){ |
| 32 | + var missingCases = []; |
| 33 | + Ext4.Array.forEach(ids, function(id){ |
| 34 | + if (idMap[id]){ |
| 35 | + var cases = idMap[id].getActiveCases(); |
| 36 | + if (!cases || !cases.length){ |
| 37 | + missingCases.push(id); |
| 38 | + } |
| 39 | + else { |
| 40 | + var found = false; |
| 41 | + Ext4.Array.forEach(cases, function(c){ |
| 42 | + if (c.category == 'Clinical' && c.isActive){ |
| 43 | + found = true; |
| 44 | + } |
| 45 | + }, this); |
| 46 | + |
| 47 | + if (!found){ |
| 48 | + missingCases.push(id); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + }, this); |
| 53 | + |
| 54 | + if (missingCases.length){ |
| 55 | + Ext4.Msg.confirm('No Case', 'There is no active clinical case for this animal, do you want to continue anyway?', function(val){ |
| 56 | + if (val == 'yes'){ |
| 57 | + this.onSubmit(btn, true); |
| 58 | + } |
| 59 | + else { |
| 60 | + |
| 61 | + } |
| 62 | + }, this); |
| 63 | + } |
| 64 | + else { |
| 65 | + this.onSubmit(btn, true); |
| 66 | + } |
| 67 | + }, this); |
| 68 | + |
| 69 | + return false; |
| 70 | + }, |
| 71 | + |
| 72 | + onStoreCollectionCommitComplete: function(sc, extraContext){ |
| 73 | + if (Ext4.Msg.isVisible()) |
| 74 | + Ext4.Msg.hide(); |
| 75 | + |
| 76 | + |
| 77 | + var store = sc.getClientStoreByName('housing'); |
| 78 | + LDK.Assert.assertNotEmpty('Unable to find housing store in HousingDataEntryPanel', store); |
| 79 | + |
| 80 | + if (extraContext && extraContext.successURL && store.getCount() > 0){ |
| 81 | + Ext4.Msg.confirm('Success', 'Do you want to view the room layout now? This will allow you to verify and/or change dividers', function(val){ |
| 82 | + window.onbeforeunload = Ext4.emptyFn; |
| 83 | + if (val == 'yes'){ |
| 84 | + |
| 85 | + var rooms = []; |
| 86 | + store.each(function(r){ |
| 87 | + if (r.get('room') && rooms.indexOf(r.get('room')) == -1){ |
| 88 | + rooms.push(r.get('room')); |
| 89 | + } |
| 90 | + }, this); |
| 91 | + window.location = LABKEY.ActionURL.buildURL('onprc_ehr', 'printRoom', null, {rooms: rooms}); |
| 92 | + |
| 93 | + } |
| 94 | + else { |
| 95 | + window.location = extraContext.successURL; |
| 96 | + } |
| 97 | + }, this); |
| 98 | + |
| 99 | + return; |
| 100 | + } |
| 101 | + |
| 102 | + this.callParent(arguments); |
| 103 | + } |
| 104 | + }); |
0 commit comments