-
Notifications
You must be signed in to change notification settings - Fork 35
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
Add Protocols, and Protocol Drugs #25
Changes from 10 commits
a58ec7d
6bd194f
b1bad19
82b1b4a
4a22f36
044b0ae
8808d17
de34f6d
5b4423b
4342c48
bd51c7f
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,84 @@ | ||
body { | ||
background-color: #fff; | ||
color: #333; | ||
margin: 33px; | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; | ||
} | ||
|
||
p, ol, ul, td { | ||
font-family: verdana, arial, helvetica, sans-serif; | ||
font-size: 13px; | ||
line-height: 18px; | ||
} | ||
|
||
pre { | ||
background-color: #eee; | ||
padding: 10px; | ||
font-size: 11px; | ||
} | ||
|
||
a { | ||
color: #000; | ||
|
||
&:visited { | ||
color: #666; | ||
} | ||
|
||
&:hover { | ||
color: #fff; | ||
background-color: #000; | ||
} | ||
} | ||
|
||
th { | ||
padding-bottom: 5px; | ||
} | ||
|
||
td { | ||
padding: 0 5px 7px; | ||
} | ||
|
||
div { | ||
&.field, &.actions { | ||
margin-bottom: 10px; | ||
} | ||
} | ||
|
||
#notice { | ||
color: green; | ||
} | ||
|
||
.field_with_errors { | ||
padding: 2px; | ||
background-color: red; | ||
display: table; | ||
} | ||
|
||
#error_explanation { | ||
width: 450px; | ||
border: 2px solid red; | ||
padding: 7px 7px 0; | ||
margin-bottom: 20px; | ||
background-color: #f0f0f0; | ||
|
||
h2 { | ||
text-align: left; | ||
font-weight: bold; | ||
padding: 5px 5px 5px 15px; | ||
font-size: 12px; | ||
margin: -7px -7px 0; | ||
background-color: #c00; | ||
color: #fff; | ||
} | ||
|
||
ul li { | ||
font-size: 12px; | ||
list-style: square; | ||
} | ||
} | ||
|
||
label { | ||
display: block; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class Api::V1::ProtocolsController < Api::V1::SyncController | ||
def sync_to_user | ||
__sync_to_user__('protocols') | ||
end | ||
|
||
private | ||
|
||
def find_records_to_sync(since, limit) | ||
Protocol.updated_on_server_since(since, limit).includes(:protocol_drugs) | ||
end | ||
|
||
def transform_to_response(protocol) | ||
protocol.as_json(include: :protocol_drugs) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
class ProtocolDrugsController < ApplicationController | ||
before_action :set_protocol_drug, only: %i[show edit update destroy] | ||
before_action :set_protocols, only: %i[create edit update new] | ||
|
||
def index | ||
@protocol_drugs = ProtocolDrug.all | ||
end | ||
|
||
def show | ||
end | ||
|
||
def new | ||
@protocol_drug = ProtocolDrug.new | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def create | ||
@protocol_drug = ProtocolDrug.new(protocol_drug_params) | ||
|
||
respond_to do |format| | ||
if @protocol_drug.save | ||
format.html { redirect_to :protocols, notice: 'Protocol drug was successfully created.' } | ||
format.json { render :show, status: :created, location: @protocol_drug } | ||
else | ||
format.html { render :new } | ||
format.json { render json: @protocol_drug.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def update | ||
respond_to do |format| | ||
if @protocol_drug.update(protocol_drug_params) | ||
format.html { redirect_to :protocols, notice: 'Protocol drug was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @protocol_drug } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @protocol_drug.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@protocol_drug.destroy | ||
respond_to do |format| | ||
format.html { redirect_to protocol_drugs_url, notice: 'Protocol drug was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_protocols | ||
@protocols = Protocol.all | ||
end | ||
|
||
def set_protocol_drug | ||
@protocol_drug = ProtocolDrug.find(params[:id]) | ||
end | ||
|
||
def protocol_drug_params | ||
params.require(:protocol_drug).permit(:name, :dosage, :rxnorm_code, :protocol_id) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
class ProtocolsController < ApplicationController | ||
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. These should live in an |
||
before_action :set_protocol, only: %i[show edit update destroy] | ||
|
||
def index | ||
@protocols = Protocol.all | ||
end | ||
|
||
def show | ||
end | ||
|
||
def new | ||
@protocol = Protocol.new | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def create | ||
@protocol = Protocol.new(protocol_params) | ||
|
||
respond_to do |format| | ||
if @protocol.save | ||
format.html { redirect_to @protocol, notice: 'Protocol was successfully created.' } | ||
format.json { render :show, status: :created, location: @protocol } | ||
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. I don't think we need JSON replies in the admin UI 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. Yeah, we'll remove these. |
||
else | ||
format.html { render :new } | ||
format.json { render json: @protocol.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def update | ||
respond_to do |format| | ||
if @protocol.update(protocol_params) | ||
format.html { redirect_to @protocol, notice: 'Protocol was successfully updated.' } | ||
format.json { render :show, status: :ok, location: @protocol } | ||
else | ||
format.html { render :edit } | ||
format.json { render json: @protocol.errors, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@protocol.destroy | ||
respond_to do |format| | ||
format.html { redirect_to protocols_url, notice: 'Protocol was successfully destroyed.' } | ||
format.json { head :no_content } | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_protocol | ||
@protocol = Protocol.find(params[:id]) | ||
end | ||
|
||
def protocol_params | ||
params.require(:protocol).permit(:name, :follow_up_days) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
class Address < ApplicationRecord | ||
include Mergeable | ||
|
||
validates :device_created_at, presence: true | ||
validates :device_updated_at, presence: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
class BloodPressure < ApplicationRecord | ||
include Mergeable | ||
belongs_to :patient, optional: true | ||
|
||
validates :device_created_at, presence: true | ||
validates :device_updated_at, presence: true | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Protocol < ApplicationRecord | ||
has_many :protocol_drugs | ||
before_create :assign_id | ||
|
||
validates :name, presence: true | ||
validates :follow_up_days, numericality: true, presence: true | ||
|
||
def assign_id | ||
self.id = SecureRandom.uuid | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class ProtocolDrug < ApplicationRecord | ||
belongs_to :protocol | ||
before_create :assign_id | ||
|
||
validates :name, presence: true | ||
validates :dosage, presence: true | ||
|
||
def assign_id | ||
self.id = SecureRandom.uuid | ||
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. We should discuss this. I think we should switch all of these records to create UUIDs as ID by default, or move UUID to a separate field and use bigint IDs. As it is, this is messy; I ran into the same issue with Facility. 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. Creating UUIDs by default in the database sounds like the way to go. We'll do this for all entities that are created via the admin interface. 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. We'll do this after the facilities PR is merged in, so that we don't conflict with your changes of adding pgcrypto or another extension. |
||
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.
These should live in an
Admin::
namespace