Skip to content

Commit

Permalink
Modify CVD Risk for range-score and stale-delete (#5508)
Browse files Browse the repository at this point in the history
**Story card:**
[sc-14311](https://app.shortcut.com/simpledotorg/story/14311/modify-cvd-risk-for-range-score-and-stale-delete)

## Because

- We would need to give the risk scores as a range sometimes
- Risk scores may need to be deleted when they've gone _stale_

## This addresses

- The blocker building out the CVD sync resource on the Android side

## Test instructions

- suite tests
  • Loading branch information
igbanam authored Dec 10, 2024
1 parent a7b72ef commit 9f950eb
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/controllers/api/v4/cvd_risks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def cvd_risk_params
:id,
:patient_id,
:risk_score,
:deleted_at,
:created_at,
:updated_at
)
Expand Down
3 changes: 2 additions & 1 deletion app/schema/api/v4/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def cvd_risk
properties: {
id: {"$ref" => "#/definitions/uuid"},
patient_id: {"$ref" => "#/definitions/uuid"},
risk_score: {type: :number},
risk_score: {"$ref" => "#/definitions/non_empty_string"},
deleted_at: {"$ref" => "#/definitions/nullable_timestamp"},
created_at: {"$ref" => "#/definitions/timestamp"},
updated_at: {"$ref" => "#/definitions/timestamp"}
},
Expand Down
2 changes: 1 addition & 1 deletion app/validators/api/v4/cvd_risk_payload_validator.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Api::V4::CvdRiskPayloadValidator < Api::V4::PayloadValidator
attr_accessor :id, :patient_id, :risk_score, :created_at, :updated_at
attr_accessor :id, :patient_id, :risk_score, :deleted_at, :created_at, :updated_at

validate :validate_schema

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20241210092449_change_cvd_risk_score_to_string.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ChangeCvdRiskScoreToString < ActiveRecord::Migration[6.1]
def change
change_column(:cvd_risks, :risk_score, :string)
end
end
5 changes: 3 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ ALTER SEQUENCE public.cphc_migration_error_logs_id_seq OWNED BY public.cphc_migr

CREATE TABLE public.cvd_risks (
id uuid DEFAULT gen_random_uuid() NOT NULL,
risk_score integer,
risk_score character varying,
patient_id uuid NOT NULL,
deleted_at timestamp without time zone,
device_created_at timestamp without time zone,
Expand Down Expand Up @@ -7858,6 +7858,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20241125155649'),
('20241126111757'),
('20241129212725'),
('20241204155510');
('20241204155510'),
('20241210092449');


2 changes: 1 addition & 1 deletion spec/factories/cvd_risks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
factory :cvd_risk do
id { SecureRandom.uuid }
patient
risk_score { 42 }
risk_score { "42" }
device_created_at { Time.current }
device_updated_at { Time.current }

Expand Down
5 changes: 4 additions & 1 deletion swagger/v4/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,10 @@
"$ref": "#/definitions/uuid"
},
"risk_score": {
"type": "number"
"$ref": "#/definitions/non_empty_string"
},
"deleted_at": {
"$ref": "#/definitions/nullable_timestamp"
},
"created_at": {
"$ref": "#/definitions/timestamp"
Expand Down

0 comments on commit 9f950eb

Please sign in to comment.