Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions fixtures/stu3/terminology/codesystem-simple.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@
This is not an absolute requirement, but it may be enforced by some
servers - for instance, the HL7 valueset registry will. -->
<url value="http://hl7.org/fhir/CodeSystem/example-crucible"/>
<!-- an imaginary identifier. This is a non FHIR identifier - might be used in a
v2 context (though you always need to translate namespaces for v2) -->
<identifier>
<system value="http://acme.com/identifiers/codesystems"/>
<value value="internal-cholesterol-inl"/>
</identifier>
<!-- for version, we are going to simply use the day of publication. This is also
arbitrary - whatever is here is what people use to refer to the version.
Could also be a UUID too. Note that you should change the identify of the code
Expand Down
40 changes: 32 additions & 8 deletions lib/resource_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -772,10 +772,7 @@ def self.apply_invariants!(resource)
# i.maxLength = nil if !['boolean', 'decimal', 'integer', 'string', 'text', 'url'].include?(i.type)
# end
when FHIR::QuestionnaireResponse
resource.item.each do |i|
i.item = nil
i.answer.each {|q|q.valueBoolean = true if !q.value }
end
fix_questionnaire_response_items(resource.item)
when FHIR::Range
# validate that the low/high values in the range are correct (e.g. the low value is not higher than the high value)
if resource.low && resource.high
Expand Down Expand Up @@ -1559,10 +1556,7 @@ def self.apply_invariants!(resource)
i.maxLength = nil if !['boolean', 'decimal', 'integer', 'string', 'text', 'url'].include?(i.type)
end
when FHIR::STU3::QuestionnaireResponse
resource.item.each do |i|
i.item = nil
i.answer.each {|q|q.valueBoolean = true if !q.value }
end
fix_questionnaire_response_items(resource.item)
when FHIR::STU3::Range
# validate that the low/high values in the range are correct (e.g. the low value is not higher than the high value)
if resource.low && resource.high
Expand Down Expand Up @@ -2267,6 +2261,36 @@ def self.apply_invariants!(resource)
end
end

# Recursively fixes a QuestionnaireResponse item tree so it can be accepted
# by a strict FHIR parser.
#
# The generated tree can be arbitrarily deep via two nesting axes:
# item.answer[].item[] — items nested inside an answer
# item.item[] — direct sub-item groups on an item
#
# Two problems are corrected at every level:
# 1. Answers with no value are given `valueBoolean = true`. A strict parser
# rejects answer objects that are completely empty (`{}`).
# 2. Direct sub-item groups (`item.item`) are removed. They are often
# generated empty or with invalid content that would fail validation.
#
# Ordering matters: `answer.item` is recursed BEFORE `item.item` is cleared,
# because answer-nested items may themselves contain answers that need fixing.
# Clearing `item.item` first would not affect `answer.item`, but fixing
# `answer.item` last would process items that are immediately discarded —
# so the current order keeps the logic clear: fix answers deeply first, then drop
# the direct sub-groups.
def self.fix_questionnaire_response_items(items)
return if items.nil? || items.empty?
items.each do |item|
item.answer.each do |answer|
answer.valueBoolean = true unless answer.value
fix_questionnaire_response_items(answer.item) unless answer.item.nil?
end
item.item = nil
end
end

end
end
end
14 changes: 7 additions & 7 deletions lib/tests/suites/connectathon_attachment_track_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def teardown
requires resource: 'Communication', methods: ['create']
}
comm = FHIR::STU3::Communication.new()
comm.subject = [@records[:patient].to_reference]
comm.subject = @records[:patient].to_reference
comm.recipient = [@records[:practitioner].to_reference]
comm.status = 'preparation'

Expand All @@ -69,9 +69,9 @@ def teardown
comm_att.title = @attachments[att_type]

payload = FHIR::STU3::Communication::Payload.new
payload.contentAttachment = [comm_att]
payload.contentAttachment = comm_att

comm.payload = payload
comm.payload = [payload]
create_object(comm, "comm_#{att_type}")
end

Expand Down Expand Up @@ -103,8 +103,8 @@ def teardown
assert comm_req, 'No CommunicationRequest returned from server'

comm = FHIR::STU3::Communication.new()
comm.subject = [comm_req.subject]
comm.recipient = [comm_req.sender]
comm.subject = comm_req.subject
comm.recipient = [comm_req.sender].compact
comm.basedOn = [comm_req.to_reference]
comm.status = 'preparation'

Expand All @@ -114,9 +114,9 @@ def teardown
comm_att.title = @attachments[att_type]

payload = FHIR::STU3::Communication::Payload.new
payload.contentAttachment = [comm_att]
payload.contentAttachment = comm_att

comm.payload = payload
comm.payload = [payload]
create_object(comm, "comm_#{att_type}")
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/tests/suites/connectathon_genomics_track_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def teardown

observation.subject = @records[:patient].to_reference
observation.specimen = @records[:specimen_register_create].to_reference
observation.performer = @records[:practitioner].to_reference
observation.performer = [@records[:practitioner].to_reference]
create_object(observation, :observation_register_create)
end

Expand Down Expand Up @@ -127,11 +127,11 @@ def teardown
create_object(specimen, :family_specimen)

diag_report = @resources.diagnostic_familyhistory
diag_report.result = @records[:family_observation].to_reference
diag_report.result = [@records[:family_observation].to_reference]
diag_report.subject = @records[:family_patient].to_reference
diag_report.performer = [ FHIR::STU3::DiagnosticReport::Performer.new ]
diag_report.performer.first.actor = @records[:practitioner].to_reference
diag_report.specimen = @records[:family_specimen].to_reference
diag_report.specimen = [@records[:family_specimen].to_reference]
create_object(diag_report, :family_report)

reply = @client.read FHIR::STU3::FamilyMemberHistory, @records[:family_member_history].id
Expand Down Expand Up @@ -162,7 +162,7 @@ def teardown


dw_obs = @resources.observation_datawarehouse
dw_obs.performer = @records[:practitioner].to_reference
dw_obs.performer = [@records[:practitioner].to_reference]
dw_obs.subject = @records[:family_patient].to_reference
dw_obs.specimen = @records[:family_specimen].to_reference
create_object(dw_obs, :dw_obs)
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/suites/connectathon_lab_order_track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def create_diagnostic_report(specimen_name, observation_fixture_paths, diagnosti
observation = @resources.load_fixture(obs, :xml)
observation.specimen = @records[specimen_name].to_reference
observation.subject = @records[:patient].to_reference
observation.performer = @records[:performer].to_reference
observation.performer = [@records[:performer].to_reference]
observation_name = "#{dr_name}_observation_#{index}".to_sym
create_object(observation, observation_name)
diag_report.result << @records[observation_name].to_reference
Expand Down