示例#1
0
function ActiveIssueCodeRecycleFn($thispid2, $ISSUE_TYPES2)
{
    ///////////////////////////////////////////////////////////////////////
    // Active Issue Code Recycle Function authored by epsdky (2014-2015) //
    ///////////////////////////////////////////////////////////////////////
    $modeIssueTypes = array();
    $issueTypeIdx2 = array();
    $idx2 = 0;
    foreach ($ISSUE_TYPES2 as $issueTypeX => $isJunk) {
        $modeIssueTypes[$idx2] = $issueTypeX;
        $issueTypeIdx2[$issueTypeX] = $idx2;
        ++$idx2;
    }
    $pe2 = array($thispid2);
    $qs2 = str_repeat('?, ', count($modeIssueTypes) - 1) . '?';
    $sqlParameters2 = array_merge($pe2, $modeIssueTypes);
    $codeList2 = array();
    $issueCodes2 = sqlStatement("SELECT diagnosis FROM lists WHERE pid = ? AND enddate is NULL AND type IN ({$qs2})", $sqlParameters2);
    while ($issueCodesRow2 = sqlFetchArray($issueCodes2)) {
        if ($issueCodesRow2['diagnosis'] != "") {
            $someCodes2 = explode(";", $issueCodesRow2['diagnosis']);
            $codeList2 = array_merge($codeList2, $someCodes2);
        }
    }
    if ($codeList2) {
        $codeList2 = array_unique($codeList2);
        sort($codeList2);
    }
    $memberCodes = array();
    $memberCodes[0] = array();
    $memberCodes[1] = array();
    $memberCodes[2] = array();
    $allowedCodes2 = array();
    $allowedCodes2[0] = collect_codetypes("medical_problem");
    $allowedCodes2[1] = collect_codetypes("diagnosis");
    $allowedCodes2[2] = collect_codetypes("drug");
    // Test membership of codes to each code type set
    foreach ($allowedCodes2 as $akey1 => $allowCodes2) {
        foreach ($codeList2 as $listCode2) {
            list($codeTyX, ) = explode(":", $listCode2);
            if (in_array($codeTyX, $allowCodes2)) {
                array_push($memberCodes[$akey1], $listCode2);
            }
        }
    }
    // output sets of display options
    $displayCodeSets[0] = $memberCodes[0];
    // medical_problem
    $displayCodeSets[1] = array_merge($memberCodes[1], $memberCodes[2]);
    // allergy
    $displayCodeSets[2] = array_merge($memberCodes[2], $memberCodes[1]);
    // medication
    $displayCodeSets[3] = $memberCodes[1];
    // default
    echo "var listBoxOptionSets = new Array();\n\n";
    foreach ($displayCodeSets as $akey => $displayCodeSet) {
        echo "listBoxOptionSets[" . attr($akey) . "] = new Array();\n";
        if ($displayCodeSet) {
            foreach ($displayCodeSet as $dispCode2) {
                $codeDesc2 = lookup_code_descriptions($dispCode2);
                echo "listBoxOptionSets[" . attr($akey) . "][listBoxOptionSets[" . attr($akey) . "].length] = new Option('" . attr($dispCode2) . " (" . attr(trim($codeDesc2)) . ") ' ,'" . attr($dispCode2) . "' , false, false);\n";
            }
        }
    }
    // map issues to a set of display options
    $modeIndexMapping = array();
    foreach ($modeIssueTypes as $akey2 => $isJunk) {
        $modeIndexMapping[$akey2] = 3;
    }
    if (array_key_exists("medical_problem", $issueTypeIdx2)) {
        $modeIndexMapping[$issueTypeIdx2['medical_problem']] = 0;
    }
    if (array_key_exists("allergy", $issueTypeIdx2)) {
        $modeIndexMapping[$issueTypeIdx2['allergy']] = 1;
    }
    if (array_key_exists("medication", $issueTypeIdx2)) {
        $modeIndexMapping[$issueTypeIdx2['medication']] = 2;
    }
    echo "\nvar listBoxOptions2 = new Array();\n\n";
    foreach ($modeIssueTypes as $akey2 => $isJunk) {
        echo "listBoxOptions2[" . attr($akey2) . "] = listBoxOptionSets[" . attr($modeIndexMapping[$akey2]) . "];\n";
    }
    ///////////////////////////////////////////////////////////////////////
    // End of Active Issue Code Recycle Function main code block         //
    ///////////////////////////////////////////////////////////////////////
}
示例#2
0
     // output a header for each Issue Type we encounter
     $disptype = $ISSUE_TYPES[$irow['type']][0];
     echo "<div class='issue_type'>" . $disptype . ":</div>\n";
     $prevIssueType = $irow['type'];
 }
 echo "<div class='text issue'>";
 echo "<span class='issue_title'>" . $irow['title'] . ":</span>";
 echo "<span class='issue_comments'> " . $irow['comments'] . "</span>\n";
 // Show issue's chief diagnosis and its description:
 if ($diagnosis) {
     echo "<div class='text issue_diag'>";
     echo "<span class='bold'>[" . xl('Diagnosis') . "]</span><br>";
     $dcodes = explode(";", $diagnosis);
     foreach ($dcodes as $dcode) {
         echo "<span class='italic'>" . $dcode . "</span>: ";
         echo lookup_code_descriptions($dcode) . "<br>\n";
     }
     //echo $diagnosis." -- ".lookup_code_descriptions($diagnosis)."\n";
     echo "</div>";
 }
 // Supplemental data for GCAC or Contraception issues.
 if ($irow['type'] == 'ippf_gcac') {
     echo "   <table>\n";
     display_layout_rows('GCA', sqlQuery("SELECT * FROM lists_ippf_gcac WHERE id = '{$rowid}'"));
     echo "   </table>\n";
 } else {
     if ($irow['type'] == 'contraceptive') {
         echo "   <table>\n";
         display_layout_rows('CON', sqlQuery("SELECT * FROM lists_ippf_con WHERE id = '{$rowid}'"));
         echo "   </table>\n";
     }
示例#3
0
     }
 }
 // display issues
 while ($row = sqlFetchArray($pres)) {
     $rowid = $row['id'];
     $disptitle = trim($row['title']) ? $row['title'] : "[Missing Title]";
     $ierow = sqlQuery("SELECT count(*) AS count FROM issue_encounter WHERE " . "list_id = ?", array($rowid));
     // encount is used to toggle the color of the table-row output below
     ++$encount;
     $bgclass = $encount & 1 ? "bg1" : "bg2";
     // look up the diag codes
     $codetext = "";
     if ($row['diagnosis'] != "") {
         $diags = explode(";", $row['diagnosis']);
         foreach ($diags as $diag) {
             $codedesc = lookup_code_descriptions($diag);
             $codetext .= htmlspecialchars($diag, ENT_NOQUOTES) . " (" . htmlspecialchars($codedesc, ENT_NOQUOTES) . ")<br>";
         }
     }
     // calculate the status
     if ($row['outcome'] == "1" && $row['enddate'] != NULL) {
         // Resolved
         $statusCompute = generate_display_field(array('data_type' => '1', 'list_id' => 'outcome'), $row['outcome']);
     } else {
         if ($row['enddate'] == NULL) {
             $statusCompute = htmlspecialchars(xl("Active"), ENT_NOQUOTES);
         } else {
             $statusCompute = htmlspecialchars(xl("Inactive"), ENT_NOQUOTES);
         }
     }
     $click_class = 'statrow';
示例#4
0
function generate_form_field($frow, $currvalue)
{
    global $rootdir, $date_init, $ISSUE_TYPES, $code_types;
    $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'];
    // 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 ? "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);
    } 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 " />";
        } 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>";
            } 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'>";
                    }
                    echo "<input type='text' size='10' name='form_{$field_id_esc}' id='form_{$field_id_esc}'" . " value='" . substr($currescaped, 0, 10) . "'";
                    if (!$agestr) {
                        echo " title='{$description}'";
                    }
                    echo " {$lbfonchange} onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' {$disabled} />";
                    if (!$disabled) {
                        echo "<img src='{$rootdir}/pic/show_calendar.gif' align='absbottom' width='24' height='22'" . " id='img_{$field_id_esc}' border='0' alt='[?]' style='cursor:pointer'" . " title='" . htmlspecialchars(xl('Click here to choose a date'), ENT_QUOTES) . "' />";
                        $date_init .= " Calendar.setup({" . "inputField:'form_{$field_id}', " . "ifFormat:'%Y-%m-%d', ";
                        if ($agestr) {
                            $date_init .= "onUpdate: function() {" . "if (typeof(updateAgeString) == 'function') updateAgeString('{$field_id}','{$age_asof_date}', {$age_format});" . "}, ";
                        }
                        $date_init .= "button:'img_{$field_id}'})\n";
                    }
                    // 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>";
                    }
                } 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>";
                        }
                    } 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>";
                            }
                        } 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>";
                                }
                            } 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=''>&nbsp;</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>";
                                } 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>";
                                    } 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} />";
                                            }
                                        } 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>";
                                                }
                                            } 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>";
                                                    }
                                                } else {
                                                    if ($data_type == 18) {
                                                        $cres = sqlStatement("SELECT pc_catid, pc_catname " . "FROM openemr_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>";
                                                        }
                                                    } 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>";
                                                        } 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) . "&nbsp;</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>";
                                                            } 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>&nbsp;</td><td class='bold'>" . htmlspecialchars(xl('N/A'), ENT_NOQUOTES) . "&nbsp;</td><td class='bold'>" . htmlspecialchars(xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" . "<td class='bold'>" . htmlspecialchars(xl('Abn'), ENT_NOQUOTES) . "&nbsp;</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) . "&nbsp;</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>";
                                                                } 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) . ')';
                                                                            }
                                                                        }
                                                                    } 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) . "&nbsp;</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} />&nbsp;</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>";
                                                                        } 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;
                                                                                    }
                                                                                }
                                                                            } 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>";
                                                                                    }
                                                                                } else {
                                                                                    if ($data_type == 28 || $data_type == 32) {
                                                                                        $tmp = explode('|', $currvalue);
                                                                                        switch (count($tmp)) {
                                                                                            case "4":
                                                                                                $resnote = $tmp[0];
                                                                                                $restype = $tmp[1];
                                                                                                $resdate = $tmp[2];
                                                                                                $reslist = $tmp[3];
                                                                                                break;
                                                                                            case "3":
                                                                                                $resnote = $tmp[0];
                                                                                                $restype = $tmp[1];
                                                                                                $resdate = $tmp[2];
                                                                                                break;
                                                                                            case "2":
                                                                                                $resnote = $tmp[0];
                                                                                                $restype = $tmp[1];
                                                                                                $resdate = "";
                                                                                                break;
                                                                                            case "1":
                                                                                                $resnote = $tmp[0];
                                                                                                $resdate = $restype = "";
                                                                                                break;
                                                                                            default:
                                                                                                $restype = $resdate = $resnote = "";
                                                                                                break;
                                                                                        }
                                                                                        $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'];
                                                                                        $fldlength = htmlspecialchars($fldlength, ENT_QUOTES);
                                                                                        $resnote = htmlspecialchars($resnote, ENT_QUOTES);
                                                                                        $resdate = htmlspecialchars($resdate, ENT_QUOTES);
                                                                                        echo "<table cellpadding='0' cellspacing='0'>";
                                                                                        echo "<tr>";
                                                                                        if ($data_type == 28) {
                                                                                            // input text
                                                                                            echo "<td><input type='text'" . " name='form_{$field_id_esc}'" . " id='form_{$field_id_esc}'" . " size='{$fldlength}'" . " {$string_maxlength}" . " value='{$resnote}' {$disabled} />&nbsp;</td>";
                                                                                            echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . htmlspecialchars(xl('Status'), ENT_NOQUOTES) . ":&nbsp;&nbsp;</td>";
                                                                                        } else {
                                                                                            if ($data_type == 32) {
                                                                                                // input text
                                                                                                echo "<tr><td><input type='text'" . " name='form_text_{$field_id_esc}'" . " id='form_text_{$field_id_esc}'" . " size='{$fldlength}'" . " {$string_maxlength}" . " value='{$resnote}' {$disabled} />&nbsp;</td></tr>";
                                                                                                echo "<td>";
                                                                                                //Selection list for smoking status
                                                                                                $onchange = 'radioChange(this.options[this.selectedIndex].value)';
                                                                                                //VicarePlus :: The javascript function for selection list.
                                                                                                echo generate_select_list("form_{$field_id}", $list_id, $reslist, $description, $showEmpty ? $empty_title : '', '', $onchange, '', $disabled ? array('disabled' => 'disabled') : null);
                                                                                                echo "</td>";
                                                                                                echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
                                                                                            }
                                                                                        }
                                                                                        // current
                                                                                        echo "<td class='text' ><input type='radio'" . " name='radio_{$field_id_esc}'" . " id='radio_{$field_id_esc}[current]'" . " value='current" . $field_id_esc . "' {$lbfonchange}";
                                                                                        if ($restype == "current" . $field_id) {
                                                                                            echo " checked";
                                                                                        }
                                                                                        if ($data_type == 32) {
                                                                                            echo " onClick='smoking_statusClicked(this)'";
                                                                                        }
                                                                                        echo " />" . xlt('Current') . "&nbsp;</td>";
                                                                                        // quit
                                                                                        echo "<td class='text'><input type='radio'" . " name='radio_{$field_id_esc}'" . " id='radio_{$field_id_esc}[quit]'" . " value='quit" . $field_id_esc . "' {$lbfonchange}";
                                                                                        if ($restype == "quit" . $field_id) {
                                                                                            echo " checked";
                                                                                        }
                                                                                        if ($data_type == 32) {
                                                                                            echo " onClick='smoking_statusClicked(this)'";
                                                                                        }
                                                                                        echo " {$disabled} />" . xlt('Quit') . "&nbsp;</td>";
                                                                                        // quit date
                                                                                        echo "<td class='text'><input type='text' size='6' name='date_{$field_id_esc}' id='date_{$field_id_esc}'" . " value='{$resdate}'" . " title='{$description}'" . " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' {$disabled} />";
                                                                                        if (!$disabled) {
                                                                                            echo "<img src='{$rootdir}/pic/show_calendar.gif' align='absbottom' width='24' height='22'" . " id='img_{$field_id_esc}' border='0' alt='[?]' style='cursor:pointer'" . " title='" . htmlspecialchars(xl('Click here to choose a date'), ENT_QUOTES) . "' />";
                                                                                            $date_init .= " Calendar.setup({inputField:'date_{$field_id}', ifFormat:'%Y-%m-%d', button:'img_{$field_id}'});\n";
                                                                                        }
                                                                                        echo "&nbsp;</td>";
                                                                                        // never
                                                                                        echo "<td class='text'><input type='radio'" . " name='radio_{$field_id_esc}'" . " id='radio_{$field_id_esc}[never]'" . " value='never" . $field_id_esc . "' {$lbfonchange}";
                                                                                        if ($restype == "never" . $field_id) {
                                                                                            echo " checked";
                                                                                        }
                                                                                        if ($data_type == 32) {
                                                                                            echo " onClick='smoking_statusClicked(this)'";
                                                                                        }
                                                                                        echo " />" . xlt('Never') . "&nbsp;</td>";
                                                                                        // Not Applicable
                                                                                        echo "<td class='text'><input type='radio'" . " name='radio_{$field_id}'" . " id='radio_{$field_id}[not_applicable]'" . " value='not_applicable" . $field_id . "' {$lbfonchange}";
                                                                                        if ($restype == "not_applicable" . $field_id) {
                                                                                            echo " checked";
                                                                                        }
                                                                                        if ($data_type == 32) {
                                                                                            echo " onClick='smoking_statusClicked(this)'";
                                                                                        }
                                                                                        echo " {$disabled} />" . xlt('N/A') . "&nbsp;</td>";
                                                                                        //
                                                                                        //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
                                                                                        echo "<td class='text' ><div id='smoke_code'></div></td>";
                                                                                        echo "</tr>";
                                                                                        echo "</table>";
                                                                                    } else {
                                                                                        if ($data_type == 31) {
                                                                                            echo nl2br($frow['description']);
                                                                                        } else {
                                                                                            if ($data_type == 34) {
                                                                                                $arr = explode("|*|*|*|", $currvalue);
                                                                                                echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=" . htmlspecialchars($list_id_esc, ENT_QUOTES) . "' class='iframe_medium' style='text-decoration:none;color:black;'>";
                                                                                                echo "<div id='form_{$field_id}_div' class='text-area'>" . htmlspecialchars($arr[0], ENT_QUOTES) . "</div>";
                                                                                                echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' {$lbfonchange} {$disabled}>" . $currvalue . "</textarea></div>";
                                                                                                echo "</a>";
                                                                                            } else {
                                                                                                if ($data_type == 35) {
                                                                                                    if (empty($currvalue)) {
                                                                                                        $currvalue = 0;
                                                                                                    }
                                                                                                    dropdown_facility($selected = $currvalue, $name = "form_{$field_id_esc}", $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
                                                                                                } else {
                                                                                                    if ($data_type == 36) {
                                                                                                        echo generate_select_list("form_{$field_id}", $list_id, $currvalue, $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list);
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
示例#5
0
     echo "  <td class='text'>" . ($iter["active"] || $iter["active"] == NULL ? xlt('Yes') : xlt('No')) . "</td>\n";
 } else {
     echo "  <td class='text'>" . ($iter["active"] ? xlt('Yes') : xlt('No')) . "</td>\n";
 }
 echo "  <td class='text'>" . ($iter["reportable"] ? xlt('Yes') : xlt('No')) . "</td>\n";
 echo "  <td class='text'>" . ($iter["financial_reporting"] ? xlt('Yes') : xlt('No')) . "</td>\n";
 echo "  <td class='text'>" . text($iter['code_type_name']) . "</td>\n";
 echo "  <td class='text'>" . text($iter['code_text']) . "</td>\n";
 echo "  <td class='text'>" . text($iter['code_text_short']) . "</td>\n";
 if (related_codes_are_used()) {
     // Show related codes.
     echo "  <td class='text'>";
     $arel = explode(';', $iter['related_code']);
     foreach ($arel as $tmp) {
         list($reltype, $relcode) = explode(':', $tmp);
         $code_description = lookup_code_descriptions($reltype . ":" . $relcode);
         echo text($relcode) . ' ' . text(trim($code_description)) . '<br />';
     }
     echo "</td>\n";
 }
 $pres = sqlStatement("SELECT p.pr_price " . "FROM list_options AS lo LEFT OUTER JOIN prices AS p ON " . "p.pr_id = ? AND p.pr_selector = '' AND p.pr_level = lo.option_id " . "WHERE list_id = 'pricelevel' ORDER BY lo.seq", array($iter['id']));
 while ($prow = sqlFetchArray($pres)) {
     echo "<td class='text' align='right'>" . text(bucks($prow['pr_price'])) . "</td>\n";
 }
 if ($iter["code_external"] > 0) {
     echo "  <td align='right'><a class='link' href='javascript:submitModify(\"" . attr($iter['code_type_name']) . "\",\"" . attr($iter['code']) . "\",\"" . attr($iter['id']) . "\")'>[" . xlt('Modify') . "]</a></td>\n";
 } else {
     echo "  <td align='right'><a class='link' href='javascript:submitDelete(" . attr($iter['id']) . ")'>[" . xlt('Delete') . "]</a></td>\n";
     echo "  <td align='right'><a class='link' href='javascript:submitEdit(" . attr($iter['id']) . ")'>[" . xlt('Edit') . "]</a></td>\n";
 }
 echo " </tr>\n";
function description_test($codes, $mode)
{
    $descriptions = lookup_code_descriptions($codes, $mode);
    echo $descriptions . "    <br>" . PHP_EOL;
}
示例#7
0
function generate_form_field($frow, $currvalue) {
  global $rootdir, $date_init, $ISSUE_TYPES, $code_types,$condition_str;

  $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'>";
    }
    echo "<input type='text' size='10' name='form_$field_id_esc' id='form_$field_id_esc'" .
      " value='" . substr($currescaped, 0, 10) . "'";
    if (!$agestr) echo " title='$description'";
    echo " $lbfonchange onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
    if (!$disabled) {
      echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
      " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
      " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
      $date_init .= " Calendar.setup({" .
        "inputField:'form_$field_id', " .
        "ifFormat:'%Y-%m-%d', ";
      if ($agestr) {
        $date_init .= "onUpdate: function() {" .
          "if (typeof(updateAgeString) == 'function') updateAgeString('$field_id','$age_asof_date', $age_format);" .
        "}, ";
      }
      $date_init .= "button:'img_$field_id'})\n";
    }
    // 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>";
    }
  }

  // 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=''>&nbsp;</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 openemr_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 = ? AND activity = 1 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 = ? AND activity = 1 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) . "&nbsp;</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 = ? AND activity = 1 ORDER BY seq, title", array($list_id) );
    echo "<table cellpadding='0' cellspacing='0'>";
    echo "<tr><td>&nbsp;</td><td class='bold'>" .
      htmlspecialchars( xl('N/A'), ENT_NOQUOTES) .
      "&nbsp;</td><td class='bold'>" .
      htmlspecialchars( xl('Nor'), ENT_NOQUOTES) . "&nbsp;</td>" .
      "<td class='bold'>" .
      htmlspecialchars( xl('Abn'), ENT_NOQUOTES) . "&nbsp;</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) . "&nbsp;</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 = ? AND activity = 1 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) . "&nbsp;</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 />&nbsp;</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 = ? AND activity = 1 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>";
    }
  }

  // special case for history of lifestyle status; 3 radio buttons and a date text field:
  // VicarePlus :: A selection list box for smoking status:
  else if ($data_type == 28 || $data_type == 32) {
    $tmp = explode('|', $currvalue);
    switch(count($tmp)) {
      case "4": {
        $resnote = $tmp[0];
        $restype = $tmp[1];
        $resdate = $tmp[2];
        $reslist = $tmp[3];
      } break;
      case "3": {
        $resnote = $tmp[0];
        $restype = $tmp[1];
        $resdate = $tmp[2];
      } break;
      case "2": {
        $resnote = $tmp[0];
        $restype = $tmp[1];
        $resdate = "";
      } break;
      case "1": {
        $resnote = $tmp[0];
        $resdate = $restype = "";
      } break;
      default: {
        $restype = $resdate = $resnote = "";
      } break;
    }
    $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'];

    $fldlength = htmlspecialchars( $fldlength, ENT_QUOTES);
    $resnote = htmlspecialchars( $resnote, ENT_QUOTES);
    $resdate = htmlspecialchars( $resdate, ENT_QUOTES);
    echo "<table cellpadding='0' cellspacing='0'>";
    echo "<tr>";
    if ($data_type == 28)
    {
	// input text
    echo "<td><input type='text'" .
      " name='form_$field_id_esc'" .
      " id='form_$field_id_esc'" .
      " size='$fldlength'" .
      " $string_maxlength" .
      " value='$resnote' $disabled />&nbsp;</td>";
   echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
      "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
      htmlspecialchars( xl('Status'), ENT_NOQUOTES).":&nbsp;&nbsp;</td>";
    }
    else if($data_type == 32)
    {
    // input text
    echo "<tr><td><input type='text'" .
      " name='form_text_$field_id_esc'" .
      " id='form_text_$field_id_esc'" .
      " size='$fldlength'" .
      " $string_maxlength" .
      " value='$resnote' $disabled />&nbsp;</td></tr>";
    echo "<td>";
    //Selection list for smoking status
    $onchange = 'radioChange(this.options[this.selectedIndex].value)';//VicarePlus :: The javascript function for selection list.
    echo generate_select_list("form_$field_id", $list_id, $reslist,
      $description, ($showEmpty ? $empty_title : ''), '', $onchange, '',
      ($disabled ? array('disabled' => 'disabled') : null));
    echo "</td>";
    echo "<td class='bold'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" . xlt('Status') . ":&nbsp;&nbsp;</td>";
    }
    // current
    echo "<td class='text' ><input type='radio'" .
      " name='radio_{$field_id_esc}'" .
      " id='radio_{$field_id_esc}[current]'" .
      " value='current" . $field_id_esc . "' $lbfonchange";
    if ($restype == "current" . $field_id) echo " checked";
    if ($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
    echo " />" . xlt('Current') . "&nbsp;</td>";
    // quit
    echo "<td class='text'><input type='radio'" .
      " name='radio_{$field_id_esc}'" .
      " id='radio_{$field_id_esc}[quit]'" .
      " value='quit".$field_id_esc."' $lbfonchange";
    if ($restype == "quit" . $field_id) echo " checked";
    if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
    echo " $disabled />" . xlt('Quit') . "&nbsp;</td>";
    // quit date
    echo "<td class='text'><input type='text' size='6' name='date_$field_id_esc' id='date_$field_id_esc'" .
      " value='$resdate'" .
      " title='$description'" .
      " onkeyup='datekeyup(this,mypcc)' onblur='dateblur(this,mypcc)' $disabled />";
    if (!$disabled) {
      echo "<img src='$rootdir/pic/show_calendar.gif' align='absbottom' width='24' height='22'" .
      " id='img_$field_id_esc' border='0' alt='[?]' style='cursor:pointer'" .
      " title='" . htmlspecialchars( xl('Click here to choose a date'), ENT_QUOTES) . "' />";
      $date_init .= " Calendar.setup({inputField:'date_$field_id', ifFormat:'%Y-%m-%d', button:'img_$field_id'});\n";
    }
    echo "&nbsp;</td>";
    // never
    echo "<td class='text'><input type='radio'" .
      " name='radio_{$field_id_esc}'" .
      " id='radio_{$field_id_esc}[never]'" .
      " value='never" . $field_id_esc . "' $lbfonchange";
    if ($restype == "never" . $field_id) echo " checked";
    if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
    echo " />" . xlt('Never') . "&nbsp;</td>";
    // Not Applicable
    echo "<td class='text'><input type='radio'" .
      " name='radio_{$field_id}'" .
      " id='radio_{$field_id}[not_applicable]'" .
      " value='not_applicable" . $field_id . "' $lbfonchange";
    if ($restype == "not_applicable" . $field_id) echo " checked";
    if($data_type == 32) echo " onClick='smoking_statusClicked(this)'";
    echo " $disabled />" . xlt('N/A') . "&nbsp;</td>";
    //
    //Added on 5-jun-2k14 (regarding 'Smoking Status - display SNOMED code description')
    echo "<td class='text' ><div id='smoke_code'></div></td>";
    echo "</tr>";
    echo "</table>";
  }

  // static text.  read-only, of course.
  else if ($data_type == 31) {
    echo nl2br($frow['description']);
  }

  //$data_type == 33
  // Race and Ethnicity. After added support for backup lists, this is now the same as datatype 1; so have migrated it there.
  //$data_type == 33

  else if($data_type == 34){
    $arr = explode("|*|*|*|",$currvalue);
    echo "<a href='../../../library/custom_template/custom_template.php?type=form_{$field_id}&contextName=".htmlspecialchars($list_id_esc,ENT_QUOTES)."' class='iframe_medium' style='text-decoration:none;color:black;'>";
    echo "<div id='form_{$field_id}_div' class='text-area'>".htmlspecialchars($arr[0],ENT_QUOTES)."</div>";
    echo "<div style='display:none'><textarea name='form_{$field_id}' id='form_{$field_id}' style='display:none' $lbfonchange $disabled>" . $currvalue . "</textarea></div>";
    echo "</a>";
  }

  //facilities drop-down list
  else if ($data_type == 35) {
    if (empty($currvalue)){
   	  $currvalue = 0;
    }
    dropdown_facility($selected = $currvalue, $name = "form_$field_id_esc",
      $allow_unspecified = true, $allow_allfacilities = false, $disabled, $lbfchange);
  }

  //multiple select
  // supports backup list
  else if ($data_type == 36) {
  	echo generate_select_list("form_$field_id", $list_id, $currvalue,
      $description, $showEmpty ? $empty_title : '', '', $onchange, '', null, true, $backup_list);

  }

  // Canvas and related elements for browser-side image drawing.
  // Note you must invoke lbf_canvas_head() (below) to use this field type in a form.
  else if ($data_type == 40) {
    // Unlike other field types, width and height are in pixels.
    $canWidth  = intval($frow['fld_length']);
    $canHeight = intval($frow['fld_rows']);
    if (empty($currvalue)) {
      if (preg_match('/\\bimage=([a-zA-Z0-9._-]*)/', $frow['description'], $matches)) {
        // If defined this is the filename of the default starting image.
        $currvalue = $GLOBALS['web_root'] . '/sites/' . $_SESSION['site_id'] . '/images/' . $matches[1];
      }
    }
    echo "<div id='form_$field_id_esc'></div>";
    // Hidden form field exists to send updated data to the server at submit time.
    echo "<input type='hidden' name='form_$field_id_esc' value='' />";
    // Hidden image exists to support initialization of the canvas.
    echo "<img src='" . attr($currvalue) . "' id='form_{$field_id_esc}_img' style='display:none'>";
    // $date_init is a misnomer but it's the place for browser-side setup logic.
    $date_init .= " lbfCanvasSetup('form_$field_id_esc', $canWidth, $canHeight);\n";
  }

}
示例#8
0
        } else {
            ?>
  <td class='detail'>
   <?php 
            echo $key == 'z' ? '' : $key;
            ?>
  </td>
  <td class='detail'>
<?php 
            if (empty($key)) {
                echo xl('Undiagnosed');
            } else {
                if ($key == 'z') {
                    echo xl('No injury/illness');
                } else {
                    echo lookup_code_descriptions($key);
                }
            }
            ?>
  </td>
<?php 
        }
        ?>
  <!--
  <td class='detail' align='right'>
   <?php 
        // echo $row['count']
        ?>
  </td>
  -->
  <td class='detail' align='right'>
