fix: quick fix to enforce support of x509 database connection on install (#6157)
[openemr.git] / interface / reports / cqm.php
blob7e104b2ca4f81ae40b7ae760e334b4d00f1d25b0
1 <?php
3 /**
4 * CDR reports. Handles the generation and display of CQM/AMC/patient_alerts/standard reports
6 * @package OpenEMR
7 * @link http://www.open-emr.org
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @author Stephen Nielson <snielson@discoverandchange.com>
10 * @copyright Copyright (c) 2010-2018 Brady Miller <brady.g.miller@gmail.com>
11 * @copyright Copyright (c) 2022 Discover and Change, Inc. <snielson@discoverandchange.com>
12 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 // TODO: This needs a complete makeover
18 require_once("../globals.php");
19 require_once("../../library/patient.inc.php");
20 require_once "$srcdir/options.inc.php";
21 require_once "$srcdir/clinical_rules.php";
22 require_once "$srcdir/report_database.inc.php";
24 use OpenEMR\Common\Acl\AclMain;
25 use OpenEMR\ClinicialDecisionRules\AMC\CertificationReportTypes;
26 use OpenEMR\Common\Csrf\CsrfUtils;
27 use OpenEMR\Common\Twig\TwigContainer;
28 use OpenEMR\Services\PractitionerService;
30 if (!AclMain::aclCheckCore('patients', 'med')) {
31 echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("Report")]);
32 exit;
35 if (!empty($_POST)) {
36 if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) {
37 CsrfUtils::csrfNotVerified();
41 $amc_report_types = CertificationReportTypes::getReportTypeRecords();
43 // See if showing an old report or creating a new report
44 $report_id = (isset($_GET['report_id'])) ? trim($_GET['report_id']) : "";
46 // Collect the back variable, if pertinent
47 $back_link = (isset($_GET['back'])) ? trim($_GET['back']) : "";
49 // If showing an old report, then collect information
50 $heading_title = "";
51 $help_file_name = "";
52 if (!empty($report_id)) {
53 $report_view = collectReportDatabase($report_id);
54 $date_report = $report_view['date_report'];
55 $type_report = $report_view['type'];
57 $is_amc_report = CertificationReportTypes::isAMCReportType($type_report);
58 $is_cqm_report = ($type_report == "cqm") || ($type_report == "cqm_2011") || ($type_report == "cqm_2014");
59 $type_report = ($is_amc_report || $is_cqm_report) ? $type_report : "standard";
60 $rule_filter = $report_view['type'];
62 if ($is_amc_report) {
63 $begin_date = $report_view['date_begin'];
64 $labs_manual = $report_view['labs_manual'];
67 $target_date = $report_view['date_target'];
68 $plan_filter = $report_view['plan'];
69 $organize_method = $report_view['organize_mode'];
70 $provider = $report_view['provider'];
71 $pat_prov_rel = $report_view['pat_prov_rel'];
74 $amc_report_data = $amc_report_types[$type_report] ?? array();
75 $dataSheet = formatReportData($report_id, $report_view['data'], $is_amc_report, $is_cqm_report, $type_report, $amc_report_data);
76 } else {
77 // Collect report type parameter (standard, amc, cqm)
78 // Note that need to convert amc_2011 and amc_2014 to amc and cqm_2011 and cqm_2014 to cqm
79 // to simplify for when submitting for a new report.
80 $type_report = (isset($_GET['type'])) ? trim($_GET['type']) : "standard";
82 $is_amc_report = CertificationReportTypes::isAMCReportType($type_report);
83 $is_cqm_report = ($type_report == "cqm") || ($type_report == "cqm_2011") || ($type_report == "cqm_2014");
85 if (($type_report == "cqm_2011") || ($type_report == "cqm_2014")) {
86 $type_report = "cqm";
89 // Collect form parameters (set defaults if empty)
90 if ($is_amc_report) {
91 $begin_date = (isset($_POST['form_begin_date'])) ? DateTimeToYYYYMMDDHHMMSS(trim($_POST['form_begin_date'])) : "";
92 $labs_manual = (isset($_POST['labs_manual_entry'])) ? trim($_POST['labs_manual_entry']) : "0";
95 $target_date = (isset($_POST['form_target_date'])) ? DateTimeToYYYYMMDDHHMMSS(trim($_POST['form_target_date'])) : date('Y-m-d H:i:s');
96 $rule_filter = (isset($_POST['form_rule_filter'])) ? trim($_POST['form_rule_filter']) : CertificationReportTypes::DEFAULT;
97 $plan_filter = (isset($_POST['form_plan_filter'])) ? trim($_POST['form_plan_filter']) : "";
98 $organize_method = (empty($plan_filter)) ? "default" : "plans";
99 $provider = trim($_POST['form_provider'] ?? '');
100 $pat_prov_rel = (empty($_POST['form_pat_prov_rel'])) ? "primary" : trim($_POST['form_pat_prov_rel']);
101 $dataSheet = [];
104 $show_help = false;
105 if ($type_report == "standard") {
106 $heading_title = xl('Standard Measures');
107 } else if ($type_report == "cqm") {
108 $heading_title = xl('Clinical Quality Measures (CQM)');
109 } else if ($type_report == 'cqm_2011') {
110 $heading_title = 'Clinical Quality Measures (CQM) - 2011';
111 } else if ($type_report == "cqm_2014") {
112 $heading_title = 'Clinical Quality Measures (CQM) - 2014';
113 } else if ($is_amc_report) {
114 $heading_title = $amc_report_types[$type_report]['title'];
115 $show_help = true;
116 $help_file_name = "cqm_amc_help.php";
119 $twigContainer = new TwigContainer(null, $GLOBALS['kernel']);
120 $twig = $twigContainer->getTwig();
122 $formData = [
123 'type_report' => $type_report
124 ,'heading_title' => $heading_title
125 ,'date_report' => isset($date_report) ? oeFormatDateTime($date_report, "global", true) : ''
126 ,'report_id' => $report_id ?? null
127 ,'show_help' => $show_help
128 ,'oemrUiSettings' => [
129 'heading_title' => xl('Add/Edit Patient Transaction'),
130 'include_patient_name' => false,
131 'expandable' => false,
132 'expandable_files' => array(),//all file names need suffix _xpd
133 'action' => "conceal",//conceal, reveal, search, reset, link or back
134 'action_title' => "",
135 'action_href' => "cqm.php",//only for actions - reset, link and back
136 'show_help_icon' => $show_help,
137 'help_file_name' => $help_file_name
139 ,'csrf_token' => CsrfUtils::collectCsrfToken()
140 ,'widthDyn' => '610px'
141 ,'is_amc_report' => $is_amc_report
142 ,'dis_text' => (!empty($report_id) ? "disabled='disabled'" : "")
143 ,'begin_date' => isset($begin_date) ? oeFormatDateTime($begin_date, 0, true) : ""
144 ,'target_date' => oeFormatDateTime($target_date, 0, true)
145 ,'target_date_label' => ($is_amc_report ? xl('End Date') : xl('Target Date'))
146 ,'rule_filters' => []
147 ,'show_plans' => !$is_amc_report
148 ,'plans' => []
149 ,'providerReportOptions' => [
150 ['value' => '', 'selected' => false, 'label' => '-- ' . xl('All (Cumulative)') . ' --']
151 ,['value' => 'collate_outer', 'selected' => $provider == 'collate_outer', 'label' => xl('All (Collated Format A)')]
152 ,['value' => 'collate_inner', 'selected' => $provider == 'collate_inner', 'label' => xl('All (Collated Format B)')]
154 ,'providerRelationship' => [
155 ['value' => 'primary', 'selected' => $pat_prov_rel == 'primary', 'label' => xl('Primary')]
156 ,['value' => 'encounter', 'selected' => $pat_prov_rel == 'encounter', 'label' => xl('Encounter')]
158 ,'show_manual_labs' => false
159 ,'labs_manual' => $labs_manual ?? 0
160 ,'display_submit' => empty($report_id)
161 ,'display_pqri_btns' => $type_report == 'cqm' && !empty($report_id)
162 ,'display_amc_details' => !empty($report_id) && $is_amc_report
163 ,'display_back_link' => $back_link == 'list'
164 ,'display_qrda_btns' => !empty($report_id) && $type_report == 'cqm_2014'
165 ,'display_new_report_btn' => !empty($report_id) && $back_link != 'list'
166 , 'collate_outer' => $provider == 'collate_outer'
167 , 'datasheet' => $dataSheet
169 if (($type_report == "cqm") || ($type_report == "cqm_2011") || ($type_report == "cqm_2014")) {
170 $formData['widthDyn'] = '410px';
171 $formData['rule_filters'] = [
172 ['value' => 'cqm', 'selected' => $type_report == 'cqm', 'label' => xl('All Clinical Quality Measures (CQM)')]
173 ,['value' => 'cqm_2011', 'selected' => $type_report == 'cqm_2011', 'label' => xl('2011 Clinical Quality Measures (CQM)')]
174 ,['value' => 'cqm_2014', 'selected' => $type_report == 'cqm_2014', 'label' => xl('2014 Clinical Quality Measures (CQM)')]
176 $formData['plans'] = [
177 ['value' => '', 'selected' => false, 'label' => '-- ' . xl('Ignore') . ' --']
178 ,['value' => 'cqm', 'selected' => $plan_filter == 'cqm', 'label' => xl('All Official Clinical Quality Measures (CQM) Measure Groups')]
179 ,['value' => 'cqm_2011', 'selected' => $plan_filter == 'cqm_2011', 'label' => xl('2011 Official Clinical Quality Measures (CQM) Measure Groups')]
180 ,['value' => 'cqm_2014', 'selected' => $plan_filter == 'cqm_2014', 'label' => xl('2014 Official Clinical Quality Measures (CQM) Measure Groups')]
182 } else if ($is_amc_report) {
183 // latest AMC doesn't have collate options
184 if (empty($report_id)) {
185 // truncate to just the first option
186 $formData['providerReportOptions'] = [
187 $formData['providerReportOptions'][0]
189 $formData['rule_filters'] = [
190 ['value' => CertificationReportTypes::DEFAULT, 'selected' => true
191 , 'label' => $amc_report_types[CertificationReportTypes::DEFAULT]['ruleset_title']]
193 // modern AMC only deals with encounter based relationships
194 $formData['providerRelationship'] = [
195 $formData['providerRelationship'][1]
197 } else {
198 // old AMC had a manual labs input for MIPS
199 $formData['show_manual_labs'] = true;
200 // need to handle historical data
201 foreach ($amc_report_types as $key => $report_type) {
202 $formData['rule_filters'][] = ['value' => $key, 'selected' => $type_report == $key
203 , 'label' => $amc_report_types[$key]['ruleset_title']];
206 $formData['providerReportOptions'][] = ['value' => 'group_calculation', 'selected' => $provider == 'group_calculation'
207 , 'label' => xl('All EP/EC Group Calculation')];
208 } else if ($type_report == 'standard') {
209 $formData['rule_filters'] = [
210 ['value' => 'passive_alert', 'selected' => $type_report == 'passive_alert', 'label' => xl('Passive Alert Rules')]
211 ,['value' => 'active_alert', 'selected' => $type_report == 'active_alert', 'label' => xl('Active Alert Rules')]
212 ,['value' => 'patient_reminder', 'selected' => $type_report == 'patient_reminder', 'label' => xl('Patient Reminder Rules')]
214 $formData['plans'] = [
215 ['value' => '', 'selected' => false, 'label' => '-- ' . xl('Ignore') . ' --']
216 ,['value' => 'value', 'selected' => $plan_filter == 'normal', 'label' => xl('Active Plans')]
220 // we need to grab the providers and add them to the provider dropdown
221 $practitionerService = new PractitionerService();
222 $result = $practitionerService->getAll();
223 if ($result->hasData()) {
224 foreach ($result->getData() as $practitioner) {
225 $formData['providerReportOptions'][] = ['value' => $practitioner['id'], 'selected' => $provider == $practitioner['id']
226 , 'label' => $practitioner['lname'] . ',' . $practitioner['fname']];
229 echo $twig->render('reports/cqm/cqm.html.twig', $formData);
230 exit;