Git Product home page Git Product logo

fhir-react's Introduction

CircleCI Storybook

fhir-react

A React component library for displaying FHIR data.

Installation

npm install --save fhir-react

Usage

This package has two exports: a FhirResource React component and fhirVersions object.

import { FhirResource, fhirVersions } from 'fhir-react';

Render the component providing the FHIR data as a JavaScript object:

const MyComponent = () => {
  const fhirResource = JSON.parse(fhirResourceAsJsonString);
  return (
    <FhirResource
      fhirResource={fhirResource}
      fhirVersion={fhirVersions.R4}
      fhirIcons={fhirIcons}
      withCarinBBProfile
    />
  );
};

Optionally custom header icons could be passed as fhirIcons props in few different way:

  1. As a URL
const MyComponent = () => {
  const fhirResource = JSON.parse(fhirResourceAsJsonString);
  return (
    <FhirResource
      fhirResource={fhirResource}
      fhirVersion={fhirVersions.R4}
      fhirIcons="https://www.gravatar.com/avatar/?s=50&r=any&default=identicon&forcedefault=1"
      withCarinBBProfile
    />
  );
};
  1. As a <img> element
const MyComponent = () => {
  const fhirResource = JSON.parse(fhirResourceAsJsonString);
  return (
    <FhirResource
      fhirResource={fhirResource}
      fhirVersion={fhirVersions.R4}
      fhirIcons={<img
        src={require('./dstu2/resources/condition/condition.svg')}
        alt="header icon"
      />}
      withCarinBBProfile
    />
  );
};
  1. As a React src from import
import EncounterIcon from '../../../assets/containers/Encounter/encounter.svg';

const MyComponent = () => {
  const fhirResource = JSON.parse(fhirResourceAsJsonString);
  return (
    <FhirResource
      fhirResource={fhirResource}
      fhirVersion={fhirVersions.R4}
      fhirIcons={EncounterIcon}
      withCarinBBProfile
    />
  );
};

or

const MyComponent = () => {
  const fhirResource = JSON.parse(fhirResourceAsJsonString);
  return (
    <FhirResource
      fhirResource={fhirResource}
      fhirVersion={fhirVersions.R4}
      fhirIcons={require('./dstu2/resources/condition/condition.svg')}
      withCarinBBProfile
    />
  );
};
  1. As a false value to display the placeholder
const MyComponent = () => {
  const fhirResource = JSON.parse(fhirResourceAsJsonString);
  return (
    <FhirResource
      fhirResource={fhirResource}
      fhirVersion={fhirVersions.R4}
      fhirIcons={false}
      withCarinBBProfile
    />
  );
};
  1. Without a fhirIcons props The resource icon if it exists or a placeholder will be displayed.

  2. As the resources object with resource type as the key and image URL or DOM node as the value

import React from 'react';

export default {
  Condition: (
    <img
      src={require('./dstu2/resources/condition/condition.svg')}
      alt="header icon"
    />
  ),
  Immunization: (
    <img
      src={require('./dstu2/resources/immunization/immunization.svg')}
      alt="header icon"
    />
  ),
};

There is a possibility to overwrite default's Accordion function, by passing a function to onClick variable in a component.

const MyComponent = () => {
  const fhirResource = JSON.parse(fhirResourceAsJsonString);
  
  const functionHandler = /*function*/
  
  return (
    <FhirResource
      fhirResource={fhirResource}
      fhirVersion={fhirVersions.R4}
      onClick={functionHandler}
    />
  );
};

User can provide a number that can be assigned at the end of Accordion id. Not providing any number will cause a lodash uniqueId function to be used instead (default functionality up to this point).

const MyComponent = () => {
  const fhirResource = JSON.parse(fhirResourceAsJsonString);
  
  return (
    <FhirResource
      fhirResource={fhirResource}
      fhirVersion={fhirVersions.R4}
      customId={id}
    />
  );
};

FhirResource component props