示例#9
0
 public function save(&$bill, &$prod, $main_provid = NULL, $main_supid = NULL, $default_warehouse = NULL, $mark_as_closed = false)
 {
     global $code_types;
     if (isset($main_provid) && $main_supid == $main_provid) {
         $main_supid = 0;
     }
     $copay_update = FALSE;
     $update_session_id = '';
     $ct0 = '';
     // takes the code type of the first fee type code type entry from the fee sheet, against which the copay is posted
     $cod0 = '';
     // takes the code of the first fee type code type entry from the fee sheet, against which the copay is posted
     $mod0 = '';
     // takes the modifier of the first fee type code type entry from the fee sheet, against which the copay is posted
     if (is_array($bill)) {
         foreach ($bill as $iter) {
             // Skip disabled (billed) line items.
             if (!empty($iter['billed'])) {
                 continue;
             }
             $id = $iter['id'];
             $code_type = $iter['code_type'];
             $code = $iter['code'];
             $del = !empty($iter['del']);
             $units = empty($iter['units']) ? 1 : intval($iter['units']);
             $price = empty($iter['price']) ? 0 : 0 + trim($iter['price']);
             $pricelevel = empty($iter['pricelevel']) ? '' : $iter['pricelevel'];
             $modifier = empty($iter['mod']) ? '' : trim($iter['mod']);
             $justify = empty($iter['justify']) ? '' : trim($iter['justify']);
             $notecodes = empty($iter['notecodes']) ? '' : trim($iter['notecodes']);
             $provid = empty($iter['provid']) ? 0 : intval($iter['provid']);
             $fee = sprintf('%01.2f', $price * $units);
             if (!$cod0 && $code_types[$code_type]['fee'] == 1) {
                 $mod0 = $modifier;
                 $cod0 = $code;
                 $ct0 = $code_type;
             }
             if ($code_type == 'COPAY') {
                 if ($fee < 0) {
                     $fee = $fee * -1;
                 }
                 if (!$id) {
                     // adding new copay from fee sheet into ar_session and ar_activity tables
                     $session_id = idSqlStatement("INSERT INTO ar_session " . "(payer_id, user_id, pay_total, payment_type, description, patient_id, payment_method, " . "adjustment_code, post_to_date) " . "VALUES ('0',?,?,'patient','COPAY',?,'','patient_payment',now())", array($_SESSION['authId'], $fee, $this->pid));
                     sqlBeginTrans();
                     $sequence_no = sqlQuery("SELECT IFNULL(MAX(sequence_no),0) + 1 AS increment FROM ar_activity WHERE " . "pid = ? AND encounter = ?", array($this->pid, $this->encounter));
                     SqlStatement("INSERT INTO ar_activity (pid, encounter, sequence_no, code_type, code, modifier, " . "payer_type, post_time, post_user, session_id, " . "pay_amount, account_code) VALUES (?,?,?,?,?,?,0,now(),?,?,?,'PCP')", array($this->pid, $this->encounter, $sequence_no['increment'], $ct0, $cod0, $mod0, $_SESSION['authId'], $session_id, $fee));
                     sqlCommitTrans();
                 } else {
                     // editing copay saved to ar_session and ar_activity
                     $session_id = $id;
                     $res_amount = sqlQuery("SELECT pay_amount FROM ar_activity WHERE pid=? AND encounter=? AND session_id=?", array($this->pid, $this->encounter, $session_id));
                     if ($fee != $res_amount['pay_amount']) {
                         sqlStatement("UPDATE ar_session SET user_id=?,pay_total=?,modified_time=now(),post_to_date=now() WHERE session_id=?", array($_SESSION['authId'], $fee, $session_id));
                         sqlStatement("UPDATE ar_activity SET code_type=?, code=?, modifier=?, post_user=?, post_time=now()," . "pay_amount=?, modified_time=now() WHERE pid=? AND encounter=? AND account_code='PCP' AND session_id=?", array($ct0, $cod0, $mod0, $_SESSION['authId'], $fee, $this->pid, $this->encounter, $session_id));
                     }
                 }
                 if (!$cod0) {
                     $copay_update = TRUE;
                     $update_session_id = $session_id;
                 }
                 continue;
             }
             # Code to create justification for all codes based on first justification
             if ($GLOBALS['replicate_justification'] == '1') {
                 if ($justify != '') {
                     $autojustify = $justify;
                 }
             }
             if ($GLOBALS['replicate_justification'] == '1' && $justify == '' && check_is_code_type_justify($code_type)) {
                 $justify = $autojustify;
             }
             if ($justify) {
                 $justify = str_replace(',', ':', $justify) . ':';
             }
             $auth = "1";
             $ndc_info = '';
             if (!empty($iter['ndcnum'])) {
                 $ndc_info = 'N4' . trim($iter['ndcnum']) . '   ' . $iter['ndcuom'] . trim($iter['ndcqty']);
             }
             // If the item is already in the database...
             if ($id) {
                 if ($del) {
                     $this->logFSMessage(xl('Service deleted'));
                     deleteBilling($id);
                 } else {
                     $tmp = sqlQuery("SELECT * FROM billing WHERE id = ? AND (billed = 0 or billed is NULL) AND activity = 1", array($id));
                     if (!empty($tmp)) {
                         $tmparr = array('code' => $code, 'authorized' => $auth);
                         if (isset($iter['units'])) {
                             $tmparr['units'] = $units;
                         }
                         if (isset($iter['price'])) {
                             $tmparr['fee'] = $fee;
                         }
                         if (isset($iter['pricelevel'])) {
                             $tmparr['pricelevel'] = $pricelevel;
                         }
                         if (isset($iter['mod'])) {
                             $tmparr['modifier'] = $modifier;
                         }
                         if (isset($iter['provid'])) {
                             $tmparr['provider_id'] = $provid;
                         }
                         if (isset($iter['ndcnum'])) {
                             $tmparr['ndc_info'] = $ndc_info;
                         }
                         if (isset($iter['justify'])) {
                             $tmparr['justify'] = $justify;
                         }
                         if (isset($iter['notecodes'])) {
                             $tmparr['notecodes'] = $notecodes;
                         }
                         foreach ($tmparr as $key => $value) {
                             if ($tmp[$key] != $value) {
                                 if ('fee' == $key) {
                                     $this->logFSMessage(xl('Price changed'));
                                 }
                                 if ('units' == $key) {
                                     $this->logFSMessage(xl('Quantity changed'));
                                 }
                                 if ('provider_id' == $key) {
                                     $this->logFSMessage(xl('Service provider changed'));
                                 }
                                 sqlStatement("UPDATE billing SET `{$key}` = ? WHERE id = ?", array($value, $id));
                             }
                         }
                     }
                 }
             } else {
                 if (!$del) {
                     $this->logFSMessage(xl('Service added'));
                     $code_text = lookup_code_descriptions($code_type . ":" . $code);
                     addBilling($this->encounter, $code_type, $code, $code_text, $this->pid, $auth, $provid, $modifier, $units, $fee, $ndc_info, $justify, 0, $notecodes, $pricelevel);
                 }
             }
         }
     }
     // end for
     // if modifier is not inserted during loop update the record using the first
     // non-empty modifier and code
     if ($copay_update == TRUE && $update_session_id != '' && $mod0 != '') {
         sqlStatement("UPDATE ar_activity SET code_type = ?, code = ?, modifier = ?" . " WHERE pid = ? AND encounter = ? AND account_code = 'PCP' AND session_id = ?", array($ct0, $cod0, $mod0, $this->pid, $this->encounter, $update_session_id));
     }
     // Doing similarly to the above but for products.
     if (is_array($prod)) {
         foreach ($prod as $iter) {
             // Skip disabled (billed) line items.
             if (!empty($iter['billed'])) {
                 continue;
             }
             $drug_id = $iter['drug_id'];
             $selector = empty($iter['selector']) ? '' : $iter['selector'];
             $sale_id = $iter['sale_id'];
             // present only if already saved
             $units = max(1, intval(trim($iter['units'])));
             $price = empty($iter['price']) ? 0 : 0 + trim($iter['price']);
             $pricelevel = empty($iter['pricelevel']) ? '' : $iter['pricelevel'];
             $fee = sprintf('%01.2f', $price * $units);
             $del = !empty($iter['del']);
             $rxid = 0;
             $warehouse_id = empty($iter['warehouse']) ? '' : $iter['warehouse'];
             $somechange = false;
             // If the item is already in the database...
             if ($sale_id) {
                 $tmprow = sqlQuery("SELECT ds.prescription_id, ds.quantity, ds.inventory_id, ds.fee, " . "ds.sale_date, di.warehouse_id " . "FROM drug_sales AS ds " . "LEFT JOIN drug_inventory AS di ON di.inventory_id = ds.inventory_id " . "WHERE ds.sale_id = ?", array($sale_id));
                 $rxid = 0 + $tmprow['prescription_id'];
                 if ($del) {
                     if (!empty($tmprow)) {
                         // Delete this sale and reverse its inventory update.
                         $this->logFSMessage(xl('Product deleted'));
                         sqlStatement("DELETE FROM drug_sales WHERE sale_id = ?", array($sale_id));
                         if (!empty($tmprow['inventory_id'])) {
                             sqlStatement("UPDATE drug_inventory SET on_hand = on_hand + ? WHERE inventory_id = ?", array($tmprow['quantity'], $tmprow['inventory_id']));
                         }
                     }
                     if ($rxid) {
                         sqlStatement("DELETE FROM prescriptions WHERE id = ?", array($rxid));
                     }
                 } else {
                     // Modify the sale and adjust inventory accordingly.
                     if (!empty($tmprow)) {
                         foreach (array('quantity' => $units, 'fee' => $fee, 'pricelevel' => $pricelevel, 'selector' => $selector, 'sale_date' => $this->visit_date) as $key => $value) {
                             if ($tmprow[$key] != $value) {
                                 $somechange = true;
                                 if ('fee' == $key) {
                                     $this->logFSMessage(xl('Price changed'));
                                 }
                                 if ('pricelevel' == $key) {
                                     $this->logFSMessage(xl('Price level changed'));
                                 }
                                 if ('selector' == $key) {
                                     $this->logFSMessage(xl('Template selector changed'));
                                 }
                                 if ('quantity' == $key) {
                                     $this->logFSMessage(xl('Quantity changed'));
                                 }
                                 sqlStatement("UPDATE drug_sales SET `{$key}` = ? WHERE sale_id = ?", array($value, $sale_id));
                                 if ($key == 'quantity' && $tmprow['inventory_id']) {
                                     sqlStatement("UPDATE drug_inventory SET on_hand = on_hand - ? WHERE inventory_id = ?", array($units - $tmprow['quantity'], $tmprow['inventory_id']));
                                 }
                             }
                         }
                         if ($tmprow['inventory_id'] && $warehouse_id && $warehouse_id != $tmprow['warehouse_id']) {
                             // Changing warehouse.  Requires deleting and re-adding the sale.
                             // Not setting $somechange because this alone does not affect a prescription.
                             $this->logFSMessage(xl('Warehouse changed'));
                             sqlStatement("DELETE FROM drug_sales WHERE sale_id = ?", array($sale_id));
                             sqlStatement("UPDATE drug_inventory SET on_hand = on_hand + ? WHERE inventory_id = ?", array($units, $tmprow['inventory_id']));
                             $tmpnull = null;
                             $sale_id = sellDrug($drug_id, $units, $fee, $this->pid, $this->encounter, empty($iter['rx']) ? 0 : $rxid, $this->visit_date, '', $warehouse_id, false, $tmpnull, $pricelevel, $selector);
                         }
                     }
                     // Delete Rx if $rxid and flag not set.
                     if ($GLOBALS['gbl_auto_create_rx'] && $rxid && empty($iter['rx'])) {
                         sqlStatement("UPDATE drug_sales SET prescription_id = 0 WHERE sale_id = ?", array($sale_id));
                         sqlStatement("DELETE FROM prescriptions WHERE id = ?", array($rxid));
                     }
                 }
             } else {
                 if (!$del) {
                     $somechange = true;
                     $this->logFSMessage(xl('Product added'));
                     $tmpnull = null;
                     $sale_id = sellDrug($drug_id, $units, $fee, $this->pid, $this->encounter, 0, $this->visit_date, '', $warehouse_id, false, $tmpnull, $pricelevel, $selector);
                     if (!$sale_id) {
                         die(xlt("Insufficient inventory for product ID") . " \"" . text($drug_id) . "\".");
                     }
                 }
             }
             // If a prescription applies, create or update it.
             if (!empty($iter['rx']) && !$del && ($somechange || empty($rxid))) {
                 // If an active rx already exists for this drug and date we will
                 // replace it, otherwise we'll make a new one.
                 if (empty($rxid)) {
                     $rxid = '';
                 }
                 // Get default drug attributes; prefer the template with the matching selector.
                 $drow = sqlQuery("SELECT dt.*, " . "d.name, d.form, d.size, d.unit, d.route, d.substitute " . "FROM drugs AS d, drug_templates AS dt WHERE " . "d.drug_id = ? AND dt.drug_id = d.drug_id " . "ORDER BY (dt.selector = ?) DESC, dt.quantity, dt.dosage, dt.selector LIMIT 1", array($drug_id, $selector));
                 if (!empty($drow)) {
                     $rxobj = new Prescription($rxid);
                     $rxobj->set_patient_id($this->pid);
                     $rxobj->set_provider_id(isset($main_provid) ? $main_provid : $this->provider_id);
                     $rxobj->set_drug_id($drug_id);
                     $rxobj->set_quantity($units);
                     $rxobj->set_per_refill($units);
                     $rxobj->set_start_date_y(substr($this->visit_date, 0, 4));
                     $rxobj->set_start_date_m(substr($this->visit_date, 5, 2));
                     $rxobj->set_start_date_d(substr($this->visit_date, 8, 2));
                     $rxobj->set_date_added($this->visit_date);
                     // Remaining attributes are the drug and template defaults.
                     $rxobj->set_drug($drow['name']);
                     $rxobj->set_unit($drow['unit']);
                     $rxobj->set_dosage($drow['dosage']);
                     $rxobj->set_form($drow['form']);
                     $rxobj->set_refills($drow['refills']);
                     $rxobj->set_size($drow['size']);
                     $rxobj->set_route($drow['route']);
                     $rxobj->set_interval($drow['period']);
                     $rxobj->set_substitute($drow['substitute']);
                     //
                     $rxobj->persist();
                     // Set drug_sales.prescription_id to $rxobj->get_id().
                     $oldrxid = $rxid;
                     $rxid = 0 + $rxobj->get_id();
                     if ($rxid != $oldrxid) {
                         sqlStatement("UPDATE drug_sales SET prescription_id = ? WHERE sale_id = ?", array($rxid, $sale_id));
                     }
                 }
             }
         }
     }
     // end for
     // Set default and/or supervising provider for the encounter.
     if (isset($main_provid) && $main_provid != $this->provider_id) {
         $this->logFSMessage(xl('Default provider changed'));
         sqlStatement("UPDATE form_encounter SET provider_id = ? WHERE pid = ? AND encounter = ?", array($main_provid, $this->pid, $this->encounter));
         $this->provider_id = $main_provid;
     }
     if (isset($main_supid) && $main_supid != $this->supervisor_id) {
         sqlStatement("UPDATE form_encounter SET supervisor_id = ? WHERE pid = ? AND encounter = ?", array($main_supid, $this->pid, $this->encounter));
         $this->supervisor_id = $main_supid;
     }
     // Save-and-Close is currently specific to Family Planning but might be more
     // generally useful.  It provides the ability to mark an encounter as billed
     // directly from the Fee Sheet, if there are no charges.
     if ($mark_as_closed) {
         $tmp1 = sqlQuery("SELECT SUM(ABS(fee)) AS sum FROM drug_sales WHERE " . "pid = ? AND encounter = ? AND billed = 0", array($this->pid, $this->encounter));
         $tmp2 = sqlQuery("SELECT SUM(ABS(fee)) AS sum FROM billing WHERE " . "pid = ? AND encounter = ? AND billed = 0 AND activity = 1", array($this->pid, $this->encounter));
         if ($tmp1['sum'] + $tmp2['sum'] == 0) {
             sqlStatement("update drug_sales SET billed = 1 WHERE " . "pid = ? AND encounter = ? AND billed = 0", array($this->pid, $this->encounter));
             sqlStatement("UPDATE billing SET billed = 1, bill_date = NOW() WHERE " . "pid = ? AND encounter = ? AND billed = 0 AND activity = 1", array($this->pid, $this->encounter));
         } else {
             // Would be good to display an error message here... they clicked
             // Save and Close but the close could not be done.  However the
             // framework does not provide an easy way to do that.
         }
     }
 }
