npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bpac/valida-client

v1.0.0

Published

Client library for third party applications that use the Valida Client API

Downloads

3

Readme

Valida Client

Usage instructions

Please refer to the implementation guide for more comprehensive API documentation.

Including in your project

Import this package into one of the files in your application.

import '@bpac/valida-client';

When the website is launched from Valida Client the FHIR and OpenEHR APIs will be available via window.ds2.pms.

If the website was not launched from Valida Client then window.ds2 will be null.

Example

Load the current patient as a FHIR Patient resource and output the name.

Note the @bpac/valida-client import statement only needs to be done once per webpage - suggest it it put into whatever file is loaded first.

import { Component, OnInit } from '@angular/core';
import { SearchParameter } from '@bpac/pms-api';
import '@bpac/valida-client';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
  public async ngOnInit(): Promise<void> {
    let patientId = await this.getOpenEhr('PatientId');

    let patientSearchParameters = [{ name: 'patientId', comparator: 'eq', value: patientId.id }];

    //load asynchronously
    let patientsPromise = this.getFhir<fhir.Patient>('Patient', patientSearchParameters);
    let observationsPromise = this.getFhir<fhir.Observation>('Observation', patientSearchParameters);
    let conditionsPromise = this.getFhir<fhir.Condition>('Condition', patientSearchParameters);

    //await all async requests
    let [patients, observations, conditions] = await Promise.all([patientsPromise, observationsPromise, conditionsPromise]);

    //do something with the data
    let message = `Patient: ${patientId.id} - ${patients[0].name[0].given} - has ${observations.length} Observation resources and ${conditions.length} Condition resources.`;

    alert(message);
  }

  private getOpenEhr(type: string): Promise<any> {
    return new Promise((resolve, reject) => {
      window.ds2.pms.get({ type }, response => {
        //status.success will be true when the request succeeded
        if (response.status.success) {
          resolve(response.instance);
        } else {
          //status.message contains the error message when status.success is false
          reject(response.status.message);
        }
      });
    });
  }

  private getFhir<T>(type: string, searchParameter: SearchParameter[]): Promise<T[]> {
    return new Promise((resolve, reject) => {
      window.ds2.pms.getFhir(type, searchParameter, result => {
        //an OperationOutcome will be returned when there is an error
        if (result.resourceType === 'OperationOutcome') {
          reject(result);
        } else {
          //otherwise a bundle of results will be returned
          let bundle = result as fhir.Bundle;

          if (bundle.entry == null) {
            return [];
          }

          //the bundle will always have an array of entries even when there is only a single result
          resolve(bundle.entry.map(entry => entry.resource as T));
        }
      }, 0);
    });
  }
}

FHIR API

getFhirApiDefinition

Calls though to window.FhirApi.getApiDefinition

window.ds2.pms.getFhirApiDefinition((definition: FhirDataProviderDefinition[]) => {
    //do something with the definition
});

getFhir

Calls though to window.FhirApi.getFhir

window.ds2.pms.getFhir('Patient', [], (patientBundle: fhir.Bundle) => {
    //do something with the result
});

putFhir

Calls though to window.FhirApi.putFhir

window.ds2.pms.putFhir('patientId', {resourceType:'Bundle'}, (result: fhir.OperationOutcome) => {
    //check the writeback result
});

cancelOutstandingRequests

Calls though to window.FhirApi.cancelOutstandingRequests

window.ds2.pms.cancelOutstandingRequests('Observation', (result: fhir.OperationOutcome) => {
    //observation requests will be canceled
});

OpenEHR API

getOpenEhrApiDefinition

Calls though to window.PmsInterface.getApiDefinition

window.ds2.pms.getOpenEhrApiDefinition((definition: OpenEhrDataProviderDefinition[]) => {
    //do something with the definition
});

get

Calls though to window.PmsInterface.get

window.ds2.pms.get({type:'Patient', patientId:{id:'123'}}, (response: PmsApiResponse) => {
    //do something with the response
});

list

Calls though to window.PmsInterface.list

window.ds2.pms.list({type:'Blood pressure', patientId:{id:'123'}}, (response: PmsApiResponse) => {
    //do something with the response
});

put

Calls though to window.PmsInterface.put

window.ds2.pms.put({type:'Blood pressure', patientId:{id:'123'}, instance:{}}, (response: PutResult) => {
    //do something with the response
});

putBatch

Calls though to window.PmsInterface.putBatch

window.ds2.pms.putBatch([{type:'Blood pressure', patientId:{id:'123'}, instance:{}}], (response: PutResult) => {
    //do something with the response
});

Miscellaneous

flushCache

Calls though to window.PmsInterface.flushCache

window.ds2.pms.flushCache(() => {
    //any cached patient data has now been cleared within Valida Client
});

registerCallback

Calls though to window.MosaicClient.registerCallback

window.ds2.pms.registerCallback('patientOpened', () => {
    //the current patient has been changed
});