Highway to PSR2
[openemr.git] / interface / therapy_groups / therapy_groups_models / therapy_groups_participants_model.php
blob85984262cd47b87a7f59ba99b71de0431fac47ae
1 <?php
2 /**
3 * interface/therapy_groups/therapy_groups_models/therapy_groups_participants_model.php contains the model for therapy group participants.
5 * This model fetches the participants of the therapy group from the DB.
7 * Copyright (C) 2016 Shachar Zilbershlag <shaharzi@matrix.co.il>
8 * Copyright (C) 2016 Amiel Elboim <amielel@matrix.co.il>
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 3
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @package OpenEMR
22 * @author Shachar Zilbershlag <shaharzi@matrix.co.il>
23 * @author Amiel Elboim <amielel@matrix.co.il>
24 * @link http://www.open-emr.org
27 class Therapy_groups_participants
30 const TABLE = 'therapy_groups_participants';
31 const PATIENT_TABLE = 'patient_data';
33 public function getParticipants($groupId, $onlyActive = false)
36 $sql = "SELECT gp.*, p.fname, p.lname FROM " . self::TABLE . " AS gp ";
37 $sql .= "JOIN " . self::PATIENT_TABLE . " AS p ON gp.pid = p.pid ";
38 $sql .= "WHERE gp.group_id = ?";
39 $binds = array($groupId);
41 if ($onlyActive) {
42 $sql .= " AND gp.group_patient_status = ?";
43 $binds[] = 10;
46 $groupParticipants = array();
47 $result = sqlStatement($sql, $binds);
48 while ($gp = sqlFetchArray($result)) {
49 $groupParticipants[] = $gp;
52 return $groupParticipants;
55 public function updateParticipant(array $participant, $patientId, $groupId)
58 if (empty($participant['group_patient_end'])) {
59 $participant['group_patient_end'] = null;
62 $sql = "UPDATE " . self::TABLE . " SET ";
63 foreach ($participant as $key => $value) {
64 $sql .= $key . '=?,';
67 $sql = substr($sql, 0, -1);
68 $sql .= ' WHERE pid = ? AND group_id = ?';
70 $data = array_merge($participant, array($patientId, $groupId));
71 $result = sqlStatement($sql, $data);
72 return !$result ? false :true;
75 public function removeParticipant($groupId, $pid)
78 $sql = "DELETE FROM " . self::TABLE . " WHERE group_id = ? AND pid = ?";
79 $result = sqlStatement($sql, array($groupId, $pid));
80 return !$result ? false :true;
83 public function isAlreadyRegistered($pid, $groupId)
86 $sql = "SELECT COUNT(*) AS count FROM " . self::TABLE . " WHERE pid = ? AND group_id = ?";
88 // $result = sqlStatement($sql, array($pid, $groupId));
89 // $count = sqlFetchArray($result);
90 $count = sqlQuery($sql, array($pid, $groupId));
91 return($count['count'] > 0) ? true : false;
94 public function saveParticipant($participantData)
96 // print_r($participantData);die;
97 $sql = "INSERT INTO " .self::TABLE . " VALUES(?,?,?,?,?,?);";
98 $data[] = $participantData['group_id'];
99 $data[] = $participantData['pid'];
100 $data[] = $participantData['group_patient_status'];
101 $data[] = $participantData['group_patient_start'];
102 $data[] = $participantData['group_patient_end'];
103 $data[] = $participantData['group_patient_comment'];
105 $result = sqlStatement($sql, $data);
107 return !$result ? false :true;