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