Reset demo app

60 views
Skip to first unread message

Dave

unread,
Jul 31, 2024, 11:18:00 AMJul 31
to SMART on FHIR
It seems that the demo app is in an error state and needs to be reset (at least the instance I am using).  

Tinkering with the SMART on FHIR fhirclient, I called...
client.patient.request("Patient")

Afterwards, ALL calls give the error: "Error: Patient is not available", even if the call has nothing to do with Patient.

I'm newer to the project, so could be something else, but I am positive that code I ran to pull all Encounters no longer works and it gives the patient error.  Does the app need to be reset?  Or how can I get around this error?

Dylan Phelan

unread,
Aug 1, 2024, 10:08:30 AMAug 1
to SMART on FHIR
Hi Dave,

Can you provide a little more context on your error, which fhirclient/version you're using, and exactly what demo app you're testing? From what you've said, it sounds like you might be using the latest version of the client-py fhirclient, but I'm not sure

Thanks!
- Dylan P.

Dave

unread,
Aug 1, 2024, 10:36:14 AMAug 1
to SMART on FHIR
I'm using the javascript fhir-client.  I'll pull together a minimal demonstration of the problem and post here shortly.

Dave

unread,
Aug 1, 2024, 11:07:16 AMAug 1
to SMART on FHIR
Here is the complete example with the specific `iss` I used.  I tried several different `iss` values from various launch types and with and without a selected patient from https://launch.smarthealthit.org.  It seems that possibly the smarthealthit.org/v/r4/sim environment needs to be reset.  If that is the case, I can share the other code which seems to have triggered the fault state.

import express from "express";
import smart from "fhirclient";
import { fhirclient } from "fhirclient/lib/types";
import session from "express-session";
import dotenv from "dotenv";

dotenv.config();

const app = express();

export class StorageWrapper {
  session: any;

  constructor(session: any) {
    this.session = session;
  }

  async get(key: string): Promise<any> {
    return this.session[key];
  }

  async set(key: string, value: any): Promise<any> {
    this.session[key] = value;
    return value;
  }

  async unset(key: string): Promise<boolean> {
    if (Object.prototype.hasOwnProperty.call(this.session, key)) {
      delete this.session[key];
      return true;
    }
    return false;
  }
}

app.use(express.json());

app.use(
  session({
    secret: "my-secret-key",
    resave: false,
    saveUninitialized: true,
    cookie: { secure: false },
  })
);

app.get("/", async (req, res) => {
  const authorizeParams: fhirclient.AuthorizeParams = {
    clientId: "whatever",
    clientSecret: "my secret",
    scope: "user/*.* openid fhirUser offline_access",
  };

  await smart(req, res, new StorageWrapper(req.session)).authorize(authorizeParams);
});

app.get("/api/integration/fhir/callback", async (req, res) => {
  const client = await smart(req, res, new StorageWrapper(req.session)).ready();
  const encountersBundle = await client.request("Encounter");
  console.log(encountersBundle);
  // Throws "Error: Patient is not available"
});

app.listen(3000, () => {
  console.log(`Server is running on http://localhost:3000`);
});

Vladimir Ignatov

unread,
Aug 1, 2024, 11:33:46 AMAug 1
to Dave, SMART on FHIR
Here are some clarifications that might help you solve this.

1. The “standard” way to make requests is using client.request(“SomeResource”)
2. To get a patient you can do client.request(“Patient/SomePatientID”)
3. If you select a patient at launch time, then you will have a patient object property on your client and you will be able to call the client.patient.request() method. Otherwise you will get the error you mentioned which means your client does not have a “current patient” and therefore every attempt to use the client.patient… API will fail with such error.

Things like client.patient.request() or client.patient.id exist for compatibility with legacy apps using older version of this library. The important part to remember here is that these patient properties and methods are only available if there is a current patient selected at launch time.

Conclusion: Make sure there is a patient selected at launch. Add “launch” to your requested scopes and try again.

For more info on client.patient.request() see https://docs.smarthealthit.org/client-js/client.html.

Hope that helps,
Vlad

-- 
You received this message because you are subscribed to the Google Groups "SMART on FHIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to smart-on-fhi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/smart-on-fhir/3918a910-7886-4c3d-9d7d-d6b23b53624bn%40googlegroups.com.

Dave

unread,
Aug 1, 2024, 2:16:55 PMAug 1
to SMART on FHIR
Including `launch` in scopes worked.

Still I think there may an internal state issue with the SMART server sim environment, because removing `launch` with no other changes, now works again.  When I was exploring the library I believe I called `client.patient.request("Patient")` (possibly without the await in front of it).  And problems started after that.  I am not certain about that as I have not gone back to reproduce.  But I'm familiar with the clarifications you mentioned, and the error "Patient is not available" was returned even when not querying for patient information.  Maybe not worth investigating since it is a legacy function.  Thank you for the information and your help!

Heshan Wanigasooriya

unread,
Aug 1, 2024, 2:45:30 PMAug 1
to SMART on FHIR
I have this demo App do pretty much what you need https://github.com/heshanlk/epic-sandbox
Reply all
Reply to author
Forward
0 new messages