some portal work
[openemr.git] / library / encounter.inc
blobb06b5dec779c28003a793143b0e64986a0279f3a
1 <?php
2 require_once(__DIR__."/forms.inc");
4 //function called to set the global session variable for encounter number
5 function setencounter($enc)
8     // Escape $enc by forcing it to an integer to protect from sql injection
9     $enc = intval($enc);
11     $return_val = 1;
12     global $encounter;
13     global $pid;
14     global $attendant_type;
16     $attendant_id = $attendant_type == 'pid' ? $pid : $_SESSION['therapy_group'];
17     if ($enc == "") {
18         $enc = date("Ymd");
19         if (getFormByEncounter($attendant_id, $enc)) {
20             //there is an encounter enterred for today
21         } else {
22             //addForm($enc, "New Patient Encounter", 0, $pid, 1);
23             $return_val = 0;
24         }
25     }
27     $_SESSION['encounter']=$enc;
28     $encounter=$enc;
31     //returns 1 on successful global set, or 0 if there was no
32     //current encounter, signifying that the interface should load
33     //the screen for a new encounter
34     return $return_val;
38 //fetches encounter pc_catid by encounter number
39 function fetchCategoryIdByEncounter($encounter)
41     global $attendant_type;
42     $table = $attendant_type == 'pid' ? 'form_encounter' : 'form_groups_encounter';
43     $sql = "SELECT pc_catid FROM " . escape_table_name($table) . " WHERE encounter = ? limit 1";
44     $result = sqlQuery($sql, array($encounter));
45     return $result['pc_catid'];
48 /**
49  * @param $encounter
50  * @return mixed
51  */
52 function fetchDateService($encounter)
54     $sql = "select date from form_encounter where encounter = ?";
55     $result = sqlQuery($sql, [$encounter]);
56     $result = explode(" ", $result['date']);
57     return $result[0];