Some change to prior PR#7429 (#7447)
[openemr.git] / templates / prescription / general_edit.html
blob91ab7456d9163bcab2468f5af164e022af6edb86
1 {**
2 * Prescription edit
4 * @package OpenEMR
5 * @link http://www.open-emr.org
6 * @author Brady Miller <brady.g.miller@gmail.com>
7 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
8 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
9 *}
10 <!DOCTYPE html>
11 <html>
12 <head>
14 {headerTemplate assets='datetime-picker|select2'}
16 <script>
19 function my_process_lookup(drug, rxcode = '') {
20 // Pass the variable
21 let newOption = new Option(drug, drug, true, true);
22 $("#rxnorm_drugcode").val(rxcode);
23 $('#drug').append(newOption).trigger('change');
24 $('#hiddendiv').hide();
25 $("#hiddendiv").html( "&nbsp;" );
28 </script>
29 <!---Gen Look up-->
31 <script>
33 // This holds all the default drug attributes.
34 // This was html escaped previously
36 var drugopts = [{if !empty($DRUG_ATTRIBUTES)}{$DRUG_ATTRIBUTES}{/if}];
39 // Helper to choose an option from its value.
40 function selchoose(sel, value) {
41 var o = sel.options;
42 for (let i = 0; i < o.length; ++i) {
43 o[i].selected = (o[i].value == value);
47 // Fill in default values when a drop-down drug is selected.
48 function drugselected(sel) {
49 var f = document.forms[0];
50 var i = f.drug_id.selectedIndex - 1;
51 if (i >= 0) {
52 var d = drugopts[i];
53 var newOption = new Option(d[0], d[0], true, true);
54 $('#drug').append(newOption).trigger('change');
55 selchoose(f.form, d[1]);
56 f.dosage.value = d[2];
57 f.size.value = d[3];
58 f.rxnorm_drugcode.value = d[11];
59 selchoose(f.unit, d[4]);
60 selchoose(f.route, d[5]);
61 selchoose(f.interval, d[6]);
62 selchoose(f.substitute, d[7]);
63 f.quantity.value = d[8];
64 f.disp_quantity.value = d[8];
65 selchoose(f.refills, d[9]);
66 f.per_refill.value = d[10];
70 // Invoke the popup to dispense a drug.
71 function dispense() {
72 var f = document.forms[0];
73 dlgopen('interface/drugs/dispense_drug.php' +
74 '?drug_id=' + {$prescription->get_drug_id()|js_url} +
75 '&prescription=' + encodeURIComponent(f.id.value) +
76 '&quantity=' + encodeURIComponent(f.disp_quantity.value) +
77 '&fee=' + encodeURIComponent(f.disp_fee.value),
78 '_blank', 400, 200);
81 function quantityChanged() {
82 var f = document.forms[0];
83 f.per_refill.value = f.quantity.value;
84 if (f.disp_quantity) {
85 f.disp_quantity.value = f.quantity.value;
89 </script>
91 </head>
92 <body id="prescription_edit">
93 <div class="container">
94 <form name="prescribe" id="prescribe" method="post" action="{$FORM_ACTION}" >
95 <table>
96 <tr>
97 <td class="title font-weight-bold">{xlt t='Add'}/{xlt t='Edit'}&nbsp;</td>
98 <td>
99 <a id="save" href=# onclick="submitfun();" class="btn btn-primary btn-sm btn-save">{xlt t='Save'}</a>
100 {if !empty($DRUG_ARRAY_VALUES)}
101 &nbsp; &nbsp; &nbsp; &nbsp;
102 {if $prescription->get_refills() >= $prescription->get_dispensation_count()}
103 <input type="submit" name="disp_button"class='btn btn-primary btn-sm my-0 mr-1 ml-1' value="{xla t='Save and Dispense'}" />
104 <input class="input-sm" type="text" name="disp_quantity" size="2" maxlength="10" value="{$DISP_QUANTITY|attr}" />
105 units, {$GBL_CURRENCY_SYMBOL|text}
106 <input class="input-sm" type="text" name="disp_fee" size="5" maxlength="10" value="{$DISP_FEE|attr}" />
107 {else}&nbsp;
108 {xlt t='prescription has reached its limit of'} {$prescription->get_refills()|text} {xlt t='refills'}.
109 {/if}
110 {/if}
111 <a id="back" class='btn btn-secondary btn-sm btn-back' href="controller.php?prescription&list&id={$prescription->patient->id|attr_url}">{xlt t='Back'}</a>
112 </td>
113 </tr>
114 </table>
116 {if $GLOBALS.enable_amc_prompting}
117 <div class='float-right border mr-5'>
118 <div class='float-left m-1'>
119 {amcCollect amc_id='e_prescribe_amc' patient_id=$prescription->patient->id object_category='prescriptions' object_id=$prescription->id}
120 {if not $amcCollectReturn}
121 <input type="checkbox" id="escribe_flag" name="escribe_flag" />
122 {else}
123 <input type="checkbox" id="escribe_flag" name="escribe_flag" checked="checked" />
124 {/if}
125 <span class="text">{xlt t='E-Prescription?'}</span><br />
127 {amcCollect amc_id='e_prescribe_chk_formulary_amc' patient_id=$prescription->patient->id object_category='prescriptions' object_id=$prescription->id}
128 {if not $amcCollectReturn}
129 <input type="checkbox" id="checked_formulary_flag" name="checked_formulary_flag" />
130 {else}
131 <input type="checkbox" id="checked_formulary_flag" name="checked_formulary_flag" checked="checked" />
132 {/if}
133 <span class="text">{xlt t='Checked Drug Formulary?'}</span><br />
135 {amcCollect amc_id='e_prescribe_cont_subst_amc' patient_id=$prescription->patient->id object_category='prescriptions' object_id=$prescription->id}
136 {if not $amcCollectReturn}
137 <input type="checkbox" id="controlled_substance_flag" name="controlled_substance_flag" />
138 {else}
139 <input type="checkbox" id="controlled_substance_flag" name="controlled_substance_flag" checked="checked" />
140 {/if}
141 <span class="text">{xlt t='Controlled Substance?'}</span><br />
142 </div>
143 </div>
144 {/if}
146 <div class="form-group mt-3">
147 <label>{xlt t='Currently Active'}</label>
148 <input class="input-sm" type="checkbox" name="active" value="1"{if $prescription->get_active() > 0} checked{/if} />
149 </div>
150 <div class="form-group mt-3">
151 <label>{xlt t='Starting Date'}</label>
152 <input type="text" size="10" class="datepicker form-control" name="start_date" id="start_date" value="{$prescription->start_date|oeFormatShortDate|attr}" />
153 </div>
154 <div class="form-group mt-3">
155 <label>{xlt t='Provider'}</label>
156 {html_options class="input-sm form-control" name="provider_id" options=$prescription->provider->utility_provider_array() selected=$prescription->provider->get_id()}
157 <input type="hidden" name="patient_id" value="{$prescription->patient->id|attr}" />
158 </div>
159 <div class="form-group mt-3">
160 <label class="mr-2">{xlt t='Drug'}</label>
161 <div class="form-check-inline">
162 <label class="form-check-label" title="{xlt t='Search from native inventory drugs table'}">
163 <input type="radio" class="form-check-input" name="rxcui_select" checked />{xlt t='Use Default'}
164 </label>
165 </div>
166 <div class="form-check-inline">
167 <label class="form-check-label" title="{xlt t='Search from external RxNorm table. Vocabulary RXNORM'}">
168 <input type="radio" class="form-check-input" name="rxcui_select" {if empty($RXNORMS_AVAILABLE)} disabled{else} checked{/if} />{xlt t='Use RxNorm'}
169 </label>
170 </div>
171 <div class="form-check-inline">
172 <label class="form-check-label" title="{xlt t='Search from native loaded RxCUI table.'}">
173 <input type="radio" class="form-check-input" name="rxcui_select" {if empty($RXCUI_AVAILABLE)}disabled{else} checked{/if} />{xlt t='Use RxCUI'}
174 </label>
175 </div>
176 <select class="input-sm form-control" type="input" name="drug" id="drug"></select>
177 <a href="javascript:;" id="druglookup" class="small" name="B4" onclick="$('#hiddendiv').show(); document.getElementById('hiddendiv').innerHTML='&lt;iframe src=&quot;controller.php?prescription&amp;lookup&amp;drug=&quot; width=&quot;100%&quot;height=&quot;75&quot; scrolling=&quot;no&quot; frameborder=&quot;no&quot;&gt;&lt;/iframe&gt;'">
178 ({xlt t='Search Web API'})
179 </a>
180 <div class="jumbotron jumbotron-fluid" id="hiddendiv" style="display: none">&nbsp;</div>
181 </div>
182 {if !empty($DRUG_ARRAY_VALUES)}
183 <div class="form-group mt-3">
184 <label>&nbsp; {xlt t='in-house'}</label>
185 <select class="input-sm form-control" name="drug_id" onchange="drugselected(this)">
186 {html_options values=$DRUG_ARRAY_VALUES output=$DRUG_ARRAY_OUTPUT selected=$prescription->get_drug_id()}
187 </select>
188 <input type="hidden" name="rxnorm_drugcode" value="{$prescription->rxnorm_drugcode|attr}">
189 </div>
190 {/if}
191 <div class="form-group mt-3">
192 <label>{xlt t='Quantity'}</label>
193 <input class="input-sm form-control" type="text" name="quantity" id="quantity" size="10" maxlength="31"
194 value="{$prescription->quantity|attr}" onchange="quantityChanged()" />
195 </div>
196 {if $SIMPLIFIED_PRESCRIPTIONS && !$prescription->size}
197 <div class="form-group row mt-3 d-none">
198 {else}
199 <div class="form-group row mt-3">
200 {/if}
201 <div class="col-12">
202 <label>{xlt t='Medicine Units'}</label>
203 </div>
204 <div class="col">
205 <input class="input-sm form-control" type="text" name="size" id="size" size="11" maxlength="10" value="{$prescription->size|attr}"/>
206 </div>
207 <div class="col">
208 <select class="input-sm form-control" name="unit" id="unit">{html_options options=$prescription->unit_array selected=$prescription->unit}</select>
209 </div>
210 </div>
211 <div class="form-group row mt-3">
212 <div class="col-12">
213 <label>{xlt t='Directions'}</label>
214 </div>
215 {if $SIMPLIFIED_PRESCRIPTIONS && !$prescription->form && !$prescription->route && !$prescription->interval}
216 <input class="input-sm form-control" type="text" name="dosage" id="dosage" size="30" maxlength="100" value="{$prescription->dosage|attr}" />
217 <input type="hidden" name="form" id="form" value="0" />
218 <input type="hidden" name="route" id="route" value="0" />
219 <input type="hidden" name="interval" id="interval" value="0" />
220 {else}
221 <div class="col">
222 <input class="input-sm form-control" type="text" name="dosage" id="dosage" size="2" maxlength="10" value="{$prescription->dosage|attr}"/>
223 </div>
224 <div class="col">
225 {xlt t='in'}
226 </div>
227 <div class="col">
228 <select class="input-sm form-control" name="form" id="form">{html_options options=$prescription->form_array selected=$prescription->form}</select>
229 </div>
230 <div class="col">
231 <select class="input-sm form-control" name="route" id="route">{html_options options=$prescription->route_array selected=$prescription->route}</select>
232 </div>
233 <div class="col">
234 <select class="input-sm form-control" name="interval" id="interval">{html_options options=$prescription->interval_array selected=$prescription->interval}</select>
235 </div>
236 {/if}
237 </div>
238 <div class="form-group row mt-3">
239 <div class="col-12">
240 <label>{xlt t='Refills'}</label>
241 </div>
242 <div class="col">
243 {html_options name="refills" class="form-control" options=$prescription->refills_array selected=$prescription->refills}
244 </div>
245 {if $SIMPLIFIED_PRESCRIPTIONS}
246 <input type="hidden" id="per_refill" name="per_refill" value="{$prescription->per_refill|attr}" />
247 {else}
248 <div class="col">
249 &nbsp; &nbsp; # {xlt t='of tablets'}:
250 </div>
251 <div class="col">
252 <input class="input-sm form-control" type="text" id="per_refill" name="per_refill" size="2" maxlength="9" value="{$prescription->per_refill|attr}" />
253 </div>
254 {/if}
255 </div>
256 <div class="form-group mt-3">
257 <label>{xlt t='Notes'}</label>
258 <textarea class="form-control" name="note" cols="30" rows="1" wrap="virtual">{$prescription->note|text}</textarea>
259 </div>
260 <div class="form-group row mt-3">
261 {if $WEIGHT_LOSS_CLINIC}
262 <label>{xlt t='Substitution'}</label>
263 {html_options name="substitute" class="form-control" options=$prescription->substitute_array selected=$prescription->substitute}
264 {else}
265 <div class="col-12">
266 <label>{xlt t='Add to Medication List'}</label>
267 </div>
268 <div class="col">
269 {html_radios class="input-sm" name="medication" options=$prescription->medication_array selected=$prescription->medication}
270 </div>
271 <div class="col">
272 {html_options class="input-sm form-control" name="substitute" options=$prescription->substitute_array selected=$prescription->substitute}
273 </div>
274 {/if}
275 </div>
277 <input type="hidden" name="id" value="{$prescription->id|attr}" />
278 <input type="hidden" name="process" value="{$PROCESS|attr}" />
279 <input type="hidden" id="rxnorm_drugcode" name="rxnorm_drugcode" value="{$prescription->rxnorm_drugcode|attr}" />
281 <script>
282 {if !empty($ENDING_JAVASCRIPT)}{$ENDING_JAVASCRIPT}{/if}
283 </script>
284 </form>
285 </div>
287 <!-- for the fancy jQuery stuff -->
288 <script>
290 function submitfun() {
291 top.restoreSession();
292 if (CheckForErrors(this)) {
293 document.forms["prescribe"].submit();
295 else {
296 return false;
300 function iframetopardiv(string){
301 var name=string
302 document.getElementById('drug').value=name;
303 $("#hiddendiv").html( "&nbsp;" );
304 $('#hiddendiv').hide();
307 function cancelParlookup () {
308 $('#hiddendiv').hide();
309 $("#hiddendiv").html( "&nbsp;" );
312 $(function () {
314 $("#save,#back").on("click",function(){
315 $("#clearButton",window.parent.document).css("display", "none");
316 $("#backButton",window.parent.document).css("display", "none");
317 $("#addButton",window.parent.document).css("display", "");
321 {if $GLOBALS.weno_rx_enable}
323 $("#drug").select2({
324 ajax: {
325 url: "library/ajax/drug_autocomplete/search.php",
326 dataType: 'json',
327 data: function(params) {
328 return {
329 csrf_token_form: {$CSRF_TOKEN_FORM|js_escape},
330 term: params.term
334 processResults: function(data) {
335 return {
336 results: $.map(data, function(item, index) {
337 return {
338 text: item,
339 id: index,
340 value: item
344 return x;
346 cache: true,
347 minimumInputLength: 3
350 {else}
352 $("#drug").select2({
353 ajax: {
354 url: "library/ajax/prescription_drugname_lookup.php",
355 dataType: 'json',
356 data: function(params) {
357 return {
358 csrf_token_form: {$CSRF_TOKEN_FORM|js_escape},
360 term: params.term,
361 use_rxnorm: document.prescribe.rxcui_select[1].checked,
362 use_rxcui: document.prescribe.rxcui_select[2].checked
365 processResults: function(data) {
366 return {
367 results: $.map(data, function(item, index) {
368 return {
369 text: item['display_name'],
370 id: item['id_name'],
371 value: item['display_name']
375 return x;
377 cache: true
379 tags: true,
380 minimumInputLength: 3
382 {/if}
383 {if $prescription->drug}
385 // Show the current drug name in the select
386 var newOption = new Option({$prescription->drug|js_escape}, {$prescription->drug|js_escape}, true, true);
387 $('#drug').append(newOption).trigger('change');
388 {/if}
391 $("#drug").focus();
392 $("#prescribe").submit(function() { return CheckForErrors(this) });
395 // check the form for required fields before submitting
396 var CheckForErrors = function(eObj) {
397 // REQUIRED FIELDS
398 if (CheckRequired('drug') == false) { return false; }
399 if (CheckRequired('quantity') == false) { return false; }
400 //if (CheckRequired('unit') == false) { return false; }
401 //if (CheckRequired('size') == false) { return false; }
402 if (CheckRequired('dosage') == false) { return false; }
403 //if (CheckRequired('form') == false) { return false; }
404 //if (CheckRequired('route') == false) { return false; }
405 //if (CheckRequired('interval') == false) { return false; }
407 return top.restoreSession();
410 function CheckRequired(objID) {
412 // for text boxes
413 if ($('#'+objID).is('input')) {
414 if ($('#'+objID).val() == "") {
415 alert({xlj t='Missing a required field and will be highlighted'});
416 $('#'+objID).css("backgroundColor", "pink");
417 return false;
421 // for select boxes
422 if ($('#'+objID).is('select')) {
423 if ($('#'+objID).val() == "0") {
424 alert({xlj t='Missing a required field'});
425 $('#'+objID).css("backgroundColor", "pink");
426 return false;
430 return true;
433 $(document).on('select2:select', 'select#drug', function(e) {
434 let idx = this.selectedIndex;
435 if (idx === 0) {
436 // already selected.
437 return false;
439 let optionText = document.getElementById("drug").options[idx].text;
440 let rxcode = (optionText.split('(RxCUI:').pop().split(')')[0]).trim();
441 $("#rxnorm_drugcode").val(rxcode);
444 $(function () {
445 {datetimepickerSupport input='format'}
446 });</script>
450 </body>
451 </html>