-
Notifications
You must be signed in to change notification settings - Fork 39
Deploy merge #5790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Deploy merge #5790
Changes from all commits
9ceb635
c449801
815d52b
19c7acf
b1608f8
4d43f01
99338d3
cac5c00
4db92a2
634e538
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| class Api::V4::PatientScoresController < Api::V4::SyncController | ||
| def sync_to_user | ||
| __sync_to_user__("patient_scores") | ||
| end | ||
|
|
||
| def current_facility_records | ||
| @current_facility_records ||= | ||
| PatientScore | ||
| .for_sync | ||
| .where(patient: current_facility.prioritized_patients.select(:id)) | ||
| .updated_on_server_since(current_facility_processed_since, limit) | ||
| end | ||
|
|
||
| def other_facility_records | ||
| other_facilities_limit = limit - current_facility_records.size | ||
| @other_facility_records ||= | ||
| PatientScore | ||
| .for_sync | ||
| .where(patient_id: current_sync_region | ||
| .syncable_patients | ||
| .where.not(registration_facility: current_facility) | ||
| .select(:id)) | ||
| .updated_on_server_since(other_facilities_processed_since, other_facilities_limit) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def transform_to_response(patient_score) | ||
| Api::V4::PatientScoreTransformer.to_response(patient_score) | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| class PatientScore < ApplicationRecord | ||
| include Mergeable | ||
| include Discard::Model | ||
|
|
||
| belongs_to :patient, optional: true | ||
|
|
||
| validates :device_created_at, presence: true | ||
| validates :device_updated_at, presence: true | ||
| validates :score_type, presence: true | ||
| validates :score_value, presence: true, numericality: true | ||
|
|
||
| scope :for_sync, -> { with_discarded } | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| class Api::V4::PatientScoreTransformer < Api::V4::Transformer | ||
| class << self | ||
| def to_response(payload) | ||
| current_time = Time.current.iso8601 | ||
| super(payload) | ||
| .merge({ | ||
| "score_type" => payload["score_type"], | ||
| "score_value" => payload["score_value"].to_f, | ||
| "created_at" => current_time, | ||
| "updated_at" => current_time | ||
| }) | ||
| end | ||
|
|
||
| def from_request(payload) | ||
| super(payload) | ||
| .merge({ | ||
| "score_type" => payload["score_type"], | ||
| "score_value" => payload["score_value"].to_f | ||
| }) | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,10 @@ | |
| get "sync", to: "cvd_risks#sync_to_user" | ||
| post "sync", to: "cvd_risks#sync_from_user" | ||
| end | ||
|
|
||
| scope :patient_scores do | ||
| get "sync", to: "patient_scores#sync_to_user" | ||
| end | ||
|
Comment on lines
+75
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need a sync route for this? |
||
| end | ||
|
|
||
| namespace :webview do | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| class CreatePatientScores < ActiveRecord::Migration[6.1] | ||
| def change | ||
| unless table_exists?(:patient_scores) | ||
| create_table :patient_scores, id: :uuid do |t| | ||
| t.references :patient, null: false, foreign_key: true, type: :uuid | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| t.string :score_type, null: false, limit: 100 | ||
| t.decimal :score_value, precision: 5, scale: 2, null: false | ||
| t.datetime :device_created_at, null: false | ||
| t.datetime :device_updated_at, null: false | ||
| t.datetime :deleted_at | ||
|
|
||
| t.timestamps | ||
| end | ||
| end | ||
|
|
||
| unless index_exists?(:patient_scores, [:patient_id, :score_type]) | ||
| add_index :patient_scores, [:patient_id, :score_type] | ||
| end | ||
|
|
||
| unless index_exists?(:patient_scores, :updated_at) | ||
| add_index :patient_scores, :updated_at | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| require "rails_helper" | ||
|
|
||
| describe Api::V4::PatientScoresController, type: :controller do | ||
| let(:request_user) { create(:user) } | ||
| let(:request_facility_group) { request_user.facility.facility_group } | ||
| let(:request_facility) { create(:facility, facility_group: request_facility_group) } | ||
| let(:model) { PatientScore } | ||
|
|
||
| def create_record(options = {}) | ||
| facility = create(:facility, facility_group: request_facility_group) | ||
| patient = create(:patient, registration_facility: facility) | ||
| create(:patient_score, options.merge(patient: patient)) | ||
| end | ||
|
|
||
| def create_record_list(n, options = {}) | ||
| facility = create(:facility, facility_group_id: request_facility_group.id) | ||
| patient = create(:patient, registration_facility_id: facility.id) | ||
| create_list(:patient_score, n, options.merge(patient: patient)) | ||
| end | ||
|
|
||
| it_behaves_like "a sync controller that authenticates user requests: sync_to_user" | ||
| it_behaves_like "a sync controller that audits the data access: sync_to_user" | ||
|
|
||
| describe "GET sync: send data from server to device;" do | ||
| it_behaves_like "a working V3 sync controller sending records" | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| FactoryBot.define do | ||
| factory :patient_score do | ||
| id { SecureRandom.uuid } | ||
| patient | ||
| score_type { "risk_score" } | ||
| score_value { 75.50 } | ||
| device_created_at { Time.current } | ||
| device_updated_at { Time.current } | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need #5789 if we have this here as well?