Skip to content

Commit

Permalink
Merge pull request #9 from standardhealth/mapper_classes
Browse files Browse the repository at this point in the history
Rework mappers to be full classes
  • Loading branch information
Matthew Gramigna authored Sep 26, 2019
2 parents 1a17187 + f76800b commit 757b1e3
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 40 deletions.
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
Library for mapping various forms of FHIR to mCODE by adding mCODE profiles onto the incoming FHIR.

## Current Mappers
* Synthea FHIR => mCODE v0.5 (`src/mappers/syntheaToV05.js`)
* Synthea FHIR => mCODE v0.9 (`src/mappers/syntheaToV09.js`)
* Synthea FHIR => mCODE v0.5 (`src/mappers/SyntheaToV05.js`)
* Synthea FHIR => mCODE v0.9 (`src/mappers/SyntheaToV09.js`)
* Cerner Sandbox => mCODE v0.9 (`src/mappers/Cerner.js`)

## Quickstart

Expand All @@ -17,13 +18,15 @@ $ yarn add fhir-mapper
In the file where the mapping needs to be done, import one of the supported mappers (e.g. Synthea) directly into the project. Here is an example of utilizing the Synthea mapper to add mCODE v0.5 profiles onto Synthea FHIR:

``` JavaScript
import { syntheaToV05 } from 'fhir-mapper';
import SyntheaToV09 from 'fhir-mapper';

const mapper = new SyntheaToV09();

const json = {/* obtained Synthea FHIR json */};
const entries = [];

const resources = json.entry.map(e => e.resource);
const results = syntheaToV05.execute(resources);
const results = mapper.execute(resources);
const wrappedResults = results.map(resource => {
return {
fullUrl: `urn:uuid:${resource.id}`,
Expand Down Expand Up @@ -64,7 +67,7 @@ Create the new mapper in `src/mapping/mappers/<your-mapper>.js` and import the m
``` JavaScript
/* src/mapping/mappers/<your-mapper>.js */

const { buildMappers } = require('../mapper');
const { AggregateMapper } = require('../mapper');

