Skip to content

Commit

Permalink
Update appoinment height and weight with patient information (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanVqz authored Feb 27, 2024
1 parent 5d1176a commit 7e8f591
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/controllers/appoinments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def show
end

def new
@appoinment = Appoinment.new(patient_id: patient_id_param)
patient = patient_from_params
@appoinment = patient.appoinments.build(height: patient.height, weight: patient.weight)
end

def edit
Expand Down Expand Up @@ -63,8 +64,9 @@ def set_appoinment
@appoinment = Appoinment.includes(:patient).find(params[:id])
end

def patient_id_param
current_hospital.patients.find_by(id: params[:patient_id])&.to_param
def patient_from_params
current_hospital.patients.find_by(id: params[:patient_id]) ||
current_hospital.patients.new(height: 0.0, weight: 0.0)
end

def appoinment_params
Expand Down
3 changes: 3 additions & 0 deletions app/frontend/javascripts/controllers/imc_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default class extends Controller {
static targets = ['height', 'weight', 'result']
static values = { meter: { type: Number, default: 100 } }

connect() {
this.calculate()
}

calculate() {
if (!this.validHeightAndWeight()) {
Expand Down

0 comments on commit 7e8f591

Please sign in to comment.