Skip to content

ProjectPatient dashboards with risk indicators

  • Industry

    Pharma and healthcare

  • Cloud

    OmniStudio, Lightning Web Components

  • Role

    OmniStudio and LWC developer

  • Period

    Independent, 2023 – present

Problem

A care team looking at a long table of patients cannot scan it. The rows that matter (the patients at risk) were buried among the ones that did not, and the standard components could neither re-sort the data by what matters nor show risk at a glance.

What I built

Dashboards that combine OmniStudio (for data retrieval and orchestration) with custom LWCs (for the interaction): dynamic sorting, filtering, and risk indicators that turn a long table into something a person can triage.

How it works

The pattern: data in, shape once. Data arrives through OmniStudio (Integration Procedure and DataRaptor) and is normalised in the LWC into a flat list of row objects, with the derived risk level computed once rather than on every render.

Sort and filter on derived state. Sort key, direction and active filters are the only reactive state. The visible rows are a getter over that state, so a change to any of them re-renders the table without refetching.

Risk as a first-class column. Risk is a small ordered scale rather than a free-text value. That makes it sortable, filterable and renderable as an indicator with a colour and a text label, so it never depends on colour alone.

Illustrative: rebuilt for this site, not client codepatientTable.js
import { LightningElement, api } from 'lwc';

const RISK_ORDER = { high: 3, medium: 2, low: 1 };

export default class PatientTable extends LightningElement {
  @api rows = [];
  sortBy = 'risk';
  sortDir = 'desc';
  riskFilter = 'all';

  get visibleRows() {
      const dir = this.sortDir === 'asc' ? 1 : -1;
      const key = this.sortBy;
      return this.rows
          .filter((r) => this.riskFilter === 'all' || r.risk === this.riskFilter)
          .map((r) => ({ ...r, riskClass: `risk risk_${r.risk}`, riskLabel: r.risk.toUpperCase() }))
          .sort((a, b) => {
              const av = key === 'risk' ? RISK_ORDER[a.risk] : a[key];
              const bv = key === 'risk' ? RISK_ORDER[b.risk] : b[key];
              return av > bv ? dir : av < bv ? -dir : 0;
          });
  }

  handleSort(event) {
      const field = event.currentTarget.dataset.field;
      this.sortDir = field === this.sortBy && this.sortDir === 'desc' ? 'asc' : 'desc';
      this.sortBy = field;
  }

  handleFilter(event) {
      this.riskFilter = event.detail.value;
  }
}

Try it

Loading component…

The dashboard (c-patient-dashboard) holds the search, filter, sort and paging state and renders one c-patient-card per patient. Every change goes to the Apex method as a new request, and only the requested page comes back.

Illustrative: rebuilt for this site, not client codepatientDashboard.js
@wire(getPatients, {
  searchKey: '$searchKey',
  stage: '$stage',
  risk: '$risk',
  ageMin: '$ageMin',
  ageMax: '$ageMax',
  sortBy: '$sortBy',
  sortDir: '$sortDir',
  pageSize: '$pageSize',
  pageNumber: '$pageNumber',
})
wiredPatients({ data, error }) {
  this.isLoading = false;
  if (data) {
      this.patients = data.records;
      this.total = data.total;
  } else if (error) {
      this.error = error.body.message;
  }
}

goTo(page) {
  const target = Math.min(this.totalPages, Math.max(1, page));
  this.update({ pageNumber: target }, { resetPage: false });
}
Illustrative: rebuilt for this site, not client codePatientController.js
// Mirrors the Apex signature:
// @AuraEnabled(cacheable=true)
// getPatients(searchKey, stage, risk, ageMin, ageMax, sortBy, sortDir, pageSize, pageNumber)
export async function getPatients(p = {}) {
  // filter by search, stage, risk and age range; sort by a whitelisted field; slice the page
  return { records: rows.slice(start, start + pageSize), total: rows.length, pageNumber };
}

Built with the Salesforce Lightning Design System. Not affiliated with Salesforce.

App Launcher