const applyProfile = (resource, profile) => {
if (profile) {
Expand All @@ -89,18 +92,22 @@ const resourceMapping = {
]
};

module.exports = buildMappers(resourceMapping);
export default class YourNewMapper extends AggregateMapper {
constructor(variables = {}) {
super(resourceMapping, variables);
}
}
```

Lastly, add the new mapper to be exported by `src/mapping/mappers/index.js`:

``` JavaScript
const syntheaToV05 = require('./syntheaToV05');
const yourNewMapper = require('./<your-mapper>.js'); // want to export new mapper to use in project
const SyntheaToV05 = require('./syntheaToV05');
const YourNewMapper = require('./<your-mapper>.js'); // want to export new mapper to use in project

module.exports = {
syntheaToV05,
yourNewMapper
SyntheaToV05,
YourNewMapper
};
```

Expand All @@ -126,7 +133,7 @@ Usage:
> yarn map <mapper> <input> <output>
```
Where:
- *mapper* - The name of the mapper to use to map the given files. Must be one of the mappers defined in `src/mapping/mappers/index.js`. Ex: `syntheaToV05`
- *mapper* - The name of the mapper to use to map the given files. Must be one of the mappers defined in `src/mapping/mappers/index.js`. Ex: `SyntheaToV05`
- *input* - The path to a single FHIR JSON file or folder containing multiple FHIR JSON files to process.
- *output* - The location to put the mapped file. If *input* is a folder, *output* should be a folder. Each processed file will have the same name as the unprocessed file in the output folder. *output* may be a single filename if *input* is a single filename.

Expand All @@ -135,7 +142,7 @@ Where:
Sample:

```
$ yarn map syntheaToV09 ~/synthea/output/fhir_dstu2/ output
$ yarn map SyntheaToV09 ~/synthea/output/fhir_dstu2/ output
Processing ~/synthea/output/fhir_dstu2/Aaron697_Corwin846_e97aaf5b-609c-4147-bf6f-921f45966f72.json
Wrote output/Aaron697_Corwin846_e97aaf5b-609c-4147-bf6f-921f45966f72.json
Processing ~/synthea/output/fhir_dstu2/Aaron697_Lind531_9a572c87-2074-4263-9be5-281f55ee0e90.json
Expand Down
6 changes: 3 additions & 3 deletions dist/app.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/app.bundle.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/app.node.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/app.node.bundle.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fhir-mapper",
"version": "2.0.1",
"version": "3.0.0",
"main": "dist/app.bundle.js",
"repository": "git@github.com:standardhealth/fhir-mapper.git",
"author": "Matthew Gramigna <mgramigna@mitre.org>",
Expand Down
4 changes: 3 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ if (!fhirMapper.mappers[mapper]) {
throw new Error(`Unknown mapper name: ${mapper}`);
}

mapper = fhirMapper.mappers[mapper];
const mapperClass = fhirMapper.mappers[mapper];

mapper = new mapperClass();

if (!fs.existsSync(input)) {
throw new Error(`Input file does not exist: ${input}`);
Expand Down
20 changes: 12 additions & 8 deletions src/mapping/mappers/cerner.js → src/mapping/mappers/Cerner.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const {
buildMappers
} = require('../mapper');
const SyntheaToV09 = require('./SyntheaToV09');
const { AggregateMapper } = require('../mapper');
const utils = require('../../utils');
const syntheaToV09 = require('./syntheaToV09');
const mcodeUtils09 = utils.mcodeUtils09;

let vars = {
Expand Down Expand Up @@ -36,9 +34,11 @@ let clinicalTPath = "Observation.code.text in %cTCodes"
let clinicalNPath = "Observation.code.text in %cNCodes"
let clinicalMPath = "Observation.code.text in %cMCodes"

const baseDefaultMapper = new SyntheaToV09();

let mapper = {
filter: () => true,
default: (resource, context) => syntheaToV09.execute(resource, context),
default: (resource, context) => baseDefaultMapper.execute(resource, context),
mappers: [

{
Expand Down Expand Up @@ -213,9 +213,13 @@ let mapper = {
],
};

module.exports = buildMappers(mapper,
vars
);
class Cerner extends AggregateMapper {
constructor(variables = {}) {
super(mapper, { ...vars, ...variables });
}
}

module.exports = Cerner;


// {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { buildMappers } = require('../mapper');
const { AggregateMapper } = require('../mapper');
const {applyProfile} = require('../../utils');

const DEFAULT_PROFILE = {
Expand Down Expand Up @@ -36,4 +36,10 @@ const resourceMapping = {
]
};

module.exports = buildMappers(resourceMapping);
class SyntheaToV05 extends AggregateMapper {
constructor(variables = {}) {
super(resourceMapping, variables);
}
}

module.exports = SyntheaToV05;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { buildMappers } = require('../mapper');
const { AggregateMapper } = require('../mapper');
const { applyProfile, applyProfileFunction, hasProfileFromList, mcodeUtils09 } = require('../../utils');

const defaultProfile = (resourceType) => {
Expand Down Expand Up @@ -274,5 +274,10 @@ const resourceMapping = {
]
};

class SyntheaToV09 extends AggregateMapper {
constructor(variables = {}) {
super(resourceMapping, { ...mcodeUtils09.fhirPathVariables, ...variables });
}
}

module.exports = buildMappers(resourceMapping, mcodeUtils09.fhirPathVariables);
module.exports = SyntheaToV09;
13 changes: 7 additions & 6 deletions src/mapping/mappers/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const syntheaToV05 = require('./syntheaToV05');
const syntheaToV09 = require('./syntheaToV09');
const cerner = require('./cerner');
const SyntheaToV05 = require('./SyntheaToV05');
const SyntheaToV09 = require('./SyntheaToV09');
const Cerner = require('./Cerner');

module.exports = {
syntheaToV05,
syntheaToV09,
cerner
SyntheaToV05,
SyntheaToV09,
Cerner
};

0 comments on commit 757b1e3

Please sign in to comment.