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

fhirbuilder

v1.6.0

Published

Another FHIR Tool to build FHIR Resources

Downloads

377

Readme

Available Resources

Resources available in this package

| Resource | Resource | Resource | | ------------------------------------------------------------------------- | ------------------------------------------------------------- | ----------------------------------------------------------------- | | EpisodeOfCare | Organization | Patient | | Observation | Coverage | ServiceRequest | | AllergyIntolerance | Procedure | Bundle |

Install

npm i fhirbuilder
# for fhirtypes
npm i fhirtypes

Use

Create context

import { contextR4 } from 'fhirbuilder';

const r4Context = contextR4();

From r4Context Object you can access to all FHIR Datatypes, Resources models and Validators

Using models

In this example we will use and Address model datatype

import { contextR4 } from 'fhirbuilder';
const { Address } = contextR4();

//you can create a new Instance

const address = new Address({
  use: 'home',
  type: 'postal',
  text: 'test',
  line: ['line1', 'line2'],
});
console.log(address);

Output

{
  "use": "home",
  "type": "postal",
  "text": "test",
  "line": ["line1", "line2"]
}

Using builders

For complex object you can use a builders

import { contextR4 } from 'fhirbuilder';
import { AdministrativeGenderEnum } from 'fhirtypes/dist/r4/enums';
const { Patient, HumanName, Address, PatientBuilder } = contextR4();

const patient = new PatientBuilder()
  .setId('123')
  .setActive(true)
  .addName(
    new HumanName({
      family: 'Doe',
      given: ['John'],
    }),
  )
  .setGender(AdministrativeGenderEnum.MALE)
  .addAddress(
    new Address({
      use: 'home',
      line: ['123 Main St'],
      city: 'Somewhere',
      state: 'CA',
      postalCode: '12345',
      country: 'USA',
    }),
  )
  .build();

Output

{
  "id": "123",
  "resourceType": "Patient",
  "active": true,
  "name": [
    {
      "family": "Doe",
      "given": ["John"]
    }
  ],
  "gender": "male",
  "address": [
    {
      "use": "home",
      "line": ["123 Main St"],
      "city": "Somewhere",
      "state": "CA",
      "postalCode": "12345",
      "country": "USA"
    }
  ]
}

Using Validators

const { Patient } = contextR4();

const identifier = new Identifier({
  assigner: {
    reference: 'Acme Healthcare', // ❌ invalid reference
  },
});

const patient = new Patient({
  id: '123',
  active: true,
  identifier: [identifier],
});

const result = patient.validate();

console.log(result);

Output error

{
  "isValid": false,
  "operationOutcome": {
    "issue": [
      {
        "code": "invalid",
        "details": {
          "text": "Path: Patient.identifier[0].assigner.reference. Value: Acme Healthcare"
        },
        "diagnostics": "Invalid reference format. Reference must be in the format 'ResourceType/ResourceId'.",
        "severity": "error"
      }
    ]
  }
}