feat: share patients across all users
Removed per-user patient filtering so all staff accounts see the same patient pool. Previously each user only saw patients they created. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -167,7 +167,7 @@ router.get("/status", async (req: Request, res: Response): Promise<any> => {
|
||||
SELECT pg_size_pretty(pg_database_size(current_database())) as size
|
||||
`;
|
||||
|
||||
const patientsCount = await storage.getTotalPatientCount(userId);
|
||||
const patientsCount = await storage.getTotalPatientCount();
|
||||
const lastBackup = await storage.getLastBackup(userId);
|
||||
|
||||
res.json({
|
||||
|
||||
@@ -11,7 +11,7 @@ const router = Router();
|
||||
// Get all patients for the logged-in user
|
||||
router.get("/", async (req, res) => {
|
||||
try {
|
||||
const patients = await storage.getPatientsByUserId(req.user!.id);
|
||||
const patients = await storage.getAllPatients();
|
||||
res.json(patients);
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: "Failed to retrieve patients" });
|
||||
@@ -24,10 +24,9 @@ router.get("/recent", async (req: Request, res: Response) => {
|
||||
const limit = parseInt(req.query.limit as string) || 10;
|
||||
const offset = parseInt(req.query.offset as string) || 0;
|
||||
|
||||
const userId = req.user!.id;
|
||||
const [patients, totalCount] = await Promise.all([
|
||||
storage.getRecentPatients(limit, offset, userId),
|
||||
storage.getTotalPatientCount(userId),
|
||||
storage.getRecentPatients(limit, offset),
|
||||
storage.getTotalPatientCount(),
|
||||
]);
|
||||
|
||||
res.json({ patients, totalCount });
|
||||
|
||||
@@ -10,8 +10,8 @@ export interface IStorage {
|
||||
// Patient methods
|
||||
getPatient(id: number): Promise<Patient | undefined>;
|
||||
getPatientByInsuranceId(insuranceId: string): Promise<Patient | null>;
|
||||
getPatientsByUserId(userId: number): Promise<Patient[]>;
|
||||
getRecentPatients(limit: number, offset: number, userId: number): Promise<Patient[]>;
|
||||
getAllPatients(): Promise<Patient[]>;
|
||||
getRecentPatients(limit: number, offset: number): Promise<Patient[]>;
|
||||
getPatientsByIds(ids: number[]): Promise<Patient[]>;
|
||||
createPatient(patient: InsertPatient): Promise<Patient>;
|
||||
updatePatient(id: number, patient: UpdatePatient): Promise<Patient>;
|
||||
@@ -33,7 +33,7 @@ export interface IStorage {
|
||||
status: string;
|
||||
}[]
|
||||
>;
|
||||
getTotalPatientCount(userId: number): Promise<number>;
|
||||
getTotalPatientCount(): Promise<number>;
|
||||
countPatients(filters: any): Promise<number>; // optional but useful
|
||||
getPatientFinancialRows(
|
||||
patientId: number,
|
||||
@@ -49,8 +49,8 @@ export const patientsStorage: IStorage = {
|
||||
return patient ?? undefined;
|
||||
},
|
||||
|
||||
async getPatientsByUserId(userId: number): Promise<Patient[]> {
|
||||
return await db.patient.findMany({ where: { userId } });
|
||||
async getAllPatients(): Promise<Patient[]> {
|
||||
return await db.patient.findMany();
|
||||
},
|
||||
|
||||
async getPatientByInsuranceId(insuranceId: string): Promise<Patient | null> {
|
||||
@@ -59,9 +59,8 @@ export const patientsStorage: IStorage = {
|
||||
});
|
||||
},
|
||||
|
||||
async getRecentPatients(limit: number, offset: number, userId: number): Promise<Patient[]> {
|
||||
async getRecentPatients(limit: number, offset: number): Promise<Patient[]> {
|
||||
return db.patient.findMany({
|
||||
where: { userId },
|
||||
skip: offset,
|
||||
take: limit,
|
||||
orderBy: { updatedAt: "desc" },
|
||||
@@ -143,8 +142,8 @@ export const patientsStorage: IStorage = {
|
||||
});
|
||||
},
|
||||
|
||||
async getTotalPatientCount(userId: number): Promise<number> {
|
||||
return db.patient.count({ where: { userId } });
|
||||
async getTotalPatientCount(): Promise<number> {
|
||||
return db.patient.count();
|
||||
},
|
||||
|
||||
async countPatients(filters: any) {
|
||||
|
||||
Reference in New Issue
Block a user