-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add migration for protocols and protocol drugs. * Refactor validations, remove from application record. * Add Protocol, and Protocol Drug scaffolding. * Remove comments from generated controllers. * Move protocols and protocol drugs into the admin namespace. * Remove json from controllers * Add model and controller tests for protocols and protocol drugs. * Add rake task to seed punjab's protocol. * Add sync logic for protocols * Add API specification for protocols. Co-authored-by: Govind Krishna Joshi <govind@nilenso.com>
- Loading branch information
1 parent
fbdebd0
commit 10b1ff9
Showing
36 changed files
with
1,003 additions
and
9 deletions.
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.