Skip to content

Commit a1d43df

Browse files
authored
feat: Add smokeless_tobacco to medical_histories (#5651)
**Story card:** [sc-16397](https://app.shortcut.com/simpledotorg/story/16397/add-a-field-in-the-db-for-smokeless-tobacco) ## Because The program team wants to track this. ## This addresses - adding this to the DB - exposing it via the API ## Test instructions suite tests
1 parent f764b52 commit a1d43df

File tree

11 files changed

+52
-5
lines changed

11 files changed

+52
-5
lines changed

app/controllers/api/v3/medical_histories_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def medical_histories_params
4646
:hypertension,
4747
:diagnosed_with_hypertension,
4848
:smoking,
49+
:smokeless_tobacco,
4950
:cholesterol,
5051
:created_at,
5152
:updated_at

app/models/medical_history.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ class MedicalHistory < ApplicationRecord
1414
:receiving_treatment_for_diabetes,
1515
:diabetes,
1616
:diagnosed_with_hypertension,
17-
:smoking
17+
:smoking,
18+
:smokeless_tobacco
1819
].freeze
1920

2021
MEDICAL_HISTORY_ANSWERS = {
@@ -32,6 +33,7 @@ class MedicalHistory < ApplicationRecord
3233
enum hypertension: MEDICAL_HISTORY_ANSWERS, _prefix: true
3334
enum diagnosed_with_hypertension: MEDICAL_HISTORY_ANSWERS, _prefix: true
3435
enum smoking: MEDICAL_HISTORY_ANSWERS, _prefix: true
36+
enum smokeless_tobacco: MEDICAL_HISTORY_ANSWERS, _prefix: true
3537

3638
scope :for_sync, -> { with_discarded }
3739

app/schema/api/v3/models.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ def medical_history
308308
hypertension: {type: :string, enum: MedicalHistory::MEDICAL_HISTORY_ANSWERS.keys},
309309
diagnosed_with_hypertension: {type: :string, enum: MedicalHistory::MEDICAL_HISTORY_ANSWERS.keys},
310310
smoking: {type: :string, enum: MedicalHistory::MEDICAL_HISTORY_ANSWERS.keys},
311+
smokeless_tobacco: {type: :string, enum: MedicalHistory::MEDICAL_HISTORY_ANSWERS.keys},
311312
cholesterol_value: {type: :number},
312313
deleted_at: {"$ref" => "#/definitions/nullable_timestamp"},
313314
created_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
@@ -6,6 +6,7 @@ def to_response(medical_history)
66
.except("user_id")
77
.except(*MedicalHistory::MEDICAL_HISTORY_QUESTIONS.map { |question| "#{question}_boolean" })
88
.tap { |params| params["smoking"] ||= "unknown" }
9+
.tap { |params| params["smokeless_tobacco"] ||= "unknown" }
910
end
1011

1112
def from_request(medical_history_payload)

app/validators/api/v3/medical_history_payload_validator.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Api::V3::MedicalHistoryPayloadValidator < Api::V3::PayloadValidator
1111
:hypertension,
1212
:diagnosed_with_hypertension,
1313
:smoking,
14+
:smokeless_tobacco,
1415
:cholesterol,
1516
:created_at,
1617
:updated_at
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddSmokelessTobaccoToMedicalHistories < ActiveRecord::Migration[6.1]
2+
def change
3+
add_column :medical_histories, :smokeless_tobacco, :string
4+
end
5+
end

db/structure.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,8 @@ CREATE TABLE public.medical_histories (
641641
hypertension text,
642642
receiving_treatment_for_diabetes text,
643643
smoking text,
644-
cholesterol integer
644+
cholesterol integer,
645+
smokeless_tobacco character varying
645646
);
646647

647648

@@ -8663,6 +8664,7 @@ INSERT INTO "schema_migrations" (version) VALUES
86638664
('20250619152733'),
86648665
('20250619195214'),
86658666
('20250619222520'),
8666-
('20250619225935');
8667+
('20250619225935'),
8668+
('20250814092225');
86678669

86688670

spec/controllers/api/v3/medical_histories_controller_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ def create_record_list(n, options = {})
7979
expect(response_body["medical_histories"][0]["smoking"]).to eq "unknown"
8080
end
8181
end
82+
83+
context "non-nullable smokeless_tobacco" do
84+
let(:patient_in_request_facility) { build(:patient, registration_facility: request_facility) }
85+
it "defaults smoking to 'unknown'" do
86+
create(:medical_history, :without_smokeless_tobacco, patient: patient_in_request_facility)
87+
set_authentication_headers
88+
get :sync_to_user
89+
response_body = JSON(response.body)
90+
expect(response_body["medical_histories"][0]["smokeless_tobacco"]).not_to be nil
91+
expect(response_body["medical_histories"][0]["smokeless_tobacco"]).to eq "unknown"
92+
end
93+
end
8294
end
8395

8496
describe "#sync_from_user" do

spec/factories/medical_histories.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
hypertension { MedicalHistory::MEDICAL_HISTORY_ANSWERS[:no] }
1212
diagnosed_with_hypertension { MedicalHistory::MEDICAL_HISTORY_ANSWERS[:no] }
1313
smoking { MedicalHistory::MEDICAL_HISTORY_ANSWERS[:no] }
14+
smokeless_tobacco { MedicalHistory::MEDICAL_HISTORY_ANSWERS[:no] }
1415
cholesterol { 123 }
1516
device_created_at { Time.current }
1617
device_updated_at { Time.current }
@@ -26,6 +27,7 @@
2627
hypertension { MedicalHistory::MEDICAL_HISTORY_ANSWERS[:unknown] }
2728
diagnosed_with_hypertension { MedicalHistory::MEDICAL_HISTORY_ANSWERS[:unknown] }
2829
smoking { MedicalHistory::MEDICAL_HISTORY_ANSWERS[:unknown] }
30+
smokeless_tobacco { MedicalHistory::MEDICAL_HISTORY_ANSWERS[:unknown] }
2931
end
3032

3133
trait :hypertension_yes do
@@ -68,6 +70,10 @@
6870
trait :without_smoking do
6971
smoking { nil }
7072
end
73+
74+
trait :without_smokeless_tobacco do
75+
smokeless_tobacco { nil }
76+
end
7177
end
7278
end
7379

swagger/v3/swagger.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2485,6 +2485,14 @@
24852485
"unknown"
24862486
]
24872487
},
2488+
"smokeless_tobacco": {
2489+
"type": "string",
2490+
"enum": [
2491+
"yes",
2492+
"no",
2493+
"unknown"
2494+
]
2495+
},
24882496
"cholesterol_value": {
24892497
"type": "number"
24902498
},
@@ -2658,4 +2666,4 @@
26582666
"name": "X-PATIENT-ID"
26592667
}
26602668
}
2661-
}
2669+
}

0 commit comments

Comments
 (0)