@useplugged/core
v0.0.1
Published
Plugged TS/JS Library
Readme
Plugged JS Client Library
The Plugged JS Client Library is a pure TypeScript library for calling a FHIR server from the browser.
Key Features
- FHIR validation and operations
- FHIR client to create, read, update, delete, patch, and search
- WebSockets for realtime communication
- Evaluation of FhirPath
- No external dependencies
Installation
Add as a dependency:
npm install @useplugged/coreBasic Usage
Create a new PluggedClient:
import { PluggedClient } from '@useplugged/core';
const plugged = new PluggedClient();Create a PluggedClient with additional configuration options:
import { PluggedClient } from '@useplugged/core';
const plugged = new PluggedClient({
baseUrl: 'https://www.example.com/fhir/R4/',
clientId: 'MY_CLIENT_ID',
});Authenticate with client credentials
const plugged = new PluggedClient();
await plugged.startClientLogin(MY_CLIENT_ID, MY_CLIENT_SECRET);Authenticating with Plugged
If you are using Plugged as your FHIR server, you can use a direct sign-in API to authenticate email and password.
Before you begin
- Create a project in the Plugged App
- Enable Email/Password
After that, you can use the startLogin() method:
const loginResult = await plugged.startLogin({ email, password, remember });
const profile = await plugged.processCode(loginResult.code);
console.log(profile);Authenticating with OAuth
Authenticate with a FHIR server via OAuth2 redirect:
plugged.signInWithRedirect().then((user) => console.log(user));Search
Search for any resource using a FHIR search string:
search<K extends ResourceType>(
resourceType: K,
query?: URLSearchParams | string,
options: RequestInit = {}
): ReadablePromise<Bundle<ExtractResource<K>>>Example:
const bundle = await plugged.search('Patient', 'given=eve');
bundle.entry.forEach((entry) => console.log(entry.resource));Create
createResource<T extends Resource>(resource: T): Promise<T>Example:
plugged.createResource({
resourceType: 'Observation',
subject: {
reference: 'Patient/123',
},
valueQuantity: {
// ...
},
// ...
});Read a resource
readResource<T extends Resource>(resourceType: string, id: string): Promise<T>Example:
const patient = await plugged.readResource('Patient', '123');Read resource history
readHistory<T extends Resource>(resourceType: string, id: string): Promise<Bundle<T>>Example:
const historyBundle = await plugged.readHistory('Patient', '123');Read resource version
readVersion<T extends Resource>(resourceType: string, id: string, vid: string): Promise<T>Example:
const version = await plugged.readVersion('Patient', '123', '456');Update a resource
updateResource<T extends Resource>(resource: T): Promise<T>Example:
const result = await plugged.updateResource({
resourceType: 'Patient',
id: '123',
name: [
{
family: 'Smith',
given: ['John'],
},
],
});
console.log(result.meta.versionId);Delete a resource
deleteResource(resourceType: string, id: string): Promise<any>Example:
await plugged.deleteResource('Patient', '123');Patch a resource
patchResource<T extends Resource>(resourceType: string, id: string, operations: Operation[]): Promise<T>Example:
const result = await plugged.patchResource('Patient', '123', [
{ op: 'replace', path: '/name/0/family', value: 'Smith' },
]);
console.log(result.meta.versionId);GraphQL
graphql(query: string, options?: RequestInit): Promise<any>Example:
const result = await graphql(`
{
PatientList(name: "Alice") {
name {
given
family
}
}
}
`);License
Apache 2.0. Copyright © Plugged 2023
