3 * interface/forms/group_attendance/new.php
5 * Copyright (C) 2016 Shachar Zilbershlag <shaharzi@matrix.co.il>
6 * Copyright (C) 2016 Amiel Elboim <amielel@matrix.co.il>
8 * LICENSE: This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 3
11 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
20 * @author Shachar Zilbershlag <shaharzi@matrix.co.il>
21 * @author Amiel Elboim <amielel@matrix.co.il>
22 * @link http://www.open-emr.org
28 require_once("../../globals.php");
29 require_once("functions.php");
30 require_once(dirname(__FILE__
) . "/../../../library/group.inc");
33 $can_view = acl_check("groups", "gadd", false, 'view');
34 $can_edit = acl_check("groups", "gadd", false, 'write');
36 if (!$can_view && !$can_edit) {
40 $statuses_in_meeting = getGroupAttendanceStatuses();
42 $returnurl = 'encounter_top.php';
44 //If editing form, get participants from therapy_groups_participant_attendance table. Otherwise get from therapy_groups_participants table.
45 if (isset($_GET['id'])) {//clicked edit form
46 $form_id = $_GET['id'];
47 } else {//In case didn't click 'edit' but an attendance form already exists (can't have 2 attendance forms for same encounter)
48 $result = get_form_id_of_existing_attendance_form($encounter, $therapy_group);
49 $form_id = $result['form_id'];
53 if ($form_id) {//If editing a form or the form already exists (inwhich case will automatically go into edit mode for existing form)
54 $participants_sql = "SELECT tgpa.*, p.fname, p.lname " .
55 "FROM therapy_groups_participant_attendance as tgpa " .
56 "JOIN patient_data as p ON tgpa.pid = p.id " .
57 "WHERE tgpa.form_id = ?;";
58 $result = sqlStatement($participants_sql, array($form_id));
59 while ($p = sqlFetchArray($result)) {
63 $participants = getParticipants($therapy_group, true);
71 <?php
html_header_show();?
>
73 <link rel
="stylesheet" href
="<?php echo $css_header;?>" type
="text/css">
74 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative'];?>/datatables.net-jqui-1-10-13/css/dataTables.jqueryui.min.css" type
="text/css">
75 <link rel
="stylesheet" href
="<?php echo $GLOBALS['assets_static_relative'];?>/bootstrap-3-3-4/dist/css/bootstrap.min.css" type
="text/css">
77 <script src
="<?php echo $GLOBALS['assets_static_relative'];?>/jquery-min-1-9-1/index.js"></script
>
78 <script src
="<?php echo $GLOBALS['assets_static_relative'];?>/jquery-ui-1-12-1/jquery-ui.min.js"></script
>
79 <script src
="<?php echo $GLOBALS['assets_static_relative'];?>/datatables.net-1-10-13/js/jquery.dataTables.min.js"></script
>
80 <script src
="<?php echo $GLOBALS['assets_static_relative'];?>/bootstrap-3-3-4/dist/js/bootstrap.min.js?v=40"></script
>
81 <script src
="<?php echo $GLOBALS['web_root'];?>/library/dialog.js"></script
>
84 <body
class="body_top">
85 <?php
if ($form_id) { ?
>
86 <form id
="group_attendance_form" method
=post onclick
="top.restoreSession();" action
="<?php echo $rootdir;?>/forms/group_attendance/save.php?mode=update&id=<?php echo attr($form_id) ;?>" name
="my_form">
88 <form id
="group_attendance_form" method
=post onclick
="top.restoreSession();" action
="<?php echo $rootdir;?>/forms/group_attendance/save.php?mode=new" name
="my_form">
90 <div id
="add_participant">
91 <div
class="button_wrap">
92 <span
class='title'><?php
echo xlt('Group Attendance Form'); ?
></span
>
93 <input
class="button-css add_button" type
="button" value
="<?php echo xla('Add'); ?>" <?php
if (!$can_edit) {
97 <div id
="add_participant_element" style
="display: none;">
98 <div
class="patient_wrap">
99 <span
class="input_label"><?php
echo xlt("Participant's name");?
></span
>
100 <input name
="new_id" class="button-css new_patient_id" type
="hidden" value
="">
101 <input name
="new_patient" class="button-css new_patient" type
="text" value
="" readonly
>
102 <div
class="error_wrap">
103 <span
class="error"></span
>
106 <div
class="comment_wrap">
107 <span
class="input_label"><?php
echo xlt("Comment");?
></span
>
108 <input name
="new_comment" class="button-css new_comment" type
="text" value
="">
110 <div
class="button_wrap">
111 <input
class="button-css add_patient_button" type
="button" value
="<?php echo xla('Add Patient'); ?>">
112 <input
class="button-css cancel_button" type
="button" value
="<?php echo xla('Cancel'); ?>" >
116 <table id
="group_attendance_form_table">
119 <th align
="center"><?php
echo xlt("Participant's name"); ?
></th
>
120 <th align
="center"><?php
echo xlt("Patient's number"); ?
></th
>
121 <th align
="center"><?php
echo xlt('Status in the meeting'); ?
></th
>
122 <th align
="center"><?php
echo xlt('Comment'); ?
></th
>
126 <?php
foreach ($participants as $participant) {?
>
128 <td
><?php
echo text($participant['fname'] . ", " . $participant['lname']); ?
></td
>
129 <td
><?php
echo text($participant['pid']); ?
></td
>
131 <select
class="status_select" name
="<?php echo "patientData
[" . attr($participant['pid']) . "][status
]" ;?>" <?php
if (!$can_edit) {
134 <?php
foreach ($statuses_in_meeting as $status_in_meeting) {?
>
135 <option value
="<?php echo attr($status_in_meeting['option_id']); ?>" <?php
if ($participant['meeting_patient_status'] == $status_in_meeting['option_id']) {
137 }?
> > <?php
echo xlt($status_in_meeting['title']); ?
></option
>
142 <input
class="comment" type
="text" name
="<?php echo "patientData
[" . attr($participant['pid']) . "][comment
]"; ?>" value
="<?php echo attr($participant['meeting_patient_comment']) ;?>" <?php
if (!$can_edit) {
150 <div
class="action_buttons">
151 <input name
="submit" class="button-css" type
="submit" value
="<?php echo xla('Save'); ?>" <?php
if (!$can_edit) {
154 <input
class="button-css cancel" type
="button" value
="<?php echo xla('Cancel'); ?>">
158 $
(document
).ready(function () {
160 /* Initialise Datatable */
161 var table
= $
('#group_attendance_form_table').DataTable({
162 initComplete
: function () {
163 $
('#group_attendance_form_table_filter').hide(); //hide searchbar
165 <?php
// Bring in the translations ?>
166 <?php
require($GLOBALS['srcdir'] . '/js/xl/datatables-net.js.php'); ?
>
169 /* 'Add Participant' elements */
170 $
('.add_button').click(function () {
171 $
('#add_participant_element').show();
175 $
('.new_patient').on('click', function(){
176 top
.restoreSession();
177 $
('.new_patient').css("border-color", "black");
178 $
('.error_wrap .error').html("");
179 var url
= '<?php echo $GLOBALS['webroot
']?>/interface/main/calendar/find_patient_popup.php';
180 dlgopen(url
, '_blank', 500, 400);
183 $
('.cancel_button').click(function () {
184 $
('#add_participant_element').hide();
185 $
('.add_button').show();
187 $
('.new_patient_id').val('');
188 $
('.new_patient').val('');
189 $
('.new_comment').val('');
192 $
('.add_patient_button').click(function(e
){
193 var name
= $
('.new_patient').val();
196 //If no patient was chosen (validation)
197 $
('.new_patient').css("border-color", "red");
198 var err_msg
= "<?php echo xlt("Choose Patient
"); ?>";
199 $
('.error_wrap .error').html(err_msg
);
203 // Get new participant details
204 var new_patient_id
= $
('.new_patient_id').val();
205 var new_patient_name
= $
('.new_patient').val();
206 var new_patient_comment
= $
('.new_comment').val();
208 //Check if patient already exists in form
210 $
('#group_attendance_form_table tbody tr td:nth-child(2)').each(function(){
211 ids_array
.push($
(this
).text());
213 var exists
= $
.inArray(new_patient_id
, ids_array
);
215 $
('.new_patient').css("border-color", "red");
216 var err_msg
= "<?php echo xlt("Patient already in form
"); ?>";
217 $
('.error_wrap .error').html(err_msg
);
221 //Get statuses from list into json and create select element
222 var statuses
= <?php
echo json_encode($statuses_in_meeting); ?
>;
223 var select_element
= $
("<select class=\"status_select\" name=\"\" />");
224 $
.each(statuses
, function(key
, value
) {
225 $
("<option />", {value
: value
.option_id
, text
: value
.title
}).appendTo(select_element
);
227 var attended_sign
= '@';
228 select_element
.attr('name', 'patientData[' + new_patient_id +
'][status]');
229 select_element
.find("option[value='" + attended_sign +
"']").attr('selected', 'selected');
231 //Create comment element
232 var comment_element
= $
("<input class=\"comment\" type=\"text\" name=\"\" value=\"\">");
233 comment_element
.attr('name', 'patientData[' + new_patient_id +
'][comment]');
234 comment_element
.attr('value', new_patient_comment
);
236 //Convert html object into string for insertion into datatable
237 var select_html_string
= select_element
.prop('outerHTML');
238 var comment_html_string
= comment_element
.prop('outerHTML');
239 if(select_html_string
== undefined
){ //firefox support
240 select_html_string
= new XMLSerializer().serializeToString(select_element
[0]);
241 comment_html_string
= new XMLSerializer().serializeToString(comment_element
[0]);
244 //Insert new row into datatable
245 $
('#group_attendance_form_table').dataTable().fnAddData( [
252 //Empty values from inputs
253 $
('.new_patient').val("");
254 $
('.new_comment').val("");
261 $
('.cancel').click(function () {
262 top
.restoreSession();
263 parent
.closeTab(window
.name
, false);
270 /* For patient popup search */
271 function setpatient(pid
, lname
, fname
, dob
){
272 $
('.new_patient_id').val(pid
);
273 $
('.new_patient').val(fname +
" " + lname
);