-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c8902b9
commit b16f982
Showing
5 changed files
with
154 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { AggregateMapper } = require('fhir-mapper'); | ||
const fhirpath = require('fhirpath'); | ||
|
||
// Mapping of resource tyoe to FHIR date property / format | ||
// This is based on what date type our CSV extractors output | ||
// for example, Observation could have any of the effectiveX date types, but we output effectiveDateTime | ||
const DateFormatByResourceType = { | ||
Observation: 'effectiveDateTime', | ||
Condition: 'extension.valueDateTime', | ||
// TODO add other resource types and their associate dates | ||
// OR write code to check for all date formats | ||
}; | ||
|
||
|
||
// Excludes resources of a specified type from a bundle if they are outside the given date range | ||
class DateFilterMapper extends AggregateMapper { | ||
constructor(resourceType, startDate = null, endDate = null) { | ||
const resourceMapping = { | ||
filter: (r) => r.resource.resourceType === this.resourceType, | ||
exclude: (r) => { | ||
const date = fhirpath.evaluate(r.resource, DateFormatByResourceType[this.resourceType])[0]; | ||
// const date = resource[DateFormatByResourceType[this.resourceType]]; | ||
const time = new Date(date).getTime(); | ||
const start = (new Date(this.startDate)).getTime(); | ||
const end = (new Date(this.endDate)).getTime(); | ||
return (this.endDate && (time > end)) || (this.startDate && time < start); | ||
}, | ||
exec: (resource) => resource, | ||
}; | ||
|
||
super(resourceMapping, {}); | ||
|
||
this.startDate = startDate; | ||
this.endDate = endDate; | ||
this.resourceType = resourceType; | ||
} | ||
} | ||
|
||
module.exports = { | ||
DateFilterMapper, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters