-
Notifications
You must be signed in to change notification settings - Fork 4
#164 prescription module #179
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,70 @@ | ||
| class MedicationFormsController < ApplicationController | ||
| before_action :set_medication_form, only: %i[ show edit update destroy ] | ||
|
|
||
| # GET /medication_forms or /medication_forms.json | ||
| def index | ||
| @medication_forms = MedicationForm.all | ||
| end | ||
|
|
||
| # GET /medication_forms/1 or /medication_forms/1.json | ||
| def show | ||
| end | ||
|
|
||
| # GET /medication_forms/new | ||
| def new | ||
| @medication_form = MedicationForm.new | ||
| end | ||
|
|
||
| # GET /medication_forms/1/edit | ||
| def edit | ||
| end | ||
|
|
||
| # POST /medication_forms or /medication_forms.json | ||
| def create | ||
| @medication_form = MedicationForm.new(medication_form_params) | ||
|
|
||
| respond_to do |format| | ||
| if @medication_form.save | ||
| format.html { redirect_to @medication_form, notice: "Medication form was successfully created." } | ||
| format.json { render :show, status: :created, location: @medication_form } | ||
| else | ||
| format.html { render :new, status: :unprocessable_content } | ||
| format.json { render json: @medication_form.errors, status: :unprocessable_content } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # PATCH/PUT /medication_forms/1 or /medication_forms/1.json | ||
| def update | ||
| respond_to do |format| | ||
| if @medication_form.update(medication_form_params) | ||
| format.html { redirect_to @medication_form, notice: "Medication form was successfully updated.", status: :see_other } | ||
| format.json { render :show, status: :ok, location: @medication_form } | ||
| else | ||
| format.html { render :edit, status: :unprocessable_content } | ||
| format.json { render json: @medication_form.errors, status: :unprocessable_content } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # DELETE /medication_forms/1 or /medication_forms/1.json | ||
| def destroy | ||
| @medication_form.destroy! | ||
|
|
||
| respond_to do |format| | ||
| format.html { redirect_to medication_forms_path, notice: "Medication form was successfully destroyed.", status: :see_other } | ||
| format.json { head :no_content } | ||
| end | ||
| end | ||
|
|
||
| private | ||
| # Use callbacks to share common setup or constraints between actions. | ||
| def set_medication_form | ||
| @medication_form = MedicationForm.find(params.expect(:id)) | ||
| end | ||
|
|
||
| # Only allow a list of trusted parameters through. | ||
| def medication_form_params | ||
| params.expect(medication_form: [ :name ]) | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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,74 @@ | ||
| class PrescriptionsController < ApplicationController | ||
| before_action :set_prescription, only: %i[ show edit update destroy ] | ||
|
|
||
| # GET /prescriptions or /prescriptions.json | ||
| def index | ||
| # The index reads as a log: what is being taken now, newest first, with the | ||
| # stopped ones below it as history. includes avoids a medication and a form | ||
| # query per row. | ||
| @prescriptions = Prescription.includes(:medication, :medication_form) | ||
| .order(active: :desc, start_date: :desc, created_at: :desc) | ||
| end | ||
|
|
||
| # GET /prescriptions/1 or /prescriptions/1.json | ||
| def show | ||
| end | ||
|
|
||
| # GET /prescriptions/new | ||
| def new | ||
| @prescription = Prescription.new | ||
| end | ||
|
|
||
| # GET /prescriptions/1/edit | ||
| def edit | ||
| end | ||
|
|
||
| # POST /prescriptions or /prescriptions.json | ||
| def create | ||
| @prescription = Prescription.new(prescription_params) | ||
|
|
||
| respond_to do |format| | ||
| if @prescription.save | ||
| format.html { redirect_to @prescription, notice: "Prescription was successfully created." } | ||
| format.json { render :show, status: :created, location: @prescription } | ||
| else | ||
| format.html { render :new, status: :unprocessable_content } | ||
| format.json { render json: @prescription.errors, status: :unprocessable_content } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # PATCH/PUT /prescriptions/1 or /prescriptions/1.json | ||
| def update | ||
| respond_to do |format| | ||
| if @prescription.update(prescription_params) | ||
| format.html { redirect_to @prescription, notice: "Prescription was successfully updated.", status: :see_other } | ||
| format.json { render :show, status: :ok, location: @prescription } | ||
| else | ||
| format.html { render :edit, status: :unprocessable_content } | ||
| format.json { render json: @prescription.errors, status: :unprocessable_content } | ||
| end | ||
| end | ||
| end | ||
|
|
||
| # DELETE /prescriptions/1 or /prescriptions/1.json | ||
| def destroy | ||
| @prescription.destroy! | ||
|
|
||
| respond_to do |format| | ||
| format.html { redirect_to prescriptions_path, notice: "Prescription was successfully destroyed.", status: :see_other } | ||
| format.json { head :no_content } | ||
| end | ||
| end | ||
|
|
||
| private | ||
| # Use callbacks to share common setup or constraints between actions. | ||
| def set_prescription | ||
| @prescription = Prescription.find(params.expect(:id)) | ||
| end | ||
|
|
||
| # Only allow a list of trusted parameters through. | ||
| def prescription_params | ||
| params.expect(prescription: [ :medication_id, :medication_form_id, :dosage, :frequency, :time_of_day, :prescribing_doctor, :purpose, :active, :start_date, :stop_date, :notes ]) | ||
| end | ||
| end |
This file contains hidden or 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 hidden or 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,38 @@ | ||
| module PrescriptionsHelper | ||
| # Two lines in one column rather than two columns. Most prescriptions have a | ||
| # start and no stop, so a Stopped column would be a mostly empty stripe down | ||
| # the log. | ||
| def prescription_started(prescription) | ||
| prescription_date(prescription.start_date) || "—" | ||
| end | ||
|
|
||
| # What has happened since it started. Every combination of active and | ||
| # stop_date says something, and all four say it out loud: a blank line under | ||
| # a Stopped badge is indistinguishable from a column that failed to render. | ||
| def prescription_stopped(prescription) | ||
| stopped = prescription_date(prescription.stop_date) | ||
|
|
||
| if prescription.active? | ||
| stopped ? "until #{stopped}" : "ongoing" | ||
| else | ||
| stopped ? "stopped #{stopped}" : "no stop date recorded" | ||
| end | ||
| end | ||
|
|
||
| # The word carries the meaning; the colour only agrees with it. A boolean | ||
| # printed raw ("true") is the one thing a caregiver scanning this cannot read | ||
| # at a glance. | ||
| def prescription_status(prescription) | ||
| if prescription.active? | ||
| tag.span "Active", class: "status status--active" | ||
| else | ||
| tag.span "Stopped", class: "status status--stopped" | ||
| end | ||
| end | ||
|
|
||
| # "Aug 1, 2026". Short enough to keep a log column narrow, spelled enough to | ||
| # sidestep the 8/1 vs 1/8 question. | ||
| def prescription_date(date) | ||
| date&.strftime("%b %-d, %Y") | ||
| end | ||
| end | ||
This file contains hidden or 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,7 @@ | ||
| class Medication < ApplicationRecord | ||
| belongs_to :medication_type | ||
| belongs_to :medication_type, optional: true | ||
|
|
||
| has_many :prescriptions, dependent: :restrict_with_error | ||
|
|
||
| validates :name, presence: true | ||
| end |
This file contains hidden or 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,5 @@ | ||
| class MedicationForm < ApplicationRecord | ||
| has_many :prescriptions, dependent: :nullify | ||
|
|
||
| validates :name, presence: true | ||
| end |
This file contains hidden or 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,2 +1,5 @@ | ||
| class MedicationType < ApplicationRecord | ||
| has_many :medications, dependent: :nullify | ||
|
|
||
| validates :name, presence: true | ||
| end |
This file contains hidden or 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,4 @@ | ||
| class Prescription < ApplicationRecord | ||
| belongs_to :medication | ||
| belongs_to :medication_form, optional: true | ||
| end |
Oops, something went wrong.
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.
From Claude "summary": "prescription_stopped returns nil for an inactive prescription with no stop_date, leaving a blank sub-note alongside a 'Stopped' badge — indistinguishable from a data gap.",
I was wondering if this could be a problem since stop_date is optional?