Posos Widgets JavaScript SDK
    Preparing search index...

    Class PrescriptionWidget

    Class representing a prescription widget.

    Hierarchy

    • Widget<typeof PRESCRIPTION_EVENTS>
      • PrescriptionWidget
    Index

    Constructors

    • Creates an instance of PrescriptionWidget.

      Parameters

      • container: Element | null

        The DOM element where the widget will be injected.

      • options: WidgetOptions

        The options of the widget.

        • OptionalauthToken?: string

          The authentication token (JWT) for the widget.

        • OptionalbaseUrl?: string

          The base URL of the widget.

        • Optionaldebug?: boolean

          Whether to enable debug mode.

          false
          
        • Optionalenv?: "preprod" | "production"

          The widget environment.

          "production"
          

          This option has no effect if baseUrl is set.

        • OptionalframeHeight?: number

          The height of the widget’s iframe (in pixels).

          768
          

          The minimum accepted height is 768.

        • OptionalframeWidth?: number

          The width of the widget’s iframe (in pixels).

          600
          

          The minimum accepted width is 600.

        • Optionallocale?: string

          The language for the user interface of the widget.

          "fr"
          
        • OptionalsigningKey?: string

          The base64-encoded signing key using the ES256 algorithm.

          Please use the new authentication flow with authToken. Check out the documentation for more information.

        • OptionalsoftwareId?: string

          The software identifier making the widget call.

          Please use the new authentication flow with authToken. Check out the documentation for more information.

        • Optionaltheme?: string

          The widget’s user interface theme.

          "posos"
          
        • OptionaluserId?: string

          The identifier of the user making the widget call.

          Please use the new authentication flow with authToken. Check out the documentation for more information.

      Returns PrescriptionWidget

      const container = document.getElementById("posos-widget");
      const widget = new PrescriptionWidget(container, {
      authToken: "your-auth-token",
      });

    Methods

    • Destroys the widget instance by cleaning up resources and performing necessary teardown operations.

      This method should be called when the widget is no longer needed to ensure proper cleanup and avoid memory leaks.

      Returns void

      widget.destroy();
      
    • Registers a callback to handle authentication token refresh requests.

      This function is invoked when the widget detects that a new token is needed, for example when the current token is about to expire or has expired.

      Parameters

      • refreshAuthToken: () => string | Promise<string>

        A function that returns a fresh authentication token.

      Returns void

      • If the invoked function does not return a valid authentication token.
      widget.onAuthTokenRefresh(async () => {
      // Fetch a new auth token from your server
      const newAuthToken = await fetchNewAuthToken();

      return newAuthToken;
      });
    • Registers a callback that will be invoked when the prescription is ready.

      This event is triggered by the widget once the prescription is available for viewing or interaction.

      Parameters

      • handler: () => void

        A function to be called when the prescription becomes ready.

      Returns void

      widget.onPrescriptionReady(() => {
      console.log('Prescription is ready!');
      // You can now interact with the widget or update your UI
      });
    • Registers a callback that will be invoked when a prescription is saved.

      This event is triggered when the user (or the widget) initiates a save action, and the prescription export data becomes available.

      Parameters

      Returns void

      widget.onPrescriptionSave((payload) => {
      console.log('Prescription saved:', payload);
      // You can now persist or process the prescription data
      });
    • Reloads the current widget.

      Returns void

      Throws an error if the widget is not accessible.

      widget.reload();
      
    • Programmatically requests to save the current prescription and returns its payload.

      This method will reject if the widget is not ready or if the operation times out (5s).

      Returns Promise<PrescriptionExportPayload>

      A promise that resolves with the prescription export payload.

      If the widget is not ready or if no response is received within 5 seconds.

      // Example by processing the payload directly
      try {
      const payload = await widget.savePrescription();
      console.log('Prescription saved:', payload);
      } catch (err) {
      console.error('Failed to save prescription:', err);
      }

      // Example using the `onPrescriptionSave` callback
      widget.onPrescriptionSave((payload) => {
      // This will trigger everytime the `savePrescription` method is called
      console.log('Prescription saved:', payload);
      });

      try {
      // Do not process the payload directly and let the `onPrescriptionSave` callback handle it
      await widget.savePrescription();
      } catch (err) {
      console.error('Failed to save prescription:', err);
      }
    • Updates the authentication token in the widget.

      Parameters

      • authToken: string

        The new authentication token to be set.

      Returns void

      • If the given authentication token is invalid.
      widget.setAuthToken('new-auth-token');
      
    • Sets the contextual data required by the widget.

      This method must be called before the widget can complete its loading phase. Without it, the widget will remain in a loading state and will not be interactive.

      Parameters

      Returns void

      The widget will remain in loading state until this method is called.

      widget.setContext({
      patientId: "ed8c3c7b-3313-470f-b706-84a3e127c7cf",
      patientProfile: {
      allergies: [
      {
      coding: {
      code: "47703008",
      terminology: "snomed",
      },
      },
      ],
      birthDate: "1983-11-22",
      concurrentTreatments: [
      {
      coding: {
      code: "MV00001487",
      terminology: "posos",
      },
      },
      ],
      conditions: [
      {
      coding: {
      code: "186963008",
      terminology: "snomed",
      },
      isLongTermIllness: false,
      modifiers: [],
      },
      ],
      gfr: 110,
      height: 185,
      sex: "male",
      weight: 81,
      },
      sessionId: "189ea8f1-1030-4ba8-83a2-526cc6671b06",
      });
    • Sets a new comment for the current prescription.

      Parameters

      • comment: string | null

        The new prescription comment.

      Returns void

      To clear the prescription comment, pass null as the argument.

      widget.setPrescriptionComment('This is a comment for the current prescription.');