Prop Type Default Description
fhirResource* Object - The FHIR resource to be rendered
fhirVersion* fhirVersions.DSTU2, fhirVersions.STU3, fhirVersions.R4 - FHIR resource version
withCarinBBProfile Boolean false Use Carin BB profile extension on top of the HL7 default FHIR specification https://build.fhir.org/ig/HL7/carin-bb/index.html
withDaVinciPDex Boolean false Use DaVinci Payer Data Exchange (PDex) profile extension on top of the HL7 default FHIR specification https://hl7.org/fhir/us/davinci-drug-formulary/index.html
thorough Boolean false If this is set to true, or if it is absent, all array items and supported attributes will be displayed. Otherwise if this is false then only the first or otherwise important items will be displayed

* required props

Available fhirVersions

Available resources

Resource DSTU2 STU3 R4 Carin BB Profile DaVinci PDex
AdverseEvent N/A
AllergyIntolerance
AdverseEvent N/A
AllergyIntolerance
Appointment
Bundle
CarePlan
CareTeam N/A
Claim
ClaimResponse
Condition
Coverage
Device
DiagnosticReport
DocumentReference
Encounter
ExplanationOfBenefit
Goal
Immunization
List
Location
Medication
MedicationAdministration
MedicationDispense
MedicationKnowledge N/A N/A
MedicationRequest N/A
MedicationStatement
Observation
Organization
Patient
Practitioner
PractitionerRole N/A
Procedure
Questionnaire
QuestionnaireResponse
ReferralRequest N/A
ResearchStudy N/A

Styles update v0.3

The 0.3 version of the FHIR React Component library introduces the bootstrap Accordion component as the base of each available resource which provides any data. The RWD support is provided for each component.

All of the changes can be tracked by viewing the current version of the storybook.

Available resources v0.3

Resource DSTU2 STU3 R4 Carin BB Profile DaVinci PDex
Appointment
Condition
Encounter
ExplanationOfBenefit
Immunization
Observation
Patient
Practitioner
Procedure

The update does not change the datasets which components are able to handle. It means that user can display the same particulars as in the previous version of the specific component.

Styles

Optional CSS styles are provided with this library. They are split into two files:

  • style.css with basic styling of the components
  • bootstrap-reboot.min.css further enhancing those styles

To use provided styles include them in the React component:

import 'fhir-react/build/style.css';
import 'fhir-react/build/bootstrap-reboot.min.css';

The working demo example with styles included can be viewed here.

Storybook

Run storybook local server with:

npm run storybook

Now you can check how a component graphically presents information based on raw data at http://localhost:63653 .

There's also an online version available at http://storybook-fhir-react-lib.s3-website-us-east-1.amazonaws.com .

Development

  1. run npm link in this folder to create the npm package locally
  2. in the folder where you are using the package (some other project) run npm link fhir-react
  3. in that other project import this package as you would normally with import FhirReact from 'fhir-react'
  4. Finally, in this fhir-react folder run the watch command via npm start and start developing.

Test

npm run test

Lint

npm run lint
npm run stylelint

Build

npm run build

Publish to NPM Registry

To publish, create a new release in GitHub.

Storybook for the changes

When creating a new PR, changes will be available in the storybook at:
http://storybook-fhir-react-lib.s3-website-us-east-1.amazonaws.com/dev/{branch-name}/

fhir-react's People

Contributors

alseeley1uphealth avatar beeauvin avatar christopher1uphealth avatar ctomasz avatar daria-lasecka avatar dependabot[bot] avatar ishan1uphealth avatar jaceksanko avatar jocelynn1uphealth avatar joebutler2 avatar konradnojman avatar liam1uphealth avatar michal-maksajda avatar ricky1uphealth avatar sflejszman avatar tony1uphealth avatar tp1uphealth avatar vikas1uphealth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fhir-react's Issues

create ReferralRequest component

TODO:

  • Create scaffold of component
  • Add DSTU2 support to component
  • Add STU3 support to component
  • Add fixtures, tests, storybook stories

