-
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
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a58ec7d
Add migration for protocols and protocol drugs.
ssrihari 6bd194f
Merge branch 'master' into protocols
ssrihari b1bad19
Refactor validations, remove from application record.
ssrihari 82b1b4a
Add Protocol scaffolding.
ssrihari 4a22f36
Add scaffold for protocol drug.
ssrihari 044b0ae
Remove comments from generated controllers.
ssrihari 8808d17
Add model and controller tests for protocols and protocol drugs.
ssrihari de34f6d
Add rake task to seed punjab's protocol.
ssrihari 5b4423b
Add sync logic for protocols
ssrihari 4342c48
Add API specification for protocols.
ssrihari bd51c7f
Move protocols and protocol drugs into the admin namespace.
ssrihari File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
class Admin::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) | ||
if @protocol_drug.save | ||
redirect_to [:admin, :protocols], notice: 'Protocol drug was successfully created.' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
if @protocol_drug.update(protocol_drug_params) | ||
redirect_to [:admin, :protocols], notice: 'Protocol drug was successfully updated.' | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@protocol_drug.destroy | ||
redirect_to [:admin, :protocols], notice: 'Protocol drug was successfully destroyed.' | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
class Admin::ProtocolsController < ApplicationController | ||
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) | ||
if @protocol.save | ||
redirect_to [:admin, @protocol], notice: 'Protocol was successfully created.' | ||
else | ||
render :new | ||
end | ||
end | ||
|
||
def update | ||
if @protocol.update(protocol_params) | ||
redirect_to [:admin, @protocol], notice: 'Protocol was successfully updated.' | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@protocol.destroy | ||
redirect_to admin_protocols_url, notice: 'Protocol was successfully destroyed.' | ||
end | ||
|
||
private | ||
|
||
def set_protocol | ||
@protocol = Protocol.find(params[:id]) | ||
end | ||
|
||
def protocol_params | ||
params.require(:protocol).permit(:name, :follow_up_days) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<%= form_with(model: [:admin, protocol_drug], local: true) do |form| %> | ||
<% if protocol_drug.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(protocol_drug.errors.count, "error") %> prohibited this protocol_drug from being saved:</h2> | ||
|
||
<ul> | ||
<% protocol_drug.errors.full_messages.each do |message| %> | ||
<li><%= message %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= form.label :name %> | ||
<%= form.text_field :name, id: :protocol_drug_name %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :dosage %> | ||
<%= form.text_field :dosage, id: :protocol_drug_dosage %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :rxnorm_code %> | ||
<%= form.text_field :rxnorm_code, id: :protocol_drug_rxnorm_code %> | ||
</div> | ||
|
||
<div class="field"> | ||
<%= form.label :protocol_id %> | ||
<%= form.select 'protocol_id', options_from_collection_for_select(@protocols, "id", "name") %> | ||
</div> | ||
|
||
<div class="actions"> | ||
<%= form.submit %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Editing Protocol Drug</h1> | ||
|
||
<%= render 'form', protocol_drug: @protocol_drug %> | ||
|
||
<%= link_to 'Show', [:admin, @protocol_drug] %> | | ||
<%= link_to 'Back', admin_protocol_drugs_path %> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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 comment
The 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.