Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Showing results

Lens result format

When your application has queried a backend and receives results from sites, it has to pass these results to Lens so it can display them. Lens expects results of type LensResult, for example:

{
    "stratifiers": {
        "gender": {
            "female": 31,
            "male": 43
        },
        "diagnosis": {
            "C34.0": 26,
            "C34.2": 28,
            "C34.8": 25
        }
    },
    "totals": {
        "patients": 74,
        "samples": 312
    }
}

The totals field contains the total number of patients, samples, etc. The stratifiers field contains stratum counts (e.g. male, female) for each stratier (e.g. gender). The specific stratifiers depend on the application. When you add a chart to your application you specify which stratifier it should display.

Focus can return the Lens result format directly. If you are quering a FHIR server you can convert a FHIR measure report to the Lens result format using the measureReportToLensResult function.

Passing results to Lens

You pass results to Lens using the setSiteResult function. Before you pass a result you may call markSiteClaimed to indicate that the site is available and will deliver results soon. This examples shows how you would pass results from Focus to Lens.

querySpot(
    getBackendUrl(),
    getSiteList(),
    query,
    abortController.signal,
    (result: SpotResult) => {
        const site = result.from.split(".")[1];
        if (result.status === "claimed") {
            markSiteClaimed(site);
        } else if (result.status === "succeeded") {
            const siteResult = JSON.parse(atob(result.body));
            setSiteResult(site, siteResult);
        } else {
            console.error(
                `Site ${site} failed with status ${result.status}:`,
                result.body,
            );
        }
    },
);

Components

Lens provides components to render results.