示例#10
0
/**
 *  This function prepares a code found in a clinical field and returns it in $codes_found format.
 *  @param $code is in the format code_type:code eg. ICD10:H34.811
 *  @param $location is the descruiptive name of the clinical field in question
 *  @param $side is optional.  Used as the descriptive text for the finding in the Builder
 *      and IMP/Plan if selected from the Builder
 *  @return $subterm,$newdata.  $subterm is used to link items in IMP/PLAN back to its orgin.
 *          $newdata is the array of newly found items to include in the Builder.
 *
 *  This function is not called directly but via the wrapper function start_your_engines().
 */
function coding_engine($term, $code_found, $location, $side = '')
{
    if (strpos($code_found['code'], ":")) {
        list($code_type, $code) = explode(':', $code_found['code']);
    } else {
        $code = $code_found['code'];
        $code_type = "ICD10";
        //default to ICD10
        $code_found['code'] = $code_type . ":" . $code_found['code'];
    }
    $code_desc = lookup_code_descriptions($code_found['code']);
    $order = array("\r\n", "\n", "\r");
    $code_desc = str_replace($order, '', $code_desc);
    $code_text = text($code_found['code']) . " (" . text($code_desc) . ")";
    $replace = " ";
    $sub_term = str_replace($replace, "", $term);
    //some codes are bilateral, some not, some are per eyelid.  Comment this out for now:
    //(preg_match("/right/",$code_desc))? $side = xlt('OD{{right eye}}') : $side = xlt('OS{{left eye}}');
    $newdata = array('title' => ucfirst($term) . " " . $side, 'location' => $location, 'diagnosis' => $code, 'code' => $code, 'codetype' => $code_found['code_type'], 'codedesc' => $code_desc, 'codetext' => $code_text, 'PMSFH_link' => "Clinical_" . $sub_term);
    return array($sub_term, $newdata);
}
                $begsecs = $endsecs;
            }
            if ($last_endsecs < $endsecs) {
                $last_endsecs = $endsecs;
            }
            $daysmissed = round(($endsecs - $begsecs) / (60 * 60 * 24));
        }
        // Get the name of the last provider for this issue.
        $query = "SELECT users.lname, users.fname, users.mname " . "FROM issue_encounter, forms, users WHERE " . "issue_encounter.list_id = {$listid} AND " . "forms.pid = issue_encounter.pid AND " . "forms.encounter = issue_encounter.encounter AND " . "users.username = forms.user " . "ORDER BY forms.date DESC LIMIT 1";
        $user = sqlQuery($query);
        $provname = $user['lname'] ? $user['lname'] . ', ' . $user['fname'] . ' ' . $user['mname'] : '&nbsp;';
        echo " <tr bgcolor='{$bgcolor}' onclick='dopclick({$listid},{$thispid})' style='cursor:pointer'>\n";
        echo "  <td class='detail'>{$ptname}</td>\n";
        echo "  <td class='detail'>{$fitness}</td>\n";
        echo "  <td class='detail'>{$issue_title}</td>\n";
        echo "  <td class='detail'>" . lookup_code_descriptions($row['diagnosis']) . "</td>\n";
        echo "  <td class='detail'>" . $row['begdate'] . "</td>\n";
        echo "  <td class='detail' align='right'>{$daysmissed}</td>\n";
        echo "  <td class='detail' align='right'>" . $row['gmissed'] . "</td>\n";
        echo "  <td class='detail'>{$provname}</td>\n";
        echo " </tr>\n";
    }
    // end while
    ?>

