MedEx Updates
[openemr.git] / services / PatientService.php
blob75e4388f17e80fff53f59e602bedc1599b237471
1 <?php
2 /**
3 * Patient Service
5 * Copyright (C) 2017 Victor Kofia <victor.kofia@gmail.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Victor Kofia <victor.kofia@gmail.com>
20 * @link http://www.open-emr.org
23 namespace OpenEMR\Services;
25 class PatientService
28 /**
29 * In the case where a patient doesn't have a picture uploaded,
30 * this value will be returned so that the document controller
31 * can return an empty response.
33 private $patient_picture_fallback_id = -1;
35 private $pid;
37 /**
38 * Default constructor.
40 public function __construct()
44 public function setPid($pid)
46 $this->pid = $pid;
49 public function getPid()
51 return $this->pid;
54 /**
55 * TODO: This should go in the ChartTrackerService and doesn't have to be static.
56 * @param $pid unique patient id
57 * @return recordset
59 public static function getChartTrackerInformationActivity($pid)
61 $sql = "SELECT ct.ct_when,
62 ct.ct_userid,
63 ct.ct_location,
64 u.username,
65 u.fname,
66 u.mname,
67 u.lname
68 FROM chart_tracker AS ct
69 LEFT OUTER JOIN users AS u ON u.id = ct.ct_userid
70 WHERE ct.ct_pid = ?
71 ORDER BY ct.ct_when DESC";
72 return sqlStatement($sql, array($pid));
75 /**
76 * TODO: This should go in the ChartTrackerService and doesn't have to be static.
77 * @return recordset
79 public static function getChartTrackerInformation()
81 $sql = "SELECT ct.ct_when,
82 u.username,
83 u.fname AS ufname,
84 u.mname AS umname,
85 u.lname AS ulname,
86 p.pubpid,
87 p.fname,
88 p.mname,
89 p.lname
90 FROM chart_tracker AS ct
91 JOIN cttemp ON cttemp.ct_pid = ct.ct_pid AND cttemp.ct_when = ct.ct_when
92 LEFT OUTER JOIN users AS u ON u.id = ct.ct_userid
93 LEFT OUTER JOIN patient_data AS p ON p.pid = ct.ct_pid
94 WHERE ct.ct_userid != 0
95 ORDER BY p.pubpid";
96 return sqlStatement($sql);
99 /**
100 * @return number
102 public function getPatientPictureDocumentId()
104 $sql = "SELECT doc.id AS id
105 FROM documents doc
106 JOIN categories_to_documents cate_to_doc
107 ON doc.id = cate_to_doc.document_id
108 JOIN categories cate
109 ON cate.id = cate_to_doc.category_id
110 WHERE cate.name LIKE ? and doc.foreign_id = ?";
112 $result = sqlQuery($sql, array($GLOBALS['patient_photo_category_name'], $this->pid));
114 if (empty($result) || empty($result['id'])) {
115 return $this->patient_picture_fallback_id;
118 return $result['id'];