-
Notifications
You must be signed in to change notification settings - Fork 2
Update Data Script for US Core v4/v5 #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jawalonoski
wants to merge
23
commits into
master
Choose a base branch
from
updates
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
fb42ed6
Update Synthea and Validator JARs.
jawalonoski 3a3bd17
Remove old validator JAR.
jawalonoski 8197faa
Adjust smoking status searches.
jawalonoski 252b807
Move Synthea related JARs to version specific folder.
jawalonoski 76c2740
Refactor for multiple version support.
jawalonoski a270947
Initial support for US Core v4.
jawalonoski 0f3c737
Update README
jawalonoski 587e84c
Refactor and intermittent bug fixes.
jawalonoski 6d6d0d7
Check validation messages for v5.
jawalonoski a29fa68
Fix v5 validation message checking.
jawalonoski 32d9536
Move v5 validatioin checks.
jawalonoski 2c46d15
More changes for v5 support.
jawalonoski c89c375
Initial QuestionnaireResponse for v5.
jawalonoski dc30aae
Add imaging result observations to v5.
jawalonoski 9c170f0
Add more profile support for v5.
jawalonoski cdb7316
More v5 modifications and attempt to fix filtering.
jawalonoski b7db89d
Remove unused code.
jawalonoski 868fcf5
Update filter logic.
jawalonoski 589d1c2
v5 bug fixes.
jawalonoski 6e032e6
Additional v5 bug fixes and PRAPARE fixes.
jawalonoski 757fd0c
Require certificate check in script.
jawalonoski b57231d
Fix aggressive filtering to include missing references.
jawalonoski d657417
Fix US Core v5 bugs.
jawalonoski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Mac OS X FS Junk | ||
**/.DS_Store | ||
output/ | ||
output/ | ||
lib/validator_cli.jar |
This file contains hidden or 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 hidden or 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,4 @@ | ||
#!/usr/bin/env sh | ||
|
||
wget https://github.com/hapifhir/org.hl7.fhir.core/releases/download/5.6.54/validator_cli.jar --no-check-certificate | ||
mv validator_cli.jar lib/validator_cli.jar |
This file contains hidden or 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 hidden or 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,121 @@ | ||
require 'pry' | ||
|
||
module DataScript | ||
class Filter | ||
def self.filter!(bundles) | ||
organization_bundle = bundles.find {|b| b.entry.first.resource.resourceType == 'Organization'} | ||
practitioner_bundle = bundles.find {|b| b.entry.first.resource.resourceType == 'Practitioner'} | ||
patient_bundles = bundles.select {|b| b.entry.first.resource.resourceType == 'Patient'} | ||
|
||
patient_bundles.each do |bundle| | ||
print "\n" | ||
tik = Time.now.to_i | ||
initial_length = bundle.entry.length | ||
profile_coverage = [] | ||
encounters_to_keep = [] | ||
resources_to_keep = [] | ||
|
||
bundle.entry.reverse.each do |entry| | ||
next unless ['AllergyIntolerance','Device','Encounter','Goal','RelatedPerson'].include?(entry.resource.resourceType) | ||
# start by looking at Encounters, most but not all resources reference the Encounter... | ||
if entry.resource.resourceType == 'Encounter' | ||
print '.' | ||
encounter_resources = get_resources_associated_with_encounter(bundle, entry.fullUrl) | ||
encounter_resources_profiles = encounter_resources.map {|resource| resource&.meta&.profile&.first}.compact | ||
if encounter_resources_profiles.any? {|p| !profile_coverage.include?(p) } | ||
profile_coverage.append(encounter_resources_profiles).flatten! | ||
profile_coverage.uniq! | ||
encounters_to_keep << entry.resource | ||
resources_to_keep.append(encounter_resources).flatten! | ||
end | ||
elsif entry.resource.resourceType == 'AllergyIntolerance' # allergyintolerance is special because it does not reference an encounter | ||
print 'a' | ||
resource_profile = entry.resource&.meta&.profile&.first | ||
if resource_profile == 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-allergyintolerance' | ||
resources_to_keep << entry.resource | ||
profile_coverage.append(resource_profile).flatten! | ||
profile_coverage.uniq! | ||
end | ||
elsif entry.resource.resourceType == 'Device' # device is special because it does not reference an encounter | ||
print 'd' | ||
resource_profile = entry.resource&.meta&.profile&.first | ||
if resource_profile == 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-implantable-device' | ||
resources_to_keep << entry.resource | ||
profile_coverage.append(resource_profile).flatten! | ||
profile_coverage.uniq! | ||
end | ||
elsif entry.resource.resourceType == 'Goal' # goal is special because it does not reference an encounter | ||
print 'g' | ||
resource_profile = entry.resource&.meta&.profile&.first | ||
if resource_profile == 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-goal' | ||
resources_to_keep << entry.resource | ||
profile_coverage.append(resource_profile).flatten! | ||
profile_coverage.uniq! | ||
end | ||
elsif entry.resource.resourceType == 'RelatedPerson' # relatedperson is special because it does not reference anything | ||
print 'r' | ||
resource_profile = entry.resource&.meta&.profile&.first | ||
if resource_profile == 'http://hl7.org/fhir/us/core/StructureDefinition/us-core-relatedperson' | ||
resources_to_keep << entry.resource | ||
profile_coverage.append(resource_profile).flatten! | ||
profile_coverage.uniq! | ||
end | ||
end | ||
end | ||
print "\n" | ||
|
||
bundle.entry.keep_if do |entry| | ||
['Patient','Provenance'].include?(entry.resource.resourceType) || | ||
encounters_to_keep.include?(entry.resource) || | ||
resources_to_keep.include?(entry.resource) | ||
end | ||
|
||
provenance = bundle.entry.find {|e| e.resource.resourceType == 'Provenance' }.resource | ||
uuids = bundle.entry.map {|e| e.fullUrl} | ||
provenance.target.keep_if {|reference| uuids.include?(reference.reference) } | ||
final_length = bundle.entry.length | ||
tok = Time.now.to_i | ||
puts " - Filtered #{initial_length} resources down to #{final_length} (#{DataScript::TimeUtilities.pretty(tok - tik)})." | ||
end | ||
end | ||
|
||
def self.get_resources_associated_with_encounter(bundle, encounter_urn) | ||
resources = [] | ||
refd_medications = [] | ||
refd_conditions = [] | ||
refd_related_person = [] | ||
|
||
bundle.entry.each do |entry| | ||
if entry.resource.respond_to?(:encounter) && entry.resource.encounter&.reference == encounter_urn | ||
resources << entry.resource | ||
refd_medications << entry.resource&.medicationReference&.reference if entry.resource.respond_to?(:medicationReference) | ||
refd_conditions << entry.resource&.reasonReference&.first&.reference if entry.resource.respond_to?(:reasonReference) | ||
refd_related_person << entry.resource&.participant&.find {|x| x&.role&.first&.text = 'Caregiver (person)'}&.member&.reference if entry.resource.resourceType == 'CareTeam' | ||
elsif entry.resource.resourceType == 'DocumentReference' && entry.resource.context.encounter.first.reference == encounter_urn | ||
resources << entry.resource | ||
end | ||
end | ||
|
||
refd_medications.uniq! | ||
refd_conditions.uniq! | ||
refd_related_person.uniq! | ||
|
||
refd_medications.each do |fullUrl| | ||
resources << bundle.entry.find {|e| e.fullUrl == fullUrl}&.resource | ||
end | ||
|
||
refd_conditions.each do |fullUrl| | ||
resources << bundle.entry.find {|e| e.fullUrl == fullUrl}&.resource | ||
end | ||
|
||
refd_related_person.each do |fullUrl| | ||
resources << bundle.entry.find {|e| e.fullUrl == fullUrl}&.resource | ||
end | ||
|
||
resources.uniq! | ||
resources.compact! | ||
resources | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.