create Coverage component

TODO:

  • Create scaffold of component
  • Add DSTU2 support to component
  • Add STU3 support to component
  • Add fixtures, tests, storybook stories

create MedicationRequest component

TODO:

  • Create scaffold of component
  • Add DSTU2 support to component
  • Add STU3 support to component
  • Add fixtures, tests, storybook stories

create Organization component

TODO:

  • Create scaffold of component
  • Add DSTU2 support to component
  • Add STU3 support to component
  • Add fixtures, tests, storybook stories

create ClaimResponse component

TODO:

  • Create scaffold of component
  • Add DSTU2 support to component
  • Add STU3 support to component
  • Add fixtures, tests, storybook stories

create Location component

TODO:

  • Create scaffold of component
  • Add DSTU2 support to component
  • Add STU3 support to component
  • Add fixtures, tests, storybook stories

Set up code linter in fhir-react

  • Set up eslint & prettier for fihr-react.
  • Add lint and lint:fix tasks to package.json that will check and automatically fix code formatting.
  • Fix the formatting and lint violations of the entire codebase.
  • Add the lint step to CircleCI build, so it will fail when code is malformed.

Recommended eslint config: see what create-react-app uses https://www.npmjs.com/package/eslint-config-react-app
https://www.npmjs.com/package/eslint-config-prettier
https://www.npmjs.com/package/eslint-plugin-prettier

Example .eslintrc config:

{
  "extends": [
    "react-app",
    "prettier"
  ],
  "plugins": [
    "prettier"
  ],
  "rules": {
    "semi": "error",
    "prettier/prettier": "error",
  }
}

create DocumentReference component

TODO:

  • Create scaffold of component
  • Add DSTU2 support to component
  • Add STU3 support to component
  • Add fixtures, tests, storybook stories

create CareTeam component

TODO:

  • Create scaffold of component
  • Add DSTU2 support to component
  • Add STU3 support to component
  • Add fixtures, tests, storybook stories

FhirResource Component

should allow any fhir resource to be inserted and display using the correct compoenent based on resourceType

create Medication component

TODO:

  • Create scaffold of component
  • Add DSTU2 support to component
  • Add STU3 support to component
  • Add fixtures, tests, storybook stories

create Questionnaire component

TODO:

  • Create scaffold of component
  • Add DSTU2 support to component
  • Add STU3 support to component
  • Add fixtures, tests, storybook stories

Set up tests in fhir-react

  • Set up jest and react-testing-library in fihr-react.
  • Add a few example tests.
  • Run the tests during CircleCI build.

Improve the style architecture

The current state of styling in fhir-react is a mix of inline styles and bootstrap.
It is not very readable, a bit inconsistent and not extensible by users.

Here's our idea to improve the architecture:

  • Consistency: write regular CSS files for styles, instead of inline/bootstrap combo.
  • Extensibility: use BEM-style class names e.g. .fhir-ui__Value, fhir-resource__Observation. Consumers will be able to override these classes with their own styles.
  • Lessen the dependency on bootstrap (avoid using its classes and utilities).

TODO:

  • Style components in src/components/ui
  • Style components in src/components/resources
  • Style components in src/components/container
  • Style components in src/components/datatypes
  • Optional: export one stylesheet for consumers to import (e.g. via webpack)

create Claim component

TODO:

  • Create scaffold of component
  • Add DSTU2 support to component
  • Add STU3 support to component
  • Add fixtures, tests, storybook stories

create Appointment component

TODO:

  • Create scaffold of component
  • Add DSTU2 support to component
  • Add STU3 support to component
  • Add fixtures, tests, storybook stories

Remove dead code from fhir-react

I noticed the current size of fhir-react package is ~430KB (uncompressed).
This is way too big for a reusable package.

AFAICT, the main culprits are:

  • lodash package, which is being imported in entirety, even though we use only a few utilities.
  • crypto package, also imported whole even though we just use the MD5 hash function.

TODO:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.