Skip to content

Commit 9572453

Browse files
fix(sql): update care team member count and enhance demo data seeding
- Adjusted the expected count of active care team members in the `verify-demo-data.sh` script from 4 to 5 to reflect recent changes in demo data. - Added a new entry for an ACL smoke user in the `seed-demo-data.sql` file, ensuring proper seeding of healthcare professional roles for testing purposes. - Improved comments in the SQL file for better clarity on the purpose of the new entry.
1 parent 0ff76b2 commit 9572453

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

agent-forge/scripts/verify-demo-data.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ main() {
364364
expect_count \
365365
"alex care team active members" \
366366
"SELECT COUNT(*) FROM care_team_member ctm INNER JOIN care_teams ct ON ct.id = ctm.care_team_id WHERE ct.pid = ${DEMO_PID} AND ctm.status = 'active';" \
367-
"4"
367+
"5"
368368

369369
expect_count \
370370
"alex primary insurance row" \

agent-forge/sql/seed-demo-data.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,18 @@ INSERT INTO care_team_member (
14941494
'Care coordinator for referrals and prior auth.',
14951495
1,
14961496
1
1497+
),
1498+
(
1499+
@alex_care_team_id,
1500+
@af_clin_smoke_user_id,
1501+
NULL,
1502+
'healthcare_professional',
1503+
3,
1504+
'2025-12-01',
1505+
'active',
1506+
'AgentForge clinician smoke user (non-admin chart access for Co-Pilot QA).',
1507+
1,
1508+
1
14971509
);
14981510

14991511
INSERT INTO openemr_postcalendar_events (

src/AgentForge/Auth/SqlPatientAccessRepository.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
/**
44
* SQL-backed patient relationship lookups for AgentForge authorization.
55
*
6+
* A user is treated as having a direct chart relationship when any of:
7+
* - the patient lists them as primary provider (`patient_data.providerID`);
8+
* - an encounter lists them as rendering or supervising provider;
9+
* - they are an active member of an active care team for the patient.
10+
*
611
* @package OpenEMR
712
* @link https://www.open-emr.org
813
* @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
@@ -44,6 +49,17 @@ public function userHasDirectRelationship(PatientId $patientId, int $userId): bo
4449
[$patientId->value, $userId, $userId],
4550
);
4651

47-
return $encounterPid !== null;
52+
if ($encounterPid !== null) {
53+
return true;
54+
}
55+
56+
$careTeamMemberId = QueryUtils::fetchSingleValue(
57+
'SELECT ctm.id FROM care_team_member AS ctm INNER JOIN care_teams AS ct ON ct.id = ctm.care_team_id' .
58+
' WHERE ct.pid = ? AND ctm.user_id = ? AND ct.status = ? AND ctm.status = ? LIMIT 1',
59+
'id',
60+
[$patientId->value, $userId, 'active', 'active'],
61+
);
62+
63+
return $careTeamMemberId !== null;
4864
}
4965
}

0 commit comments

Comments
 (0)