Skip to content

Commit f148f5d

Browse files
author
Michael O'Keefe
authored
Remove the reference type must support changes, as they were not working as intended (#17)
1 parent 7586029 commit f148f5d

File tree

1 file changed

+0
-119
lines changed

1 file changed

+0
-119
lines changed

lib/modifications.rb

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -392,74 +392,6 @@ def self.modify!(results, random_seed = 3)
392392
'http://hl7.org/fhir/StructureDefinition/bp'
393393
]
394394

395-
resources_with_multiple_mustsupport_references = {
396-
FHIR::CareTeam => [
397-
{
398-
fhirpath: 'participant.member',
399-
required_ref_types: [
400-
FHIR::Patient,
401-
FHIR::Practitioner,
402-
FHIR::Organization
403-
],
404-
base_object: FHIR::CareTeam::Participant.new.from_hash({ role: [{ coding: [{ code: '223366009', system: 'http://snomed.info/sct', display: 'Healthcare provider' }] }] })
405-
},
406-
],
407-
# NOTE: DiagnosticReport should be here, but because of the difficulties around the two profiles, we handle it elsewhere
408-
FHIR::DocumentReference => [
409-
{
410-
fhirpath: 'author',
411-
required_ref_types: [
412-
FHIR::Patient,
413-
FHIR::Practitioner,
414-
FHIR::Organization
415-
],
416-
base_object: nil
417-
}
418-
],
419-
FHIR::MedicationRequest => [
420-
{
421-
fhirpath: 'reportedReference',
422-
required_ref_types: [
423-
FHIR::Patient,
424-
FHIR::Practitioner,
425-
FHIR::Organization
426-
],
427-
base_object: :self
428-
},
429-
{
430-
fhirpath: 'requester',
431-
required_ref_types: [
432-
FHIR::Patient,
433-
FHIR::Practitioner,
434-
FHIR::Organization,
435-
FHIR::Device
436-
],
437-
base_object: :self
438-
}
439-
],
440-
FHIR::Provenance => [
441-
{
442-
fhirpath: 'agent.who',
443-
required_ref_types: [
444-
FHIR::Patient,
445-
FHIR::Practitioner,
446-
FHIR::Organization
447-
],
448-
base_object: FHIR::Provenance::Agent.new.from_hash({
449-
type: {
450-
coding: [
451-
{
452-
code: 'author',
453-
display: 'Author',
454-
system: 'http://terminology.hl7.org/CodeSystem/provenance-participant-type'
455-
}
456-
]
457-
}
458-
})
459-
}
460-
]
461-
}
462-
463395
# Add missing Head Circumference Percent resource
464396
unless DataScript::Constraints.has_headcircum(results)
465397
headcircum_resource = FHIR::Observation.new({
@@ -563,57 +495,6 @@ def self.modify!(results, random_seed = 3)
563495
end
564496
puts " - Rewrote Provenance targets."
565497

566-
bundle_with_all = results.find do |b|
567-
DataScript::Constraints.has(b, FHIR::Patient) &&
568-
DataScript::Constraints.has(b, FHIR::Practitioner) &&
569-
DataScript::Constraints.has(b, FHIR::Organization) &&
570-
DataScript::Constraints.has(b, FHIR::Device) &&
571-
DataScript::Constraints.has(b, FHIR::CareTeam) &&
572-
DataScript::Constraints.has(b, FHIR::DiagnosticReport) &&
573-
DataScript::Constraints.has(b, FHIR::DocumentReference) &&
574-
DataScript::Constraints.has(b, FHIR::Provenance)
575-
end
576-
references = {
577-
FHIR::Patient => { reference: "urn:uuid:#{bundle_with_all.entry.find { |e| e.resource.is_a? FHIR::Patient }&.resource&.id}" },
578-
FHIR::Practitioner => { reference: "urn:uuid:#{bundle_with_all.entry.find { |e| e.resource.is_a? FHIR::Practitioner }&.resource&.id}" },
579-
FHIR::Organization => { reference: "urn:uuid:#{bundle_with_all.entry.find { |e| e.resource.is_a? FHIR::Organization }&.resource&.id}" },
580-
FHIR::Device => { reference: "urn:uuid:#{bundle_with_all.entry.find { |e| e.resource.is_a? FHIR::Device }&.resource&.id}" }
581-
}
582-
583-
resources_with_multiple_mustsupport_references.each do |resource_class, reference_attrs|
584-
resources = bundle_with_all.entry.find_all { |e| e.resource.is_a? resource_class }.map { |e| e.resource }
585-
resources.each do |resource|
586-
reference_attrs.each do |attrs|
587-
begin
588-
extant_ref_types = FHIRPath.evaluate(attrs[:fhirpath], resource&.to_hash)
589-
.collect { |ref| get_reference_type(bundle_with_all, ref['reference']) }
590-
.uniq
591-
rescue
592-
extant_ref_types = []
593-
end
594-
# Subtracting one array from the other will provide a list of elements
595-
# in needed_ref_types that aren't in extant_ref_types
596-
missing_ref_types = attrs[:required_ref_types] - extant_ref_types
597-
missing_ref_types.each do |missing_type|
598-
missing_reference = references[missing_type]
599-
if attrs[:base_object] == :self
600-
ref_obj = FHIR::Json.from_json(resource.to_json)
601-
ref_obj.id = SecureRandom.uuid
602-
ref_obj.send("#{attrs[:fhirpath]}=", missing_reference)
603-
bundle_with_all.entry << create_bundle_entry(ref_obj)
604-
elsif !attrs[:base_object].nil?
605-
fhirpath_split = attrs[:fhirpath].split('.')
606-
ref_obj = attrs[:base_object].class.new.from_hash(attrs[:base_object].to_hash)
607-
ref_obj.send("#{fhirpath_split.last}=", missing_reference)
608-
resource.send(fhirpath_split.first).push(ref_obj)
609-
else
610-
resource.send(attrs[:fhirpath]).push(missing_reference)
611-
end
612-
end
613-
end
614-
end
615-
end
616-
617498
DataScript::ChoiceTypeCreator.check_choice_types(results)
618499

619500
# DiagnosticReports need to have two performer types, so we add them here

0 commit comments

Comments
 (0)