forked from LibreHealthIO/lh-ehr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.inc.php
3268 lines (3000 loc) · 120 KB
/
options.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// Copyright (C) 2016-2017 Terry Hill <[email protected]>
// Copyright (C) 2007-2014 Rod Roark <[email protected]>
// Copyright © 2010 by Andrew Moore <[email protected]>
// Copyright © 2010 by "Boyd Stephen Smith Jr." <[email protected]>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// Functions for managing the lists and layouts
//
// Note: there are translation wrappers for the lists and layout labels
// at library/translation.inc.php. The functions are titled
// xl_list_label() and xl_layout_label() and are controlled by the
// $GLOBALS['translate_lists'] and $GLOBALS['translate_layout']
// flags in globals.php
// Documentation for layout_options.edit_options:
//
// A = Age as years or "xx month(s)"
// B = Gestational age as "xx week(s) y day(s)"
// C = Capitalize first letter of each word (text fields)
// D = Check for duplicates in New Patient form
// G = Graphable (for numeric fields in forms supporting historical data)
// H = Read-only field copied from static history (this is obsolete)
// L = Lab Order ("ord_lab") types only (address book)
// N = Show in New Patient form
// O = Procedure Order ("ord_*") types only (address book)
// P = Default to previous value when current value is not yet set
// R = Distributor types only (address book)
// T = Use description as default Text
// U = Capitalize all letters (text fields)
// V = Vendor types only (address book)
// 0 = Read Only - the input element's "disabled" property is set
// 1 = Write Once (not editable when not empty) (text fields)
// 2 = Show descriptions instead of codes for billing code input
require_once(dirname(dirname(__FILE__)) ."/interface/globals.php");
if ($GLOBALS['mod_nn'] == true){
require_once(dirname(dirname(__FILE__)) . "/modules/nation_notes/nn_library_options.inc");}
else{
require_once("formdata.inc.php");
require_once("formatting.inc.php");
require_once("user.inc");
require_once("patient.inc");
require_once("lists.inc");
require_once(dirname(dirname(__FILE__)) . "/custom/code_types.inc.php");
$date_init = "";
function get_pharmacies() {
return sqlStatement("SELECT d.id, d.name, a.line1, a.city, " .
"p.area_code, p.prefix, p.number FROM pharmacies AS d " .
"LEFT OUTER JOIN addresses AS a ON a.foreign_id = d.id " .
"LEFT OUTER JOIN phone_numbers AS p ON p.foreign_id = d.id " .
"AND p.type = 2 " .
"ORDER BY name, area_code, prefix, number");
}
function optionalAge($frow, $date, &$asof) {
$asof = '';
if (empty($date)) return '';
$date = substr($date, 0, 10);
if (strpos($frow['edit_options'], 'A') !== FALSE) {
$format = 0;
}
else if (strpos($frow['edit_options'], 'B') !== FALSE) {
$format = 3;
}
else {
return '';
}
if (strpos($frow['form_id'], 'LBF') === 0) {
$tmp = sqlQuery("SELECT date FROM form_encounter WHERE " .
"pid = ? AND encounter = ? ORDER BY id DESC LIMIT 1",
array($GLOBALS['pid'], $GLOBALS['encounter']));
if (!empty($tmp['date'])) $asof = substr($tmp['date'], 0, 10);
}
$prefix = ($format ? xl('Gest age') : xl('Age')) . ' ';
return $prefix . oeFormatAge($date, $asof, $format);
}
// Function to generate a drop-list.
//
function generate_select_list($tag_name, $list_id, $currvalue, $title, $empty_name = ' ', $class = '',
$onchange = '', $tag_id = '', $custom_attributes = null, $multiple = false, $backup_list = '') {
$s = '';
$tag_name_esc = attr($tag_name);
if ($multiple) {
$tag_name_esc = $tag_name_esc . "[]";
}
$s .= "<select name='$tag_name_esc'";
if ($multiple) {
$s .= " multiple='multiple'";
}
$tag_id_esc = $tag_name_esc;
if ($tag_id != '') {
$tag_id_esc = attr($tag_id);
}
if ($multiple) {
$tag_id_esc = $tag_id_esc . "[]";
}
$s .= " id='$tag_id_esc'";
if ($class) {
$class_esc = attr($class);
$s .= " class='$class_esc'";
}
if ($onchange) {
$s .= " onchange='$onchange'";
}
if ($custom_attributes != null && is_array ( $custom_attributes )) {
foreach ( $custom_attributes as $attr => $val ) {
if (isset ( $custom_attributes [$attr] )) {
$s .= " " . attr($attr) . "='" . attr($val) . "'";
}
}
}
$selectTitle = attr($title);
$s .= " title='$selectTitle'>";
$selectEmptyName = xlt($empty_name);
if ($empty_name)
$s .= "<option value=''>" . $selectEmptyName . "</option>";
// List order depends on language translation options.
// (Note we do not need to worry about the list order in the algorithm
// after the below code block since that is where searches for exceptions
// are done which include inactive items or items from a backup
// list; note these will always be shown at the bottom of the list no matter the
// chosen order.)
$lang_id = empty($_SESSION['language_choice']) ? '1' : $_SESSION['language_choice'];
// sort by title
if (($lang_id == '1' && !empty($GLOBALS['skip_english_translation'])) || !$GLOBALS['translate_lists']) {
// do not translate
if ($GLOBALS['gb_how_sort_list'] == '0') {
// order by seq
$order_by_sql = "seq, title";
}
else { //$GLOBALS['gb_how_sort_list'] == '1'
// order by title
$order_by_sql = "title, seq";
}
$lres = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity=1 ORDER BY " . $order_by_sql, array($list_id));
}
else {
// do translate
if ($GLOBALS['gb_how_sort_list'] == '0') {
// order by seq
$order_by_sql = "lo.seq, IF(LENGTH(ld.definition),ld.definition,lo.title)";
}
else { //$GLOBALS['gb_how_sort_list'] == '1'
// order by title
$order_by_sql = "IF(LENGTH(ld.definition),ld.definition,lo.title), lo.seq";
}
$lres = sqlStatement("SELECT lo.option_id, lo.is_default, " .
"IF(LENGTH(ld.definition),ld.definition,lo.title) AS title " .
"FROM list_options AS lo " .
"LEFT JOIN lang_constants AS lc ON lc.constant_name = lo.title " .
"LEFT JOIN lang_definitions AS ld ON ld.cons_id = lc.cons_id AND " .
"ld.lang_id = ? " .
"WHERE lo.list_id = ? AND lo.activity=1 " .
"ORDER BY " . $order_by_sql, array($lang_id, $list_id));
}
$got_selected = FALSE;
while ( $lrow = sqlFetchArray ( $lres ) ) {
$selectedValues = explode ( "|", $currvalue );
$optionValue = attr($lrow ['option_id']);
$s .= "<option value='$optionValue'";
if ($multiple && (strlen ( $currvalue ) == 0 && $lrow ['is_default']) || (strlen ( $currvalue ) > 0 && in_array ( $lrow ['option_id'], $selectedValues ))) {
$s .= " selected";
$got_selected = TRUE;
}
$optionLabel = text($lrow ['title']);
$s .= ">$optionLabel</option>\n";
}
/*
To show the inactive item in the list if the value is saved to database
*/
if (!$got_selected && strlen($currvalue) > 0)
{
$lres_inactive = sqlStatement("SELECT * FROM list_options " .
"WHERE list_id = ? AND activity = 0 AND option_id = ? ORDER BY seq, title", array($list_id, $currvalue));
$lrow_inactive = sqlFetchArray($lres_inactive);
if($lrow_inactive['option_id']) {
$optionValue = htmlspecialchars( $lrow_inactive['option_id'], ENT_QUOTES);
$s .= "<option value='$optionValue' selected>" . htmlspecialchars( xl_list_label($lrow_inactive['title']), ENT_NOQUOTES) . "</option>\n";
$got_selected = TRUE;
}
}
if (!$got_selected && strlen ( $currvalue ) > 0 && !$multiple) {
$list_id = $backup_list;
$lrow = sqlQuery("SELECT title FROM list_options WHERE list_id = ? AND option_id = ?", array($list_id,$currvalue));
if ($lrow > 0 && !empty($backup_list)) {
$selected = text(xl_list_label($lrow ['title']));
$s .= "<option value='$currescaped' selected> $selected </option>";
$s .= "</select>";
} else {
$s .= "<option value='$currescaped' selected>* $currescaped *</option>";
$s .= "</select>";
$fontTitle = xlt('Please choose a valid selection from the list.');
$fontText = xlt( 'Fix this' );
$s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
}
} else if (!$got_selected && strlen ( $currvalue ) > 0 && $multiple) {
//if not found in main list, display all selected values that exist in backup list
$list_id = $backup_list;
$got_selected_backup = FALSE;
if (!empty($backup_list)) {
$lres_backup = sqlStatement("SELECT * FROM list_options WHERE list_id = ? AND activity = 1 ORDER BY seq, title", array($list_id));
while ( $lrow_backup = sqlFetchArray ( $lres_backup ) ) {
$selectedValues = explode ( "|", $currvalue );
$optionValue = attr($lrow_backup['option_id']);
if ($multiple && (strlen ( $currvalue ) == 0 && $lrow_backup ['is_default']) ||
(strlen ( $currvalue ) > 0 && in_array ( $lrow_backup ['option_id'], $selectedValues ))) {
$s .= "<option value='$optionValue'";
$s .= " selected";
$optionLabel = text(xl_list_label($lrow_backup ['title']));
$s .= ">$optionLabel</option>\n";
$got_selected_backup = TRUE;
}
}
}
if (!$got_selected_backup) {
$s .= "<option value='$currescaped' selected>* $currescaped *</option>";
$s .= "</select>";
$fontTitle = xlt('Please choose a valid selection from the list.');
$fontText = xlt( 'Fix this' );
$s .= " <font color='red' title='$fontTitle'>$fontText!</font>";
}
}
else {
$s .= "</select>";
}
return $s;
}
// $frow is a row from the layout_options table.
// $currvalue is the current value, if any, of the associated item.
//
function generate_form_field($frow, $currvalue) {
global $rootdir, $date_init, $ISSUE_TYPES, $code_types,$condition_str;
$DateFormat = DateFormatRead();
$currescaped = htmlspecialchars($currvalue, ENT_QUOTES);
$data_type = $frow['data_type'];
$field_id = $frow['field_id'];
$list_id = $frow['list_id'];
$backup_list = $frow['list_backup_id'];
$condition_str = get_conditions_str($condition_str,$frow);
// escaped variables to use in html
$field_id_esc= htmlspecialchars( $field_id, ENT_QUOTES);
$list_id_esc = htmlspecialchars( $list_id, ENT_QUOTES);
// Added 5-09 by BM - Translate description if applicable
$description = (isset($frow['description']) ? htmlspecialchars(xl_layout_label($frow['description']), ENT_QUOTES) : '');
// Support edit option T which assigns the (possibly very long) description as
// the default value.
if (strpos($frow['edit_options'], 'T') !== FALSE) {
if (strlen($currescaped) == 0) $currescaped = $description;
// Description used in this way is not suitable as a title.
$description = '';
}
// added 5-2009 by BM to allow modification of the 'empty' text title field.
// Can pass $frow['empty_title'] with this variable, otherwise
// will default to 'Unassigned'.
// modified 6-2009 by BM to allow complete skipping of the 'empty' text title
// if make $frow['empty_title'] equal to 'SKIP'
$showEmpty = true;
if (isset($frow['empty_title'])) {
if ($frow['empty_title'] == "SKIP") {
//do not display an 'empty' choice
$showEmpty = false;
$empty_title = "Unassigned";
}
else {
$empty_title = $frow['empty_title'];
}
}
else {
$empty_title = "Unassigned";
}
$disabled = strpos($frow['edit_options'], '0') === FALSE ? '' : 'disabled';
$lbfchange = (strpos($frow['form_id'], 'LBF') === 0 || strpos($frow['form_id'], 'LBT') === 0) ?
"checkSkipConditions();" : "";
$lbfonchange = $lbfchange ? "onchange='$lbfchange'" : "";
// generic single-selection list or Race and Ethnicity.
// These data types support backup lists.
if ($data_type == 1 || $data_type == 33) {
echo generate_select_list("form_$field_id", $list_id, $currvalue,
$description, ($showEmpty ? $empty_title : ''), '', $lbfchange, '',
($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
}
// simple text field
else if ($data_type == 2) {
$fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
$maxlength = $frow['max_length'];
$string_maxlength = "";
// if max_length is set to zero, then do not set a maxlength
if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
echo "<input type='text'" .
" name='form_$field_id_esc'" .
" id='form_$field_id_esc'" .
" size='$fldlength'" .
" $string_maxlength" .
" title='$description'" .
" value='$currescaped'";
$tmp = $lbfchange;
if (strpos($frow['edit_options'], 'C') !== FALSE)
$tmp .= "capitalizeMe(this);";
else if (strpos($frow['edit_options'], 'U') !== FALSE)
$tmp .= "this.value = this.value.toUpperCase();";
if ($tmp) echo " onchange='$tmp'";
$tmp = htmlspecialchars( $GLOBALS['gbl_mask_patient_id'], ENT_QUOTES);
if ($field_id == 'pubpid' && strlen($tmp) > 0) {
echo " onkeyup='maskkeyup(this,\"$tmp\")'";
echo " onblur='maskblur(this,\"$tmp\")'";
}
if (strpos($frow['edit_options'], '1') !== FALSE && strlen($currescaped) > 0) {
echo " readonly";
}
if ($disabled) echo ' disabled';
echo " />";
}
// long or multi-line text field
else if ($data_type == 3) {
$textCols = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
$textRows = htmlspecialchars( $frow['fld_rows'], ENT_QUOTES);
echo "<textarea" .
" name='form_$field_id_esc'" .
" id='form_$field_id_esc'" .
" title='$description'" .
" cols='$textCols'" .
" rows='$textRows' $lbfonchange $disabled" .
">" . $currescaped . "</textarea>";
}
// date
else if ($data_type == 4) {
$age_asof_date = ''; // optionalAge() sets this
$age_format = strpos($frow['edit_options'], 'A') === FALSE ? 3 : 0;
$agestr = optionalAge($frow, $currvalue, $age_asof_date);
if ($agestr) {
echo "<table cellpadding='0' cellspacing='0'><tr><td class='text'>";
}
$formDate = $currescaped ;
echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
" value='" . $formDate . "' $disabled />";
if (!$disabled) {
$selector = "#form_{$field_id}";
$date_init .= "$('" . $selector . "').datetimepicker({timepicker: false, maxDate:0, format:'" . $DateFormat . "'});";
if ($agestr) {
$date_init .= "onUpdate: function() {" .
"if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format);" .
"}, ";
}
}
// Optional display of age or gestational age.
if ($agestr) {
echo "</td></tr><tr><td id='span_$field_id' class='text'>" . text($agestr) . "</td></tr></table>";
}
}
// Email datatype.
elseif ($data_type == 5) {
$fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
$maxlength = $frow['max_length'];
$string_maxlength = "";
if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
else $string_maxlength = "";
echo "<input type='email'" .
" name='form_$field_id_esc'" .
" id='form_$field_id_esc'" .
" size='$fldlength'" .
" $string_maxlength" .
" title='$description'" .
" value='$currescaped'";
if ($disabled) echo ' disabled';
echo " />";
}
// Integer Datatype (This allows only digits (doesn't allow hyphens or decimal points))
elseif ($data_type == 6) {
$fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
$string_maxlength = "";
$maxlength = $frow['max_length'];
// if max_length is set to zero, then do not set a maxlength
if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
else $string_maxlength = "";
echo "<input type='text'" .
" name='form_$field_id_esc'" .
" id='form_$field_id_esc'".
" title='$description'" .
" size='$fldlength'" .
" $string_maxlength" .
" value='$currescaped'".
" onfocus = 'allowOnlyDigits(this.name)'";
if ($disabled) echo ' disabled';
echo " />";
}
// URL Datatype (URL's can have following types: http://www.google.com.. or www.google.com or google.com)
elseif ($data_type == 7) {
$fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
$maxlength = $frow['max_length'];
$string_maxlength = "";
if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
else $string_maxlength = "";
echo "<input type='url'" .
" name='form_$field_id_esc'" .
" id='form_$field_id_esc'".
" title='$description'" .
" size='$fldlength'" .
" $string_maxlength" .
" value='$currescaped'";
if ($disabled) echo ' disabled';
echo " />";
}
// provider list, local providers only
else if ($data_type == 10) {
$ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
"WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
"AND authorized = 1 " .
"ORDER BY lname, fname");
echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description' $lbfonchange $disabled>";
echo "<option value=''>" . xlt($empty_title) . "</option>";
$got_selected = false;
while ($urow = sqlFetchArray($ures)) {
$uname = text($urow['fname'] . ' ' . $urow['lname']);
$optionId = attr($urow['id']);
echo "<option value='$optionId'";
if ($urow['id'] == $currvalue) {
echo " selected";
$got_selected = true;
}
echo ">$uname</option>";
}
if (!$got_selected && $currvalue) {
echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
echo "</select>";
echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
}
else {
echo "</select>";
}
}
// provider list, including address book entries with an NPI number
else if ($data_type == 11) {
$ures = sqlStatement("SELECT id, fname, lname, specialty FROM users " .
"WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
"AND ( authorized = 1 OR ( username = '' AND npi != '' ) ) " .
"ORDER BY lname, fname");
echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
echo " $lbfonchange $disabled>";
echo "<option value=''>" . xlt('Unassigned') . "</option>";
$got_selected = false;
while ($urow = sqlFetchArray($ures)) {
$uname = text($urow['fname'] . ' ' . $urow['lname']);
$optionId = attr($urow['id']);
echo "<option value='$optionId'";
if ($urow['id'] == $currvalue) {
echo " selected";
$got_selected = true;
}
echo ">$uname</option>";
}
if (!$got_selected && $currvalue) {
echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
echo "</select>";
echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
}
else {
echo "</select>";
}
}
// pharmacy list
else if ($data_type == 12) {
echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
echo " $lbfonchange $disabled>";
echo "<option value='0'></option>";
$pres = get_pharmacies();
$got_selected = false;
while ($prow = sqlFetchArray($pres)) {
$key = $prow['id'];
$optionValue = htmlspecialchars( $key, ENT_QUOTES);
$optionLabel = htmlspecialchars( $prow['name'] . ' ' . $prow['area_code'] . '-' .
$prow['prefix'] . '-' . $prow['number'] . ' / ' .
$prow['line1'] . ' / ' . $prow['city'], ENT_NOQUOTES);
echo "<option value='$optionValue'";
if ($currvalue == $key) {
echo " selected";
$got_selected = true;
}
echo ">$optionLabel</option>";
}
if (!$got_selected && $currvalue) {
echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
echo "</select>";
echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
}
else {
echo "</select>";
}
}
// squads
else if ($data_type == 13) {
echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
echo " $lbfonchange $disabled>";
echo "<option value=''> </option>";
$squads = acl_get_squads();
if ($squads) {
foreach ($squads as $key => $value) {
$optionValue = htmlspecialchars( $key, ENT_QUOTES);
$optionLabel = htmlspecialchars( $value[3], ENT_NOQUOTES);
echo "<option value='$optionValue'";
if ($currvalue == $key) echo " selected";
echo ">$optionLabel</option>\n";
}
}
echo "</select>";
}
// Address book, preferring organization name if it exists and is not in
// parentheses, and excluding local users who are not providers.
// Supports "referred to" practitioners and facilities.
// Alternatively the letter L in edit_options means that abook_type
// must be "ord_lab", indicating types used with the procedure
// lab ordering system.
// Alternatively the letter O in edit_options means that abook_type
// must begin with "ord_", indicating types used with the procedure
// ordering system.
// Alternatively the letter V in edit_options means that abook_type
// must be "vendor", indicating the Vendor type.
// Alternatively the letter R in edit_options means that abook_type
// must be "dist", indicating the Distributor type.
else if ($data_type == 14) {
if (strpos($frow['edit_options'], 'L') !== FALSE)
$tmp = "abook_type = 'ord_lab'";
else if (strpos($frow['edit_options'], 'O') !== FALSE)
$tmp = "abook_type LIKE 'ord\\_%'";
else if (strpos($frow['edit_options'], 'V') !== FALSE)
$tmp = "abook_type LIKE 'vendor%'";
else if (strpos($frow['edit_options'], 'R') !== FALSE)
$tmp = "abook_type LIKE 'dist'";
else
$tmp = "( username = '' OR authorized = 1 )";
$ures = sqlStatement("SELECT id, fname, lname, organization, username FROM users " .
"WHERE active = 1 AND ( info IS NULL OR info NOT LIKE '%Inactive%' ) " .
"AND $tmp " .
"ORDER BY organization, lname, fname");
echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'";
echo " $lbfonchange $disabled>";
echo "<option value=''>" . htmlspecialchars( xl('Unassigned'), ENT_NOQUOTES) . "</option>";
while ($urow = sqlFetchArray($ures)) {
$uname = $urow['organization'];
if (empty($uname) || substr($uname, 0, 1) == '(') {
$uname = $urow['lname'];
if ($urow['fname']) $uname .= ", " . $urow['fname'];
}
$optionValue = htmlspecialchars( $urow['id'], ENT_QUOTES);
$optionLabel = htmlspecialchars( $uname, ENT_NOQUOTES);
echo "<option value='$optionValue'";
$title = $urow['username'] ? xl('Local') : xl('External');
$optionTitle = htmlspecialchars( $title, ENT_QUOTES);
echo " title='$optionTitle'";
if ($urow['id'] == $currvalue) echo " selected";
echo ">$optionLabel</option>";
}
echo "</select>";
}
// A billing code. If description matches an existing code type then that type is used.
else if ($data_type == 15) {
$fldlength = htmlspecialchars( $frow['fld_length'], ENT_QUOTES);
$maxlength = $frow['max_length'];
$string_maxlength = "";
// if max_length is set to zero, then do not set a maxlength
if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
//
if (strpos($frow['edit_options'], '2') !== FALSE && substr($frow['form_id'], 0, 3) == 'LBF') {
// Option "2" generates a hidden input for the codes, and a matching visible field
// displaying their descriptions. First step is computing the description string.
$currdescstring = '';
if (!empty($currvalue)) {
$relcodes = explode(';', $currvalue);
foreach ($relcodes as $codestring) {
if ($codestring === '') continue;
$code_text = lookup_code_descriptions($codestring);
if ($currdescstring !== '') $currdescstring .= '; ';
if (!empty($code_text)) {
$currdescstring .= $code_text;
}
else {
$currdescstring .= $codestring;
}
}
}
$currdescstring = attr($currdescstring);
//
echo "<input type='text'" .
" name='form_$field_id_esc'" .
" id='form_related_code'" .
" size='$fldlength'" .
" value='$currescaped'" .
" style='display:none'" .
" $lbfonchange readonly $disabled />";
// Extra readonly input field for optional display of code description(s).
echo "<input type='text'" .
" name='form_$field_id_esc" . "__desc'" .
" size='$fldlength'" .
" title='$description'" .
" value='$currdescstring'";
if (!$disabled) {
echo " onclick='sel_related(this,\"$codetype\")'";
}
echo " readonly $disabled />";
}
else {
echo "<input type='text'" .
" name='form_$field_id_esc'" .
" id='form_related_code'" .
" size='$fldlength'" .
" $string_maxlength" .
" title='$description'" .
" value='$currescaped'";
if (!$disabled) {
echo " onclick='sel_related(this,\"$codetype\")'";
}
echo " $lbfonchange readonly $disabled />";
}
}
// insurance company list
else if ($data_type == 16) {
echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
echo "<option value='0'></option>";
$insprovs = getInsuranceProviders();
$got_selected = false;
foreach ($insprovs as $key => $ipname) {
$optionValue = htmlspecialchars($key, ENT_QUOTES);
$optionLabel = htmlspecialchars($ipname, ENT_NOQUOTES);
echo "<option value='$optionValue'";
if ($currvalue == $key) {
echo " selected";
$got_selected = true;
}
echo ">$optionLabel</option>";
}
if (!$got_selected && $currvalue) {
echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
echo "</select>";
echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
}
else {
echo "</select>";
}
}
// issue types
else if ($data_type == 17) {
echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'>";
echo "<option value='0'></option>";
$got_selected = false;
foreach ($ISSUE_TYPES as $key => $value) {
$optionValue = htmlspecialchars($key, ENT_QUOTES);
$optionLabel = htmlspecialchars($value[1], ENT_NOQUOTES);
echo "<option value='$optionValue'";
if ($currvalue == $key) {
echo " selected";
$got_selected = true;
}
echo ">$optionLabel</option>";
}
if (!$got_selected && strlen($currvalue) > 0) {
echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
echo "</select>";
echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
}
else {
echo "</select>";
}
}
// Visit categories.
else if ($data_type == 18) {
$cres = sqlStatement("SELECT pc_catid, pc_catname " .
"FROM libreehr_postcalendar_categories ORDER BY pc_catname");
echo "<select name='form_$field_id_esc' id='form_$field_id_esc' title='$description'" .
" $lbfonchange $disabled>";
echo "<option value=''>" . xlt($empty_title) . "</option>";
$got_selected = false;
while ($crow = sqlFetchArray($cres)) {
$catid = $crow['pc_catid'];
if (($catid < 9 && $catid != 5) || $catid == 11) continue;
echo "<option value='" . attr($catid) . "'";
if ($catid == $currvalue) {
echo " selected";
$got_selected = true;
}
echo ">" . text(xl_appt_category($crow['pc_catname'])) . "</option>";
}
if (!$got_selected && $currvalue) {
echo "<option value='" . attr($currvalue) . "' selected>* " . text($currvalue) . " *</option>";
echo "</select>";
echo " <font color='red' title='" . xla('Please choose a valid selection from the list.') . "'>" . xlt('Fix this') . "!</font>";
}
else {
echo "</select>";
}
}
// a set of labeled checkboxes
else if ($data_type == 21) {
// In this special case, fld_length is the number of columns generated.
$cols = max(1, $frow['fld_length']);
$avalue = explode('|', $currvalue);
$lres = sqlStatement("SELECT * FROM list_options " .
"WHERE list_id = ? ORDER BY seq, title", array($list_id) );
echo "<table cellpadding='0' cellspacing='0' width='100%'>";
$tdpct = (int) (100 / $cols);
for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
$option_id = $lrow['option_id'];
$option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
// if ($count) echo "<br />";
if ($count % $cols == 0) {
if ($count) echo "</tr>";
echo "<tr>";
}
echo "<td width='$tdpct%'>";
echo "<input type='checkbox' name='form_{$field_id_esc}[$option_id_esc]'" .
"id='form_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
if (in_array($option_id, $avalue)) echo " checked";
// Added 5-09 by BM - Translate label if applicable
echo " $disabled />" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES);
echo "</td>";
}
if ($count) {
echo "</tr>";
if ($count > $cols) {
// Add some space after multiple rows of checkboxes.
$cols = htmlspecialchars( $cols, ENT_QUOTES);
echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
}
}
echo "</table>";
}
// a set of labeled text input fields
else if ($data_type == 22) {
$tmp = explode('|', $currvalue);
$avalue = array();
foreach ($tmp as $value) {
if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
$avalue[$matches[1]] = $matches[2];
}
}
$lres = sqlStatement("SELECT * FROM list_options " .
"WHERE list_id = ? ORDER BY seq, title", array($list_id) );
echo "<table cellpadding='0' cellspacing='0'>";
while ($lrow = sqlFetchArray($lres)) {
$option_id = $lrow['option_id'];
$option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
$maxlength = $frow['max_length'];
$string_maxlength = "";
// if max_length is set to zero, then do not set a maxlength
if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
$fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
// Added 5-09 by BM - Translate label if applicable
echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . " </td>";
$fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
$optionValue = htmlspecialchars( $avalue[$option_id], ENT_QUOTES);
echo "<td><input type='text'" .
" name='form_{$field_id_esc}[$option_id_esc]'" .
" id='form_{$field_id_esc}[$option_id_esc]'" .
" size='$fldlength'" .
" $string_maxlength" .
" value='$optionValue'";
echo " $lbfonchange $disabled /></td></tr>";
}
echo "</table>";
}
// a set of exam results; 3 radio buttons and a text field:
else if ($data_type == 23) {
$tmp = explode('|', $currvalue);
$avalue = array();
foreach ($tmp as $value) {
if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
$avalue[$matches[1]] = $matches[2];
}
}
$maxlength = $frow['max_length'];
$string_maxlength = "";
// if max_length is set to zero, then do not set a maxlength
if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
$fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
$lres = sqlStatement("SELECT * FROM list_options " .
"WHERE list_id = ? ORDER BY seq, title", array($list_id) );
echo "<table cellpadding='0' cellspacing='0'>";
echo "<tr><td> </td><td class='bold'>" .
htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
" </td><td class='bold'>" .
htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . " </td>" .
"<td class='bold'>" .
htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . " </td><td class='bold'>" .
htmlspecialchars( xl('Date/Notes'), ENT_NOQUOTES) . "</td></tr>";
while ($lrow = sqlFetchArray($lres)) {
$option_id = $lrow['option_id'];
$option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
$restype = substr($avalue[$option_id], 0, 1);
$resnote = substr($avalue[$option_id], 2);
// Added 5-09 by BM - Translate label if applicable
echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . " </td>";
for ($i = 0; $i < 3; ++$i) {
$inputValue = htmlspecialchars( $i, ENT_QUOTES);
echo "<td><input type='radio'" .
" name='radio_{$field_id_esc}[$option_id_esc]'" .
" id='radio_{$field_id_esc}[$option_id_esc]'" .
" value='$inputValue' $lbfonchange";
if ($restype === "$i") echo " checked";
echo " $disabled /></td>";
}
$fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
$resnote = htmlspecialchars( $resnote, ENT_QUOTES);
echo "<td><input type='text'" .
" name='form_{$field_id_esc}[$option_id_esc]'" .
" id='form_{$field_id_esc}[$option_id_esc]'" .
" size='$fldlength'" .
" $string_maxlength" .
" value='$resnote' $disabled /></td>";
echo "</tr>";
}
echo "</table>";
}
// the list of active allergies for the current patient
// this is read-only!
else if ($data_type == 24) {
$query = "SELECT title, comments FROM lists WHERE " .
"pid = ? AND type = 'allergy' AND enddate IS NULL " .
"ORDER BY begdate";
// echo "<!-- $query -->\n"; // debugging
$lres = sqlStatement($query, array($GLOBALS['pid']));
$count = 0;
while ($lrow = sqlFetchArray($lres)) {
if ($count++) echo "<br />";
echo htmlspecialchars( $lrow['title'], ENT_NOQUOTES);
if ($lrow['comments']) echo ' (' . htmlspecialchars( $lrow['comments'], ENT_NOQUOTES) . ')';
}
}
// a set of labeled checkboxes, each with a text field:
else if ($data_type == 25) {
$tmp = explode('|', $currvalue);
$avalue = array();
foreach ($tmp as $value) {
if (preg_match('/^([^:]+):(.*)$/', $value, $matches)) {
$avalue[$matches[1]] = $matches[2];
}
}
$maxlength = $frow['max_length'];
$string_maxlength = "";
// if max_length is set to zero, then do not set a maxlength
if ($maxlength) $string_maxlength = "maxlength='".attr($maxlength)."'";
$fldlength = empty($frow['fld_length']) ? 20 : $frow['fld_length'];
$lres = sqlStatement("SELECT * FROM list_options " .
"WHERE list_id = ? ORDER BY seq, title", array($list_id) );
echo "<table cellpadding='0' cellspacing='0'>";
while ($lrow = sqlFetchArray($lres)) {
$option_id = $lrow['option_id'];
$option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
$restype = substr($avalue[$option_id], 0, 1);
$resnote = substr($avalue[$option_id], 2);
// Added 5-09 by BM - Translate label if applicable
echo "<tr><td>" . htmlspecialchars( xl_list_label($lrow['title']), ENT_NOQUOTES) . " </td>";
$option_id = htmlspecialchars( $option_id, ENT_QUOTES);
echo "<td><input type='checkbox' name='check_{$field_id_esc}[$option_id_esc]'" .
" id='check_{$field_id_esc}[$option_id_esc]' value='1' $lbfonchange";
if ($restype) echo " checked";
echo " $disabled /> </td>";
$fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
$resnote = htmlspecialchars( $resnote, ENT_QUOTES);
echo "<td><input type='text'" .
" name='form_{$field_id_esc}[$option_id_esc]'" .
" id='form_{$field_id_esc}[$option_id_esc]'" .
" size='$fldlength'" .
" $string_maxlength" .
" value='$resnote' $disabled /></td>";
echo "</tr>";
}
echo "</table>";
}
// single-selection list with ability to add to it
else if ($data_type == 26) {
echo generate_select_list("form_$field_id", $list_id, $currvalue,
$description, ($showEmpty ? $empty_title : ''), 'addtolistclass_'.$list_id, $lbfchange, '',
($disabled ? array('disabled' => 'disabled') : null), false, $backup_list);
// show the add button if user has access to correct list
$inputValue = htmlspecialchars( xl('Add'), ENT_QUOTES);
$outputAddButton = "<input type='button' id='addtolistid_" . $list_id_esc . "' fieldid='form_" .
$field_id_esc . "' class='addtolist' value='$inputValue' $disabled />";
if (aco_exist('lists', $list_id)) {
// a specific aco exist for this list, so ensure access
if (acl_check('lists', $list_id)) echo $outputAddButton;
}
else {
// no specific aco exist for this list, so check for access to 'default' list
if (acl_check('lists', 'default')) echo $outputAddButton;
}
}
// a set of labeled radio buttons
else if ($data_type == 27) {
// In this special case, fld_length is the number of columns generated.
$cols = max(1, $frow['fld_length']);
$lres = sqlStatement("SELECT * FROM list_options " .
"WHERE list_id = ? ORDER BY seq, title", array($list_id) );
echo "<table cellpadding='0' cellspacing='0' width='100%'>";
$tdpct = (int) (100 / $cols);
$got_selected = FALSE;
for ($count = 0; $lrow = sqlFetchArray($lres); ++$count) {
$option_id = $lrow['option_id'];
$option_id_esc = htmlspecialchars( $option_id, ENT_QUOTES);
if ($count % $cols == 0) {
if ($count) echo "</tr>";
echo "<tr>";
}
echo "<td width='$tdpct%'>";
echo "<input type='radio' name='form_{$field_id_esc}' id='form_{$field_id_esc}[$option_id_esc]'" .
" value='$option_id_esc' $lbfonchange";
if ((strlen($currvalue) == 0 && $lrow['is_default']) ||
(strlen($currvalue) > 0 && $option_id == $currvalue))
{
echo " checked";
$got_selected = TRUE;
}
echo " $disabled />" . htmlspecialchars(xl_list_label($lrow['title']), ENT_NOQUOTES);
echo "</td>";
}
if ($count) {
echo "</tr>";
if ($count > $cols) {
// Add some space after multiple rows of radio buttons.
$cols = htmlspecialchars($cols, ENT_QUOTES);
echo "<tr><td colspan='$cols' style='height:0.7em'></td></tr>";
}
}
echo "</table>";
if (!$got_selected && strlen($currvalue) > 0) {
$fontTitle = htmlspecialchars( xl('Please choose a valid selection.'), ENT_QUOTES);
$fontText = htmlspecialchars( xl('Fix this'), ENT_NOQUOTES);
echo "$currescaped <font color='red' title='$fontTitle'>$fontText!</font>";
}
}