7 * @link http://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @author Stephen Waite <stephen.waite@cmsvt.com>
10 * @author Stephen Nielson <snielson@discoverandchange.com>
11 * @copyright Copyright (c) 2017 Brady Miller <brady.g.miller@gmail.com>
12 * @copyright Copyright (c) 2021 Rod Roark <rod@sunsetsystems.com>
13 * @copyright Copyright (c) 2024 Care Management Solutions, Inc. <stephen.waite@cmsvt.com>
14 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
17 require_once("../../globals.php");
18 require_once("$srcdir/options.inc.php");
19 require_once("$srcdir/patientvalidation.inc.php");
20 require_once("$srcdir/pid.inc.php");
21 require_once("$srcdir/patient.inc.php");
23 use OpenEMR\Common\Acl\AclMain
;
24 use OpenEMR\Events\PatientDemographics\UpdateEvent
;
25 use OpenEMR\Common\Twig\TwigContainer
;
26 use OpenEMR\Common\Uuid\UuidRegistry
;
28 // make sure permissions are checked before we allow this page to be accessed.
29 if (!AclMain
::aclCheckCore('patients', 'demo', '', 'write')) {
30 die(xlt('Updating demographics is not authorized.'));
33 // Session pid must be right or bad things can happen when demographics are saved!
35 $set_pid = $_GET["set_pid"] ??
($_GET["pid"] ??
null);
36 if ($set_pid && $set_pid != $_SESSION["pid"]) {
40 $result = getPatientData($pid, "*, DATE_FORMAT(DOB,'%Y-%m-%d') as DOB_YMD");
42 // Check authorization.
44 // Create and fire the patient demographics update event
45 $updateEvent = new UpdateEvent($pid);
46 $updateEvent = $GLOBALS["kernel"]->getEventDispatcher()->dispatch($updateEvent, UpdateEvent
::EVENT_HANDLE
, 10);
49 !$updateEvent->authorized() ||
50 !AclMain
::aclCheckCore('patients', 'demo', '', 'write')
52 die(xlt('Updating insurance is not authorized.'));
55 if ($result['squad'] && ! AclMain
::aclCheckCore('squads', $result['squad'])) {
56 die(xlt('You are not authorized to access this squad.'));
59 if (!AclMain
::aclCheckCore('patients', 'demo', '', array('write','addonly'))) {
60 die(xlt('Adding insurance is not authorized.'));
63 // $statii = array('married','single','divorced','widowed','separated','domestic partner');
64 // $provideri = getProviderInfo();
65 if ($GLOBALS['insurance_information'] != '0') {
66 $insurancei = getInsuranceProvidersExtra();
68 $insurancei = getInsuranceProviders();
70 //Check to see if only one insurance is allowed
71 if ($GLOBALS['insurance_only_one']) {
72 $insurance_array = array('primary');
74 $insurance_array = array('primary', 'secondary', 'tertiary');
77 //Check to see if only one insurance is allowed
78 if ($GLOBALS['insurance_only_one']) {
79 $insurance_headings = array(xl("Primary Insurance Provider"));
81 $insurance_headings = array(xl("Primary Insurance Provider"), xl("Secondary Insurance Provider"), xl("Tertiary Insurance provider"));
84 $twig = (new TwigContainer(null, $GLOBALS['kernel']))->getTwig();
85 //$insurance_info[0]['active'] = true;
86 //$insuranceTypes = array_map(function($item) { return $item['type'];}, $insurance_info);
87 //$insrender(uranceTypes = array_unique($insuranceTypes);
88 // we DO NOT want to allow users to add states/localities in this form per Business Rules
89 // so if we have a state add button we are removing it here.
90 $state_data_type = $GLOBALS['state_data_type'] === '26' ?
'1' : $GLOBALS['state_data_type'];
91 $country_data_type = $GLOBALS['country_data_type'] === '26' ?
'1' : $GLOBALS['country_data_type'];
93 "patient/insurance/insurance_edit.html.twig",
95 'insuranceTypes' => $insurance_array,
96 'activeType' => $insurance_array[0],
98 'puuid' => UuidRegistry
::uuidToString($result['uuid'])
99 ,'insuranceProviderList' => $insurancei
100 ,'enableSwapSecondaryInsurance' => $GLOBALS['enable_swap_secondary_insurance']
101 ,'include_employers' => empty($GLOBALS['omit_employers']) === true
102 ,'useStateTerminology' => $GLOBALS['phone_country_code'] === '1'
103 ,'state_list' => $GLOBALS['state_list']
104 ,'state_data_type' => $state_data_type
105 ,'country_data_type' => $country_data_type
106 ,'country_list' => $GLOBALS['country_list']
107 // policy_types is defined in patient.inc.php
108 ,'policy_types' => $GLOBALS['policy_types']
109 ,'uspsVerifyAddress' => $GLOBALS['usps_webtools_enable']
110 ,'languageDirection' => $GLOBALS['language_direction'] ??
''
111 ,'rightJustifyLabels' => $GLOBALS['right_justify_labels_demographics']