Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Fix transaction suite generated Condition resource #179

Open
wants to merge 3 commits into
base: r4
Choose a base branch
from
Open
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
22 changes: 21 additions & 1 deletion lib/resource_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ def self.minimal_condition(system='http://snomed.info/sct',code='414915002',pati
resource.subject.display = 'Patient'
end
resource.code = minimal_codeableconcept(system,code, namespace)
resource.verificationStatus = 'confirmed'
if namespace == 'FHIR::DSTU2'
resource.verificationStatus = 'confirmed'
end
tag_metadata(resource)
end

Expand Down Expand Up @@ -412,6 +414,19 @@ def self.apply_invariants!(resource)
# resource.targetReference = textonly_reference('ValueSet')
# end
when FHIR::Condition
# con-3
verification_status_is_entered_in_error = resource&.verificationStatus&.coding&.include?('entered-in-error')
category_is_problem_list_item = resource&.category&.find {|e| e&.coding&.include?("problem-list-item")}
if (!verification_status_is_entered_in_error || !category_is_problem_list_item)
clinical_status_code = ['active', 'recurrence', 'relapse', 'inactive', 'remission', 'resolved'].sample
resource.clinicalStatus = minimal_codeableconcept('http://hl7.org/fhir/ValueSet/condition-clinical', clinical_status_code)
end

# con-5
if resource&.verificationStatus&.coding&.include?('entered-in-error')
resource.clinicalStatus = nil
end

if resource.onsetAge
resource.onsetAge.system = 'http://unitsofmeasure.org'
resource.onsetAge.code = 'a'
Expand Down Expand Up @@ -1079,6 +1094,11 @@ def self.apply_invariants!(resource)
resource.targetReference = textonly_reference('ValueSet', FHIR::STU3)
end
when FHIR::STU3::Condition
# con-3
if resource.verificationStatus != 'entered-in-error'
resource.clinicalStatus = ['active', 'recurrence', 'inactive', 'remission', 'resolved'].sample
end

if resource.onsetAge
resource.onsetAge.system = 'http://unitsofmeasure.org'
resource.onsetAge.code = 'a'
Expand Down
16 changes: 12 additions & 4 deletions lib/tests/suites/transaction_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ def teardown
@condition0 = ResourceGenerator.minimal_condition('http://snomed.info/sct','414915002',patient0_id)
@condition0.subject.reference = patient0_uri

ResourceGenerator.apply_invariants!(@condition0)

@client.begin_transaction
@client.add_transaction_request('POST',nil,@patient0).fullUrl = patient0_uri
@client.add_transaction_request('POST',nil,@obs0a).fullUrl = "urn:uuid:#{SecureRandom.uuid}"
Expand Down Expand Up @@ -168,9 +170,14 @@ def teardown
@obs2 = ResourceGenerator.minimal_observation('http://loinc.org','3141-9',100,'kg',@patient0.id)
# obesity has been refuted
@condition0.subject.reference = "Patient/#{@patient0.id}"
@condition0.clinicalStatus = 'resolved'
@condition0.verificationStatus = 'refuted'
@condition0.abatementString = 'Abated at unknown date'
if fhir_version() == :r4
@condition0.clinicalStatus = ResourceGenerator.minimal_codeableconcept('http://terminology.hl7.org/CodeSystem/condition-clinical', 'resolved')
@condition0.verificationStatus = ResourceGenerator.minimal_codeableconcept('http://terminology.hl7.org/CodeSystem/condition-ver-status', 'refuted')
else
@condition0.clinicalStatus = 'resolved'
@condition0.verificationStatus = 'refuted'
end

@client.begin_transaction
@client.add_transaction_request('DELETE',"Observation/#{@obs0b.id}") if @obs0b && [email protected]? # delete first weight
Expand Down Expand Up @@ -258,8 +265,9 @@ def teardown
assert_bundle_response(reply)
assert_bundle_transactions_okay(reply)

count = (reply.resource.entry.first.resource.total rescue 0)
assert(count==1,"In a transaction, GET should execute last and in this case only return 1 result; found #{count}",reply.body)
total = reply.resource.entry.first.resource.total
total = reply&.resource&.entry&.first&.resource&.entry&.count if total.nil?
assert(total==1,"In a transaction, GET should execute last and in this case only return 1 result; found #{total}",reply.body)
searchResultId = (reply.resource.entry.first.resource.entry.first.resource.id rescue nil)
assert([email protected],"The GET search returned the wrong result. Expected Observation/#{@obs0a.id} but found Observation/#{searchResultId}.",reply.body)

Expand Down