Skip to content

Commit d9fb1bd

Browse files
authored
Default smoking to "unknown" (#5501)
**Story card:** [sc-14262](https://app.shortcut.com/simpledotorg/story/14262/update-smoking-to-default-to-unknown) ## Because `smoking` should act like other questions in `medical_histories` ## This addresses Ensuring `smoking` presents as "unknown" to clients when it's not set in the server ## Test instructions - introduced a new test for the scenario
1 parent d3db929 commit d9fb1bd

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

app/schema/api/v3/models.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ def medical_history
307307
diabetes: {type: :string, enum: MedicalHistory::MEDICAL_HISTORY_ANSWERS.keys},
308308
hypertension: {type: :string, enum: MedicalHistory::MEDICAL_HISTORY_ANSWERS.keys},
309309
diagnosed_with_hypertension: {type: :string, enum: MedicalHistory::MEDICAL_HISTORY_ANSWERS.keys},
310+
smoking: {type: :string, enum: MedicalHistory::MEDICAL_HISTORY_ANSWERS.keys},
310311
deleted_at: {"$ref" => "#/definitions/nullable_timestamp"},
311312
created_at: {"$ref" => "#/definitions/timestamp"},
312313
updated_at: {"$ref" => "#/definitions/timestamp"}

app/transformers/api/v3/medical_history_transformer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ def to_response(medical_history)
55
.to_response(medical_history)
66
.except("user_id")
77
.except(*MedicalHistory::MEDICAL_HISTORY_QUESTIONS.map { |question| "#{question}_boolean" })
8+
.tap { |params| params["smoking"] ||= "unknown" }
89
end
910

1011
def from_request(medical_history_payload)

spec/controllers/api/v3/medical_histories_controller_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ def create_record_list(n, options = {})
6767
expect(response_2_records.map(&:patient).to_set).to eq Set[patient_in_request_facility, patient_in_same_group]
6868
end
6969
end
70+
71+
context "non-nullable smoking" do
72+
let(:patient_in_request_facility) { build(:patient, registration_facility: request_facility) }
73+
it "defaults smoking to 'unknown'" do
74+
create(:medical_history, :without_smoking, patient: patient_in_request_facility)
75+
set_authentication_headers
76+
get :sync_to_user
77+
response_body = JSON(response.body)
78+
expect(response_body["medical_histories"][0]["smoking"]).not_to be nil
79+
expect(response_body["medical_histories"][0]["smoking"]).to eq "unknown"
80+
end
81+
end
7082
end
7183

7284
describe "#sync_from_user" do

spec/factories/medical_histories.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
hypertension { "yes" }
6565
chronic_kidney_disease { "yes" }
6666
end
67+
68+
trait :without_smoking do
69+
smoking { nil }
70+
end
6771
end
6872
end
6973

0 commit comments

Comments
 (0)