Skip to content

Flux Notes Data Sources

Matthew Gramigna edited this page Mar 18, 2019 · 2 revisions

Patient data in Flux Notes can come from a variety of sources, hardcoded or otherwise. To ensure that we approach loading data into Flux Notes in a modular way, we have a variety of data source classes in src/dataaccess

Current Data Sources

  • Hardcoded Patient JSON
  • FHIR API Data Source
  • REST API Data Source
  • SMART on FHIR Data Source

Each of these data sources extend the IDataSource class (src/dataaccess/IDataSource.jsx), which serves as an interface to define the function that a Flux Notes data should implement for data to load correctly.

Creating A New Data Source

Naming Convention

All data sources provide Flux Notes Object Model as output and accept it as input. What differentiates them from each other is what data format and protocol they use on the other side to retrieve and store data external to the application. The name of the data source should reflect the expected format and protocol for data between the application and the external data source.

For example, if the incoming data is FHIR DSTU2 coming from a REST API, an appropriate name would be FhirDstu2RestApiDataSource.jsx which clearly indicates the incoming format and protocol of the data.

Implementation

  1. Create a new file src/dataaccess/NewDataSource.jsx (with a descriptive name) and make a class that extends IDataSource:
import IDataSource from './IDataSource';

class NewDataSource extends IDataSource {

}

export default NewDataSource;
  1. Define this._gestalt in the constructor and implement getGestalt. This object defines which CRUD operations support async or synchronous access for the data source:
import IDataSource from './IDataSource';

class NewDataSource extends IDataSource {
    constructor() { 
        super();
        this._gestalt = { 
            create: {
                async: false,
                sync: false
            },
            read: {
                async: false,
                sync: true
            },
            update: {
                async: false,
                sync: false
            },
            delete: {
                async: false,
                sync: false
            }
        };
    }

    getGestalt() {
        return this._gestalt;
    }
}

export default NewDataSource;
  1. Implement getPatient At the very least, getGestalt and getPatient must be implemented for the data source to load into Flux Notes:
import IDataSource from './IDataSource';
import PatientRecord from '../patient/PatientRecord';

class NewDataSource extends IDataSource {
    constructor() { 
        super();
        this._gestalt = { 
            create: {
                async: false,
                sync: false
            },
            read: {
                async: false,
                sync: true
            },
            update: {
                async: false,
                sync: false
            },
            delete: {
                async: false,
                sync: false
            }
        };
    }

    getGestalt() {
        return this._gestalt;
    }

    getPatient(id, callback) {
        /* get the patient JSON in the correct format */

        return new PatientRecord(/* your JSON*/);
    }
}

export default NewDataSource;

Utilizing FHIR Mapping in a Data Source

Cases my arise where incoming FHIR in a given data source needs to be passed through a mapper to accurately align the JSON with what the Flux Notes Object Model expects (e.g. putting mCODE profiles on incoming FHIR)

The fhir-mapper library allows for the authoring of mappers for any format of incoming FHIR to have mCODE profiles. The project README lists the current implemented mappers, as well as includes a guide for developing a new mapper.

Once the mapper exists in fhir-mapper it can easily be pulled into a data source to apply the mapping to data:

import IDataSource from './IDataSource';
import PatientRecord from '../patient/PatientRecord';
import { someMapper } from 'fhir-mapper';

class NewDataSource extends IDataSource {
    constructor() { 
        super();
        this._gestalt = { 
            create: {
                async: false,
                sync: false
            },
            read: {
                async: false,
                sync: true
            },
            update: {
                async: false,
                sync: false
            },
            delete: {
                async: false,
                sync: false
            }
        };
    }

    getGestalt() {
        return this._gestalt;
    }

    getPatient(id, callback) {
        const resources = /* list of FHIR resources from the JSON */;
        const results = someMapper.execute(resources); // mapped results that can be replaced in the JSON

        return new PatientRecord(/* your JSON*/);
    }
}

export default NewDataSource;
Clone this wiki locally