</table>

<?php 
}
// end of if ($_POST['form_refresh'])
?>
示例#12
0
                                <table>
                                  <tr>
                                    <td style="padding-right:20px;padding-left:20px;">
                                    <?php 
$counter = '0';
$count = '0';
$arrTESTS = explode("|", $Resource);
//form_eye_mag:Resource = billable things (not visit code) performed today
$query = "select * from list_options where list_id=? and activity='1' order by seq";
$TODO_data = sqlStatement($query, array("Eye_todo_done_" . $providerID));
while ($row = sqlFetchArray($TODO_data)) {
    if ($row['codes'] === '') {
        continue;
    }
    list($code_type_here, $code) = explode(":", $row['codes']);
    $codedesc = lookup_code_descriptions($row['codes']);
    $order = array("\r\n", "\n", "\r");
    $codedesc = str_replace($order, '', $codedesc);
    if ($codedesc == '') {
        $codedesc = $row['title'];
    }
    $codetext = $codedesc . " (" . $row['codes'] . ")";
    $checked = '';
    if (in_array($row['codes'], $arrTESTS)) {
        $checked = "checked='yes'";
    }
    /**
     *  This will link to a report generator for billable procedures/tests.
     *  They items need to be read/interpreted/dictated/documented to be billable.
     *  The reading may already be documented within the scanned item itself.
     *  Thus this will be optional.
示例#13
0
    private function getIid($val)
    {
        global $pid;
        global $ISSUE_TYPES;
        $inclookupres = sqlStatement("SELECT DISTINCT formdir FROM forms WHERE pid = ? AND deleted=?", array($pid, 0));
        while ($result = sqlFetchArray($inclookupres)) {
            $formdir = $result['formdir'];
            if (substr($formdir, 0, 3) == 'LBF') {
                include_once $GLOBALS['incdir'] . "/forms/LBF/report.php";
            } else {
                include_once $GLOBALS['incdir'] . "/forms/{$formdir}/report.php";
            }
        }
        ?>
	    <tr class=text>
		<td></td>
		<td>
	    <?php 
        $irow = sqlQuery("SELECT type, title, comments, diagnosis FROM lists WHERE id =? ", array($val));
        $diagnosis = $irow['diagnosis'];
        if ($prevIssueType != $irow['type']) {
            $disptype = $ISSUE_TYPES[$irow['type']][0];
            ?>
		<div class='issue_type' style='font-weight: bold;'><?php 
            echo htmlspecialchars($disptype, ENT_QUOTES);
            ?>
:</div>
		<?php 
            $prevIssueType = $irow['type'];
        }
        ?>
	    <div class='text issue'>
	    <span class='issue_title'><?php 
        echo htmlspecialchars($irow['title'], ENT_QUOTES);
        ?>
:</span>
	    <span class='issue_comments'><?php 
        echo htmlspecialchars($irow['comments'], ENT_QUOTES);
        ?>
</span>
	    <?php 
        if ($diagnosis) {
            ?>
		<div class='text issue_diag'>
		<span class='bold'>[<?php 
            echo htmlspecialchars(xl('Diagnosis'), ENT_QUOTES);
            ?>
]</span><br>
		<?php 
            $dcodes = explode(";", $diagnosis);
            foreach ($dcodes as $dcode) {
                ?>
		    <span class='italic'><?php 
                echo htmlspecialchars($dcode, ENT_QUOTES);
                ?>
</span>:
		    <?php 
                echo htmlspecialchars(lookup_code_descriptions($dcode), ENT_QUOTES);
                ?>
		    <br>
		    <?php 
            }
            ?>
		</div>
		<?php 
        }
        if ($irow['type'] == 'ippf_gcac') {
            ?>
		<table>
		<?php 
            display_layout_rows('GCA', sqlQuery("SELECT * FROM lists_ippf_gcac WHERE id = ?", array($rowid)));
            ?>
    
		</table>
		<?php 
        } else {
            if ($irow['type'] == 'contraceptive') {
                ?>
		<table>
		    <?php 
                display_layout_rows('CON', sqlQuery("SELECT * FROM lists_ippf_con WHERE id = ?", array($rowid)));
                ?>
		</table>
		<?php 
            }
        }
        ?>
	    </div>
	    <?php 
        ?>
                            
		</td>
	    <?php 
    }
 $e_ExactDateTime = $ccr->createElement('ExactDateTime', $date->format('Y-m-d\\TH:i:s\\Z'));
 $e_DateTime->appendChild($e_ExactDateTime);
 $e_IDs = $ccr->createElement('IDs');
 $e_Problem->appendChild($e_IDs);
 $e_ID = $ccr->createElement('ID', $row['pid']);
 $e_IDs->appendChild($e_ID);
 $e_IDs->appendChild(sourceType($ccr, $sourceID));
 $e_Type = $ccr->createElement('Type');
 $e_Problem->appendChild($e_Type);
 $e_Text = $ccr->createElement('Text', 'Problem');
 // Changed to pass through validator, Problem type must be one of the required string values: Problem, Condition, Diagnosis, Symptom, Finding, Complaint, Functional Limitation.
 //$e_Text = $ccr->createElement('Text', $row['prob_title']);
 $e_Type->appendChild($e_Text);
 $e_Description = $ccr->createElement('Description');
 $e_Problem->appendChild($e_Description);
 $e_Text = $ccr->createElement('Text', lookup_code_descriptions($row['diagnosis']));
 $e_Description->appendChild($e_Text);
 $e_Code = $ccr->createElement('Code');
 $e_Description->appendChild($e_Code);
 $e_Value = $ccr->createElement('Value', $row['diagnosis']);
 $e_Code->appendChild($e_Value);
 $e_Value = $ccr->createElement('CodingSystem', 'ICD9-CM');
 $e_Code->appendChild($e_Value);
 $e_Status = $ccr->createElement('Status');
 $e_Problem->appendChild($e_Status);
 // $e_Text = $ccr->createElement('Text', $row['outcome']);
 $e_Text = $ccr->createElement('Text', 'Active');
 $e_Status->appendChild($e_Text);
 //$e_CommentID = $ccr->createElement('CommentID', $row['comments']);
 //$e_Problem->appendChild($e_CommentID);
 $e_Source = $ccr->createElement('Source');
示例#15
0
     $provid = 0 + $iter['provid'];
     $ndc_info = '';
     if ($iter['ndcnum']) {
         $ndc_info = 'N4' . trim($iter['ndcnum']) . '   ' . $iter['ndcuom'] . trim($iter['ndcqty']);
     }
     // If the item is already in the database...
     if ($id) {
         if ($del) {
             deleteBilling($id);
         } else {
             // authorizeBilling($id, $auth);
             sqlQuery("UPDATE billing SET code = ?, " . "units = ?, fee = ?, modifier = ?, " . "authorized = ?, provider_id = ?, " . "ndc_info = ?, justify = ?, notecodes = ? " . "WHERE " . "id = ? AND billed = 0 AND activity = 1", array($code, $units, $fee, $modifier, $auth, $provid, $ndc_info, $justify, $notecodes, $id));
         }
     } else {
         if (!$del) {
             $code_text = lookup_code_descriptions($code_type . ":" . $code);
             addBilling($encounter, $code_type, $code, $code_text, $pid, $auth, $provid, $modifier, $units, $fee, $ndc_info, $justify, 0, $notecodes);
         }
     }
 }
 // end for
 //if modifier is not inserted during loop update the record using the first
 //non-empty modifier and code
 if ($copay_update == TRUE && $update_session_id != '' && $mod0 != '') {
     sqlStatement("UPDATE ar_activity SET code_type=?, code=?, modifier=?" . " WHERE pid=? AND encounter=? AND account_code='PCP' AND session_id=?", array($ct0, $cod0, $mod0, $pid, $encounter, $update_session_id));
 }
 // Doing similarly to the above but for products.
 $prod = $_POST['prod'];
 for ($lino = 1; $prod["{$lino}"]['drug_id']; ++$lino) {
     $iter = $prod["{$lino}"];
     if (!empty($iter['billed'])) {
 public function getProblemList($pid, $encounter)
 {
     $problem_lists = '';
     $query = "select l.*, lo.title as observation, lo.codes as observation_code, l.diagnosis AS code\n\t\t\t\t\t\t\t\t\t\t\tfrom lists AS l\n\t\t\t\t\t\t\t\t\t\t\tleft join list_options as lo on lo.option_id = l.outcome AND lo.list_id = ?\n\t\t\t\t\t\t\t\t\t\t\twhere l.type = ? and l.pid = ? AND l.outcome <> ? AND l.id NOT IN(SELECT list_id FROM issue_encounter WHERE pid = ?)";
     $appTable = new ApplicationTable();
     $res = $appTable->zQuery($query, array('outcome', 'medical_problem', $pid, 1, $pid));
     $problem_lists .= '<problem_lists>';
     foreach ($res as $row) {
         $split_codes = explode(';', $row['code']);
         foreach ($split_codes as $key => $single_code) {
             $get_code_details = explode(':', $single_code);
             $code = $get_code_details[1];
             $code_text = lookup_code_descriptions($single_code);
             $age = $this->getAge($pid, $row['begdate']);
             $start_date = str_replace('-', '', $row['begdate']);
             $end_date = str_replace('-', '', $row['enddate']);
             $status = $status_table = '';
             $start_date = $start_date ? $start_date : '0';
             $end_date = $end_date ? $end_date : '0';
             //Active - 55561003 	Completed - 73425007
             if ($end_date) {
                 $status = 'completed';
                 $status_table = 'Resolved';
                 $status_code = '73425007';
             } else {
                 $status = 'active';
                 $status_table = 'Active';
                 $status_code = '55561003';
             }
             $observation = $row['observation'];
             $observation_code = explode(':', $row['observation_code']);
             $observation_code = $observation_code[1];
             $problem_lists .= "<problem>\n\t\t\t\t\t\t<extension>" . htmlspecialchars(base64_encode($_SESSION['site_id'] . $row['id']), ENT_QUOTES) . "</extension>\n\t\t\t\t\t\t<sha_extension>" . htmlspecialchars("ec8a6ff8-ed4b-4f7e-82c3-e98e58b45de7", ENT_QUOTES) . "</sha_extension>\n\t\t\t\t\t\t<title>" . htmlspecialchars($row['title'], ENT_QUOTES) . ($single_code ? " [" . htmlspecialchars($single_code, ENT_QUOTES) . "]" : '') . "</title>\n\t\t\t\t\t\t<code>" . ($code ? $code : 0) . "</code>\n\t\t\t\t\t\t<code_text>" . htmlspecialchars($code_text ? $code_text : 'NULL', ENT_QUOTES) . "</code_text>\n\t\t\t\t\t\t<age>" . $age . "</age>\n\t\t\t\t\t\t<start_date_table>" . $row['begdate'] . "</start_date_table>\n\t\t\t\t\t\t<start_date>" . $start_date . "</start_date>\n\t\t\t\t\t\t<end_date>" . $end_date . "</end_date>\n\t\t\t\t\t\t<status>" . $status . "</status>\n\t\t\t\t\t\t<status_table>" . $status_table . "</status_table>\n\t\t\t\t\t\t<status_code>" . $status_code . "</status_code>\n\t\t\t\t\t\t<observation>" . htmlspecialchars($observation ? \Application\Listener\Listener::z_xlt($observation) : 'NULL', ENT_QUOTES) . "</observation>\n\t\t\t\t\t\t<observation_code>" . htmlspecialchars($observation_code ? $observation_code : 0, ENT_QUOTES) . "</observation_code>\n\t\t\t\t\t\t<diagnosis>" . htmlspecialchars($code ? $code : 0) . "</diagnosis>\n\t\t\t\t\t</problem>";
         }
     }
     $problem_lists .= '</problem_lists>';
     return $problem_lists;
 }
示例#17
0
/**
 * Generate HL7 for the specified procedure order.
 *
 * @param  integer $orderid  Procedure order ID.
 * @param  string  &$out     Container for target HL7 text.
 * @return string            Error text, or empty if no errors.
 */
function gen_hl7_order($orderid, &$out)
{
    // Delimiters
    $d0 = "\r";
    $d1 = '|';
    $d2 = '^';
    $today = time();
    $out = '';
    $porow = sqlQuery("SELECT " . "po.date_collected, po.date_ordered, po.order_priority, " . "pp.*, " . "pd.pid, pd.pubpid, pd.fname, pd.lname, pd.mname, pd.DOB, pd.ss, " . "pd.phone_home, pd.phone_biz, pd.sex, pd.street, pd.city, pd.state, pd.postal_code, " . "f.encounter, u.fname AS docfname, u.lname AS doclname, u.npi AS docnpi " . "FROM procedure_order AS po, procedure_providers AS pp, " . "forms AS f, patient_data AS pd, users AS u " . "WHERE " . "po.procedure_order_id = ? AND " . "pp.ppid = po.lab_id AND " . "f.formdir = 'procedure_order' AND " . "f.form_id = po.procedure_order_id AND " . "pd.pid = f.pid AND " . "u.id = po.provider_id", array($orderid));
    if (empty($porow)) {
        return "Procedure order, ordering provider or lab is missing for order ID '{$orderid}'";
    }
    $pcres = sqlStatement("SELECT " . "pc.procedure_code, pc.procedure_name, pc.procedure_order_seq, pc.diagnoses " . "FROM procedure_order_code AS pc " . "WHERE " . "pc.procedure_order_id = ? AND " . "pc.do_not_send = 0 " . "ORDER BY pc.procedure_order_seq", array($orderid));
    // Message Header
    $out .= "MSH" . $d1 . "{$d2}~\\&" . $d1 . $porow['send_app_id'] . $d1 . $porow['send_fac_id'] . $d1 . $porow['recv_app_id'] . $d1 . $porow['recv_fac_id'] . $d1 . date('YmdHis', $today) . $d1 . $d1 . 'ORM' . $d2 . 'O01' . $d1 . $orderid . $d1 . $porow['DorP'] . $d1 . '2.3' . $d0;
    // Patient Identification
    $out .= "PID" . $d1 . "1" . $d1 . $porow['pid'] . $d1 . $porow['pid'] . $d1 . $d1 . hl7Text($porow['lname']) . $d2 . hl7Text($porow['fname']);
    if ($porow['mname']) {
        $out .= $d2 . hl7Text($porow['mname']);
    }
    $out .= $d1 . $d1 . hl7Date($porow['DOB']) . $d1 . hl7Sex($porow['sex']) . $d1 . $d1 . $d1 . hl7Text($porow['street']) . $d2 . $d2 . hl7Text($porow['city']) . $d2 . hl7Text($porow['state']) . $d2 . hl7Zip($porow['postal_code']) . $d1 . $d1 . hl7Phone($porow['phone_home']) . $d1 . hl7Phone($porow['phone_biz']) . $d1 . $d1 . $d1 . $d1 . $porow['encounter'] . $d1 . hl7SSN($porow['ss']) . $d1 . $d1 . $d1 . $d0;
    // NTE segment(s) omitted.
    // Patient Visit.
    $out .= "PV1" . $d1 . "1" . $d1 . $d1 . $d1 . $d1 . $d1 . $d1 . hl7Text($porow['docnpi']) . $d2 . hl7Text($porow['doclname']) . $d2 . hl7Text($porow['docfname']) . str_repeat($d1, 11) . $d1 . $porow['encounter'] . str_repeat($d1, 13) . $d0;
    // Insurance stuff.
    $payers = loadPayerInfo($porow['pid'], $porow['date_ordered']);
    $setid = 0;
    foreach ($payers as $payer) {
        $payer_object = $payer['object'];
        $payer_address = $payer_object->get_address();
        $out .= "IN1" . $d1 . ++$setid . $d1 . $d1 . hl7Text($payer['company']['id']) . $d1 . hl7Text($payer['company']['name']) . $d1 . hl7Text($payer_address->get_line1()) . $d2 . $d2 . hl7Text($payer_address->get_city()) . $d2 . hl7Text($payer_address->get_state()) . $d2 . hl7Zip($payer_address->get_zip()) . $d1 . $d1 . hl7Phone($payer_object->get_phone()) . $d1 . hl7Text($payer['data']['group_number']) . str_repeat($d1, 7) . $d1 . hl7Text($payer['data']['subscriber_lname']) . $d2 . hl7Text($payer['data']['subscriber_fname']) . $d2 . hl7Text($payer['data']['subscriber_mname']) . $d1 . hl7Relation($payer['data']['subscriber_relationship']) . $d1 . hl7Date($payer['data']['subscriber_DOB']) . $d1 . hl7Date($payer['data']['subscriber_street']) . $d2 . $d2 . hl7Text($payer['data']['subscriber_city']) . $d2 . hl7Text($payer['data']['subscriber_state']) . $d2 . hl7Zip($payer['data']['subscriber_postal_code']) . $d1 . $d1 . $d1 . $setid . str_repeat($d1, 13) . $d1 . hl7Text($payer['data']['policy_number']) . str_repeat($d1, 12) . $d0;
        // IN2 segment omitted.
    }
    // Guarantor. OpenEMR doesn't have these so use the patient.
    $out .= "GT1" . $d1 . "1" . $d1 . $d1 . hl7Text($porow['lname']) . $d2 . hl7Text($porow['fname']);
    if ($porow['mname']) {
        $out .= $d2 . hl7Text($porow['mname']);
    }
    $out .= $d1 . $d1 . hl7Text($porow['street']) . $d2 . $d2 . hl7Text($porow['city']) . $d2 . hl7Text($porow['state']) . $d2 . hl7Zip($porow['postal_code']) . $d1 . hl7Phone($porow['phone_home']) . $d1 . hl7Phone($porow['phone_biz']) . $d1 . hl7Date($porow['DOB']) . $d1 . hl7Sex($porow['sex']) . $d1 . $d1 . 'self' . $d1 . hl7SSN($porow['ss']) . $d0;
    // Common Order.
    $out .= "ORC" . $d1 . "NW" . $d1 . $orderid . str_repeat($d1, 6) . $d1 . date('YmdHis') . $d1 . $d1 . $d1 . hl7Text($porow['docnpi']) . $d2 . hl7Text($porow['doclname']) . $d2 . hl7Text($porow['docfname']) . str_repeat($d1, 7) . $d1 . "2" . $d0;
    $setid = 0;
    while ($pcrow = sqlFetchArray($pcres)) {
        // Observation Request.
        $out .= "OBR" . $d1 . ++$setid . $d1 . $orderid . $d1 . $d1 . hl7Text($pcrow['procedure_code']) . $d2 . hl7Text($pcrow['procedure_name']) . $d1 . hl7Priority($porow['order_priority']) . $d1 . $d1 . hl7Time($porow['date_collected']) . str_repeat($d1, 8) . $d1 . hl7Text($porow['docnpi']) . $d2 . hl7Text($porow['doclname']) . $d2 . hl7Text($porow['docfname']) . $d1 . $d1 . (count($payers) ? 'I' : 'P') . str_repeat($d1, 8) . $d1 . '0' . $d0;
        // Diagnoses.  Currently hard-coded for ICD9 and we'll surely want to make
        // this more flexible (probably when some lab needs another diagnosis type).
        $setid2 = 0;
        if (!empty($pcrow['diagnoses'])) {
            $relcodes = explode(';', $pcrow['diagnoses']);
            foreach ($relcodes as $codestring) {
                if ($codestring === '') {
                    continue;
                }
                list($codetype, $code) = explode(':', $codestring);
                if ($codetype !== 'ICD9') {
                    continue;
                }
                $desc = lookup_code_descriptions($codestring);
                $out .= "DG1" . $d1 . ++$setid2 . $d1 . $d1 . $code . $d1 . hl7Text($desc) . $d0;
            }
        }
        // Order entry questions and answers.
        $qres = sqlStatement("SELECT " . "a.question_code, a.answer, q.fldtype " . "FROM procedure_answers AS a " . "LEFT JOIN procedure_questions AS q ON " . "q.lab_id = ? " . "AND q.procedure_code = ? AND " . "q.question_code = a.question_code " . "WHERE " . "a.procedure_order_id = ? AND " . "a.procedure_order_seq = ? " . "ORDER BY q.seq, a.answer_seq", array($porow['ppid'], $pcrow['procedure_code'], $orderid, $pcrow['procedure_order_seq']));
        $setid2 = 0;
        while ($qrow = sqlFetchArray($qres)) {
            // Formatting of these answer values may be lab-specific and we'll figure
            // out how to deal with that as more labs are supported.
            $answer = trim($qrow['answer']);
            $fldtype = $qrow['fldtype'];
            $datatype = 'ST';
            if ($fldtype == 'N') {
                $datatype = "NM";
            } else {
                if ($fldtype == 'D') {
                    $answer = hl7Date($answer);
                } else {
                    if ($fldtype == 'G') {
                        $weeks = intval($answer / 7);
                        $days = $answer % 7;
                        $answer = $weeks . 'wks ' . $days . 'days';
                    }
                }
            }
            $out .= "OBX" . $d1 . ++$setid2 . $d1 . $datatype . $d1 . hl7Text($qrow['question_code']) . $d1 . $d1 . hl7Text($answer) . $d0;
        }
    }
    return '';
}
示例#18
0
function lbf_current_value($frow, $formid, $encounter)
{
    global $pid;
    $formname = $frow['form_id'];
    $field_id = $frow['field_id'];
    $source = $frow['source'];
    $currvalue = '';
    $deffname = $formname . '_default_' . $field_id;
    if ($source == 'D' || $source == 'H') {
        // Get from patient_data, employer_data or history_data.
        if ($source == 'H') {
            $table = 'history_data';
            $orderby = 'ORDER BY date DESC LIMIT 1';
        } else {
            if (strpos($field_id, 'em_') === 0) {
                $field_id = substr($field_id, 3);
                $table = 'employer_data';
                $orderby = 'ORDER BY date DESC LIMIT 1';
            } else {
                $table = 'patient_data';
                $orderby = '';
            }
        }
        // It is an error if the field does not exist, but don't crash.
        $tmp = sqlQuery("SHOW COLUMNS FROM {$table} WHERE Field = ?", array($field_id));
        if (empty($tmp)) {
            return FALSE;
        }
        $pdrow = sqlQuery("SELECT `{$field_id}` AS field_value FROM {$table} WHERE pid = ? {$orderby}", array($pid));
        if (isset($pdrow)) {
            $currvalue = $pdrow['field_value'];
        }
    } else {
        if ($source == 'E') {
            if ($encounter) {
                // Get value from shared_attributes of the current encounter.
                $sarow = sqlQuery("SELECT field_value FROM shared_attributes WHERE " . "pid = ? AND encounter = ? AND field_id = ?", array($pid, $encounter, $field_id));
                if (isset($sarow)) {
                    $currvalue = $sarow['field_value'];
                }
            } else {
                if ($formid) {
                    // Get from shared_attributes of the encounter that this form is linked to.
                    // Note the importance of having an index on forms.form_id.
                    $sarow = sqlQuery("SELECT sa.field_value " . "FROM forms AS f, shared_attributes AS sa WHERE " . "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " . "sa.pid = f.pid AND sa.encounter = f.encounter AND sa.field_id = ?", array($formid, $formname, $field_id));
                    if (!empty($sarow)) {
                        $currvalue = $sarow['field_value'];
                    }
                } else {
                    // New form and encounter not available, this should not happen.
                }
            }
        } else {
            if ($source == 'V') {
                if ($encounter) {
                    // Get value from the current encounter's form_encounter.
                    $ferow = sqlQuery("SELECT * FROM form_encounter WHERE " . "pid = ? AND encounter = ?", array($pid, $encounter));
                    if (isset($ferow[$field_id])) {
                        $currvalue = $ferow[$field_id];
                    }
                } else {
                    if ($formid) {
                        // Get value from the form_encounter that this form is linked to.
                        $ferow = sqlQuery("SELECT fe.* " . "FROM forms AS f, form_encounter AS fe WHERE " . "f.form_id = ? AND f.formdir = ? AND f.deleted = 0 AND " . "fe.pid = f.pid AND fe.encounter = f.encounter", array($formid, $formname));
                        if (isset($ferow[$field_id])) {
                            $currvalue = $ferow[$field_id];
                        }
                    } else {
                        // New form and encounter not available, this should not happen.
                    }
                }
            } else {
                if ($formid) {
                    // This is a normal form field.
                    $ldrow = sqlQuery("SELECT field_value FROM lbf_data WHERE " . "form_id = ? AND field_id = ?", array($formid, $field_id));
                    if (!empty($ldrow)) {
                        //ViSolve: Fix to display the Code description when Option "2" is selected
                        if ($frow['data_type'] == "15" && $frow['edit_options'] == "2") {
                            $currvalue = lookup_code_descriptions($ldrow['field_value']);
                        } else {
                            $currvalue = $ldrow['field_value'];
                        }
                    }
                } else {
                    // New form, see if there is a custom default from a plugin.
                    // This logic does not apply to shared attributes because they do not
                    // have a "new form" concept.
                    if (function_exists($deffname)) {
                        $currvalue = call_user_func($deffname);
                    }
                }
            }
        }
    }
    return $currvalue;
}