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.
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();
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);
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);
52 if (!empty($is_new)) {