Visual Comparison of Key Metrics
Comparison Summary
Both facilities, Hope Care Center and Highland Rehabilitation And Health Care Center, have comparable CMS overall quality ratings, both scoring Stars. When reviewing the core nursing resources, Highland Rehabilitation And Health Care Center reports a higher licensed nursing staff ratio, providing 0.00 hours of licensed nurse care per resident day (National Average is 1.4 hours). Highland Rehabilitation And Health Care Center is part of the Tutera Senior Living & Health Care chain, which holds an average overall rating of 2.00. Regarding recent health inspection history, both facilities had deficiencies in their most recent survey, with Hope Care Center recording 11 total deficiencies and Highland Rehabilitation And Health Care Center recording 10.Finally, in terms of compliance history, both facilities have incurred past fines; Hope Care Center totaling , and Highland Rehabilitation And Health Care Center totaling .
*Staffing, resident, and quality ratings are based on the latest data provided by CMS (Centers for Medicare & Medicaid Services).
// Start of Comparison Table HTML output
echo "
Side-by-Side Facility Metrics";
echo "
";
echo "";
echo "";
echo "";
echo "";
// 1. Define the final columns list for display
$comparisonColumns = [
"provname" => "Facility Name",
"address" => "Street Address",
"city" => "City",
"state" => "State",
"zip" => "Zip Code",
"phone" => "Phone Number",
"ownership" => "Ownership Type",
"Affiliated_Entity_Name" => "Chain Name", // Source: Affiliated_Entity_Name
"Number_of_Facilities_in_Chain" => "No. of Facilities in Chain", // Handles 0/Null/Empty
// --- CMS Ratings (Primary 5-Star) ---
"overall_rating" => "Overall CMS Rating",
"staffing_rating" => "Staffing Rating",
"quality_rating" => "Quality Measures Rating",
// --- Staffing/Capacity ---
"TOTLICHRD" => "Licensed Nursing Hours/Resident Day",
"AIDHRD" => "CNA Hours/Resident Day (Minutes)",
"bedcert" => "Certified Bed Count",
"restot" => "Total Residents Average",
// --- Financial/Compliance ---
"FINE_TOT" => "Total Penalties (Fines)",
// --- CHAIN AVERAGES ---
"Chain_Average_Overall_Rating" => "Chain Avg. Overall Rating (1-5)",
"Chain_Average_Health_Rating" => "Chain Avg. Health Inspection",
"Chain_Average_Staffing_Rating" => "Chain Avg. Staffing Rating",
"Chain_Average_QM_Rating" => "Chain Avg. Quality Rating",
// --- DEFICIENCY COUNTS ---
"cycle_1_defs" => "Cycle 1 Total Deficiencies",
"cycle_2_defs" => "Cycle 2 Total Deficiencies",
];
// Helper function to handle null/zero/empty data vs. Not Available
$check_for_zero_or_null = function($raw_val) {
if ($raw_val === null || $raw_val === '' || $raw_val === '0' || $raw_val === 0 || $raw_val === '0.00') {
return 'Not Available';
}
return $raw_val;
};
// 2. Iterate through columns and output rows
foreach ($comparisonColumns as $key => $label) {
$raw_value1 = $facilityData[$providerId1][$key] ?? null;
$raw_value2 = $facilityData[$providerId2][$key] ?? null;
$value1 = $raw_value1;
$value2 = $raw_value2;
// Flags to control formatting
$is_cms_star_rating = (strpos($key, "rating") !== false && strpos($key, "Chain_Average") === false);
$is_chain_average = (strpos($key, "Chain_Average") !== false);
$is_num_facil = ($key == "Number_of_Facilities_in_Chain");
$is_chain_name = ($key == "Affiliated_Entity_Name");
$is_phone = ($key == "phone");
$is_fine = ($key == "FINE_TOT");
// --- A. Global Null/Zero/Empty Check ---
if (!$is_fine && !$is_chain_name && !$is_phone) {
// Apply check to rating values, deficiency counts, and facility counts
$value1 = $check_for_zero_or_null($raw_value1);
$value2 = $check_for_zero_or_null($raw_value2);
}
// --- B. Chain Name Custom Logic ---
if ($is_chain_name) {
if ($raw_value1 === null || $raw_value1 === '') {
$value1 = 'Not Part of a Chain';
} else {
$value1 = ucwords(strtolower($raw_value1));
}
if ($raw_value2 === null || $raw_value2 === '') {
$value2 = 'Not Part of a Chain';
} else {
$value2 = ucwords(strtolower($raw_value2));
}
}
// --- C. Chain Average / Numeric Formatting (2 decimals) ---
if ($is_chain_average && is_numeric($raw_value1)) {
// We know raw_value is numeric, now check if it's zero *after* the global check
$value1 = ($raw_value1 == 0 || $raw_value1 == '0.00') ? 'Not Available' : number_format($raw_value1, 2);
}
if ($is_chain_average && is_numeric($raw_value2)) {
$value2 = ($raw_value2 == 0 || $raw_value2 == '0.00') ? 'Not Available' : number_format($raw_value2, 2);
}
// --- D. CMS Star Rating Formatting ---
if ($is_cms_star_rating && $value1 !== 'Not Available') {
if (is_numeric($value1) && $value1 > 0) {
$value1 = $value1 . " Stars " . "
";
}
}
if ($is_cms_star_rating && $value2 !== 'Not Available') {
if (is_numeric($value2) && $value2 > 0) {
$value2 = $value2 . " Stars " . "
";
}
}
// --- E. Phone Link Handling ---
if ($is_phone && $value1 != 'Not Available') {
$value1 = "" . $value1 . "";
}
if ($is_phone && $value2 != 'Not Available') {
$value2 = "" . $value2 . "";
}
// --- F. Output the table row ---
echo "";
echo "" . $label . " | ";
echo "" . $value1 . " | ";
echo "" . $value2 . " | ";
echo "
";
}
echo "";
echo "
";
// PHP variables are already defined in Section 2: $name1, $name2, $providerId1, $providerId2, $facilityData
$data1 = $facilityData[$providerId1];
$data2 = $facilityData[$providerId2];
// --- 1. Key Metric Comparisons ---
// A. CMS Overall Rating
$overall1 = $data1['overall_rating'] ?? 0;
$overall2 = $data2['overall_rating'] ?? 0;
// B. Staffing (Licensed Hours - TOTLICHRD_NUM is raw hours)
$staffing_hrs1 = $data1['TOTLICHRD_NUM'] ?? 0;
$staffing_hrs2 = $data2['TOTLICHRD_NUM'] ?? 0;
$national_hr_avg = 1.4; // National licensed nursing hour average
// C. Penalties
$fines1 = $data1['FINE_TOT'] ?? '$0.00';
$fines2 = $data2['FINE_TOT'] ?? '$0.00';
// --- 2. Narrative Generation ---
// Note: This block assumes $overall1, $overall2, $name1, $name2, $staffing_hrs1, $staffing_hrs2, $fines1, $fines2,
// $facilityData, $providerId1, $providerId2, $defsv1 (cycle_1_defs) and $chain_avg1/2 are defined and contain data.
// --- Ensure Deficiency Data is retrieved correctly for the summary ---
$defsv1 = $facilityData[$providerId1]['cycle_1_defs'] ?? 0;
$defsv2 = $facilityData[$providerId2]['cycle_1_defs'] ?? 0;
// --- Ensure Chain Data is available for the summary ---
$chain_avg1 = $facilityData[$providerId1]['Chain_Average_Overall_Rating'] ?? 0;
$chain_avg2 = $facilityData[$providerId2]['Chain_Average_Overall_Rating'] ?? 0;
$chain_name1 = $facilityData[$providerId1]['Affiliated_Entity_Name'] ?? '';
$chain_name2 = $facilityData[$providerId2]['Affiliated_Entity_Name'] ?? '';
$summary_output = "
Comparison Summary\n";
$summary_output .= "
\n";
// --- A. Overall Ratings Summary ---
if ($overall1 > $overall2) {
$summary_output .= "
The facility {$name1} holds the edge in overall quality, scoring {$overall1} Stars compared to {$name2}'s {$overall2} Stars. ";
} elseif ($overall2 > $overall1) {
$summary_output .= "
The facility {$name2} holds the edge in overall quality, scoring {$overall2} Stars compared to {$name1}'s {$overall1} Stars. ";
} else {
$summary_output .= "
Both facilities, {$name1} and {$name2}, have comparable CMS overall quality ratings, both scoring {$overall1} Stars. ";
}
// --- B. Staffing Summary (Licensed Hours) ---
// Note: $staffing_hrs1 and $staffing_hrs2 should be the raw numeric hours (TOTLICHRD_NUM)
$higher_staffing_name = ($staffing_hrs1 > $staffing_hrs2) ? $name1 : $name2;
$higher_staffing_hrs = max($staffing_hrs1, $staffing_hrs2);
$summary_output .= "When reviewing the core nursing resources, {$higher_staffing_name} reports a higher licensed nursing staff ratio, providing " . number_format($higher_staffing_hrs, 2) . " hours of licensed nurse care per resident day (National Average is 1.4 hours). ";
// --- C. Chain and Deficiency Insight ---
$chain_insight = "";
if (!empty($chain_name1) || !empty($chain_name2)) {
$chain_insight_flag = false;
if (!empty($chain_name1) && $chain_avg1 > 0) {
$chain_insight .= "{$name1} is part of the " . ucwords(strtolower($chain_name1)) . " chain, which holds an average overall rating of " . number_format($chain_avg1, 2) . ". ";
$chain_insight_flag = true;
}
if (!empty($chain_name2) && $chain_avg2 > 0) {
$chain_insight .= "{$name2} is part of the " . ucwords(strtolower($chain_name2)) . " chain, which holds an average overall rating of " . number_format($chain_avg2, 2) . ". ";
$chain_insight_flag = true;
}
if ($chain_insight_flag) {
$summary_output .= $chain_insight;
}
}
// --- D. Deficiency Summary (using Cycle 1 Deficiencies) ---
// Note: $defsv1 and $defsv2 must be treated as numeric integers for comparison
if (($defsv1 > 0 && $defsv2 > 0) || ($defsv1 > 0 && $defsv2 == 0) || ($defsv1 == 0 && $defsv2 > 0)) {
$defsv1 = (int)$defsv1;
$defsv2 = (int)$defsv2;
$deficiency_insight = "Regarding recent health inspection history, ";
if ($defsv1 > 0 && $defsv2 > 0) {
$deficiency_insight .= "both facilities had deficiencies in their most recent survey, with {$name1} recording {$defsv1} total deficiencies and {$name2} recording {$defsv2}.";
} elseif ($defsv1 > 0) {
$deficiency_insight .= "{$name1} recorded {$defsv1} deficiencies in its last survey, while {$name2} had a clean record in that cycle.";
} elseif ($defsv2 > 0) {
$deficiency_insight .= "{$name2} recorded {$defsv2} deficiencies in its last survey, while {$name1} had a clean record in that cycle.";
}
$summary_output .= $deficiency_insight;
}
// --- E. Financial/Penalty Summary (Final sentence) ---
if ($fines1 !== '$0.00' || $fines2 !== '$0.00') {
$penalty_comparison = "";
if ($fines1 === '$0.00' && $fines2 !== '$0.00') {
$penalty_comparison = "Finally, in terms of compliance history, {$name1} has a clean record with no fines, while {$name2} has incurred total penalties of {$fines2}.";
} elseif ($fines2 === '$0.00' && $fines1 !== '$0.00') {
$penalty_comparison = "Finally, in terms of compliance history, {$name2} has a clean record with no fines, while {$name1} has incurred total penalties of {$fines1}.";
} else {
$penalty_comparison = "Finally, in terms of compliance history, both facilities have incurred past fines; {$name1} totaling {$fines1}, and {$name2} totaling {$fines2}.";
}
$summary_output .= $penalty_comparison;
} else {
$summary_output .= "Finally, both facilities have a clean compliance record with no reported penalties in the latest data.";
}
$summary_output .= "
\n";
$summary_output .= "
\n";
echo $summary_output;
?>
*Staffing, resident, and quality ratings are based on the latest data provided by CMS (Centers for Medicare & Medicaid Services).