fix: Update patient_tracker.php (#6595)
[openemr.git] / library / ajax / specialty_form_ajax.php
blob9afc63837bfd79c7325e10b6e367e67d548e518e
1 <?php
3 /**
4 * For various specialty forms to call from dialog using the
5 * Ajax, iFrame, Alert, Confirm or HTML modes. Just follow
6 * the example patient previous names history form pattern shown below.
8 * @package OpenEMR
9 * @link https://www.open-emr.org
10 * @author Jerry Padgett <sjpadgett@gmail.com>
11 * @copyright Copyright (c) 2021 Jerry Padgett <sjpadgett@gmail.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once(__DIR__ . "/../../interface/globals.php");
17 use OpenEMR\Common\Csrf\CsrfUtils;
18 use OpenEMR\Services\PatientService;
20 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
21 CsrfUtils::csrfNotVerified();
24 $post_items = $_POST;
25 if ($post_items['task_name_history'] === 'save') {
26 nameHistorySave($post_items);
28 if ($post_items['task_name_history'] === 'delete') {
29 nameHistoryDelete($post_items['id']);
32 function nameHistoryDelete($id)
34 $patientService = new PatientService();
35 $is_ok = $patientService->deletePatientNameHistoryById($id);
36 $is_ok = empty($is_ok) ? xlt("Success") : xlt("Failed");
37 echo js_escape($is_ok);
38 exit;
41 function nameHistorySave($post_items)
43 if (!empty($post_items['previous_name_enddate'])) {
44 $date = new DateTime($post_items['previous_name_enddate']);
45 $post_items['previous_name_enddate'] = $date->format('Y-m-d');
47 $patientService = new PatientService('patient_history');
48 $is_new = $patientService->createPatientNameHistory($post_items['pid'], $post_items);
49 $name = $patientService->formatPreviousName($post_items);
51 $ret = array();
52 if (!empty($is_new)) {
53 $ret['id'] = $is_new;
54 $ret['name'] = $name;
57 echo js_escape($ret);
58 exit;