Dashboard analytics across the projects
# support
t
Hi @rahul1 I'm working on a dashboard and need some guidance on displaying analytics without impacting performance. Specifically, I want to show the count of registered users across all projects in the system for a super admin view. Here are the approaches I'm considering: Approach 1: - Fetch all projects in the system. - Loop through each project to get the count of users. Concerns: If a Patient or Practitioner is deleted but the User resource remains, this could lead to count mismatches. Approach 2: - Fetch all ProjectMembership resources. - Each ProjectMembership has a User resource reference. However, it also includes references to bots and client applications, such as:
Copy code
json
  ProjectMembership {
    User: {
      reference: "Bot/123"
    }
  }
Copy code
json
  ProjectMembership {
    User: {
      reference: "ClientApplication/123"
    }
  }
- I would need to filter out these non-user references and only count resources like:
Copy code
json
  ProjectMembership {
    User: {
      reference: "User/123"
    }
  }
Concerns: Users can be deleted, but their ProjectMembership might not be, which could also cause count mismatches. Neither approach seems ideal. Do you have any suggestions for achieving this goal without affecting performance?
r
You could search for ProjectMemberships, but filter on
profile-type
to exclude bots
t
Thank you for your response will try with this.
Hi @rahul1 My dashboard includes monthly active users count. In my SaaS platform, each client has their own project, and each project can consist of multiple organizations. I need to calculate monthly active users for the following two scenarios: 1. Super Admin: - The Super Admin needs to see monthly active users across all projects. - I'm achieving this by filtering
Login
resources using the project ID and a date range:
Copy code
typescript
     const response: Bundle<any> = await this.medplumService.medplum.search(
         'Login',
         `_lastUpdated=ge${startDate}&_lastUpdated=le${endDate}&_elements=membership,project&_count=1000`,
     );
- I then extract unique user IDs from the results to calculate the monthly active user count across all projects. 2. Project Admin: - The Project Admin needs to see monthly active users within each organization. - I'm doing this by fetching all
Login
resources within a date range. - I extract
ProjectMembership
references from the
Login
resources and then: - Fetch
Patient
and
Practitioner
resources linked to the organization. Patients are fetched using the
managingOrganization
parameter, and Practitioners are fetched via the
PractitionerRole
resource, filtered by the organization ID. - Extract the corresponding user references of patients and practitioners from the
ProjectMembership
resources. Example
ProjectMembership
structure:
Copy code
typescript
   ProjectMembership {
       User: {
           reference: 'User/abc'
       },
       Profile: {
           reference: 'Patient/abc' or 'Practitioner/abc'
       }
   }
- Filter the fetched
Login
resources by user references from the
ProjectMembership
resource, and extract unique user IDs to determine the monthly active users. While this approach works, the performance is not optimal. Could you please review this approach and suggest any more efficient alternatives?
Additionally, if the approach that I shared above is correct, is there an approach of storing the data in the non-FHIR tables? Or do we have a FHIR resource in which we can store analytics data.
r
@tusharnisal , good questions. You are on the bleeding edge here, but I do think that using the
Login
resource is the core of your approach
One thing you could consider is computing a
MeasureReport
resource to cache the metric of monthly active users. This means that you could compute the metric offline, rather than than on the fly when the user loads the dashboard
t
ok Thank you @rahul1 for the response.
j
Postgres tends to not be suitable for analytics dashboards unless you only have a bit of data. If you need something designed for analytics dashboards, you can checkout ClickHouse using a serverless platform such as PropelData.
180 Views