0.3.2 • Published 6 years ago

fhir-schemas v0.3.2

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

fhir-schemas

FHIR Resources implemented with json-schemas and some backwards support for simpl-schema. The purpose of this package is to a) make the HL7 FHIR json-schemas available on NPM, and b) start migrating Meteor apps off of meteor-simple-schema. Roughly speaking, the SimpleSchemas correspond to either v1.6.0 of DST2, and the JsonSchemas correspond to v3.0.1 or STU3.

Installation

# the core schema libraries
npm install -save fhir-schemas

# if you're running a Meteor app, you'll also want to install the following conversion utility
meteor npm install -save fhir-schemas
meteor add bshamblen:json-simple-schema

JsonSchema Usage

Going forward, we recommend the Json Schama format, which is the official schema published by the HL7 FHIR working groups, has low-level Mongo support, and has cross-platform support across a wide rage of Node/NPM apps.

Client

//-------------------------------------------------------------
// Schema Validation

import { FhirApi } from 'fhir-schemas';
import Ajv from 'ajv';

var ajv = new Ajv;    
var validate = ajv.addSchema(FhirApi).getSchema('http://hl7.org/fhir/json-schema/Patient');

var newPatient = {
    "resourceType": "Patient",
    "name": [{
        "family": 'Doe',
        "given": ['Jane']
    }],
    "identifier": [{
        "value": '123'
    }]
};

var isValid = validate(newPatient);

//-------------------------------------------------------------
// Server


import MongoClient from 'mongodb';

// this is a legacy API; based on the FHIR schemas shipping in different files
// will probably be deprecated in the future
import { PatientSchema } from 'fhir-schemas';

// Connection URL
const url = 'mongodb://localhost:27017';
 
// Database Name
const dbName = 'myproject';
 
// Use connect method to connect to the server
MongoClient.connect(url, function(err, client) { 
    const db = client.db(dbName);
 
    // we're hoping to have something like the following in the future
    // var PatientSchema = ajv.addSchema(FhirApi).getSchema('http://hl7.org/fhir/json-schema/Patient');

    db.createCollection("Patients", {
        validator: {
            $jsonSchema: PatientSchema
        }
    });

    if(isValid){
        console.log("newPatient is valid...");

        // Insert some documents
        db.collection('CurrentPatients').insertMany([
            newPatient
        ], function(err, result) {
            console.log("Inserted newPatient into the CurrentPatients collection");
        });
    } else {
        console.log("newPatient isn't valid...");
        console.log(validate.errors);
    }

    client.close();
});



//-------------------------------------------------------------
// Auto Forms 
// This is still experimental, and may not work.  

import React, { Component } from "react";
import { render } from "react-dom";

import Form from "react-jsonschema-form";

import { FhirApi, PatientSchema } from 'fhir-schemas';

const log = (type) => console.log.bind(console, type);

render((
  <Form schema={ PatientSchema }
        onChange={log("changed")}
        onSubmit={log("submitted")}
        onError={log("errors")} />
), document.getElementById("app"));


var simpleSchema = jsonSchema.toSimpleSchema();

Server - Meteor

The following is an example for Meteor apps.

import { PatientSchema } from 'fhir-schemas';

// JSONSchema is provided as a global, since it's loaded from Atmosphere package repository
var jsonSchema = new JSONSchema(PatientSchema);

// convert to simple schema
var simpleSchema = jsonSchema.toSimpleSchema();

// create our server side cursor
CurrentPatients = new Mongo.Collection('CurrentPatients');

// and attach the cursor
CurrentPatients.attachSchema(SimpleSchemas.PatientSchema);

// for debugging
var props = jsonSchema.toSimpleSchemaProps();
console.log('props', props)

Json Schemas

We provide Json Schemas for all of the following resources.
FHIR Resource Index

Notes & References

https://github.com/bshamblen/meteor-json-simple-schema

https://docs.mongodb.com/manual/core/schema-validation/#json-schema
https://docs.mongodb.com/manual/reference/command/collMod/#dbcmd.collMod
https://github.com/mozilla-services/react-jsonschema-form
https://tools.ietf.org/html/draft-zyp-json-schema-04

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.13

6 years ago

0.2.12

6 years ago

0.2.11

6 years ago

0.2.10

6 years ago

0.2.9

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.2

6 years ago

0.2.0

6 years ago

0.1.39

6 years ago

0.1.38

6 years ago

0.1.37

6 years ago

0.1.36

6 years ago

0.1.35

6 years ago

0.1.34

6 years ago

0.1.33

6 years ago

0.1.32

6 years ago

0.1.31

6 years ago

0.1.30

6 years ago

0.1.29

6 years ago

0.1.28

6 years ago

0.1.27

6 years ago

0.1.26

6 years ago

0.1.25

6 years ago

0.1.24

6 years ago

0.1.23

6 years ago

0.1.22

6 years ago

0.1.21

6 years ago

0.1.20

6 years ago

0.1.19

6 years ago

0.1.18

6 years ago

0.1.17

6 years ago

0.1.16

6 years ago

0.1.15

6 years ago

0.1.14

6 years ago

0.1.13

6 years ago

0.1.12

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago