Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/controllers/api/v1/event_procedures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def index

render json: {
total: total_amount_cents.total,
total_payd: total_amount_cents.payd,
total_unpayd: total_amount_cents.unpaid,
total_paid: total_amount_cents.paid,
total_unpaid: total_amount_cents.unpaid,
event_procedures: serialized_event_procedures(event_procedures)
}, status: :ok
end
Expand Down Expand Up @@ -69,7 +69,7 @@ def event_procedure_permitted_params
:date,
:urgency,
:amount_cents,
:payd,
:paid,
:room_type,
:payment,
patient_attributes: %i[
Expand All @@ -90,7 +90,7 @@ def event_procedure_permitted_query_params
:per_page,
:month,
:year,
:payd,
:paid,
hospital: [:name],
health_insurance: [:name]
).to_h
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/api/v1/medical_shifts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def index
authorized_scope = policy_scope(MedicalShift)
medical_shifts = MedicalShifts::List.result(
scope: authorized_scope,
params: params.permit(:page, :per_page, :month, :year, :payd, :hospital_name).to_h
params: params.permit(:page, :per_page, :month, :year, :paid, :hospital_name).to_h
).medical_shifts

amount_cents = MedicalShifts::TotalAmountCents.call(medical_shifts: medical_shifts)

render json: {
total: amount_cents.total,
total_payd: amount_cents.payd,
total_paid: amount_cents.paid,
total_unpaid: amount_cents.unpaid,
medical_shifts: serialized_medical_shifts(medical_shifts)
}, status: :ok
Expand Down Expand Up @@ -84,7 +84,7 @@ def medical_shift
end

def medical_shift_params
params.permit(:hospital_name, :workload, :start_date, :start_hour, :amount_cents, :payd).to_h
params.permit(:hospital_name, :workload, :start_date, :start_hour, :amount_cents, :paid).to_h
end

def serialized_medical_shifts(medical_shifts)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/pdf_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def permitted_query_params
:per_page,
:month,
:year,
:payd,
:paid,
:entity_name,
:disposition,
hospital: [:name],
Expand Down
8 changes: 4 additions & 4 deletions app/dashboards/event_procedure_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class EventProcedureDashboard < Administrate::BaseDashboard
hospital: Field::BelongsTo,
patient: Field::BelongsTo,
patient_service_number: Field::String,
payd: Field::Boolean,
paid: Field::Boolean,
procedure: Field::BelongsTo,
room_type: Field::String,
total_amount_cents: Field::Number,
Expand All @@ -36,7 +36,7 @@ class EventProcedureDashboard < Administrate::BaseDashboard
procedure
user
date
payd
paid
total_amount_cents
].freeze

Expand All @@ -49,7 +49,7 @@ class EventProcedureDashboard < Administrate::BaseDashboard
hospital
patient
patient_service_number
payd
paid
procedure
room_type
total_amount_cents
Expand All @@ -68,7 +68,7 @@ class EventProcedureDashboard < Administrate::BaseDashboard
hospital
patient
patient_service_number
payd
paid
procedure
room_type
total_amount_cents
Expand Down
6 changes: 3 additions & 3 deletions app/dashboards/medical_shift_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MedicalShiftDashboard < Administrate::BaseDashboard
start_hour: Field::Time,
hospital_name: Field::String,
user: Field::BelongsTo,
payd: Field::Boolean,
paid: Field::Boolean,
shift: Field::String,
title: Field::String,
workload: Field::String,
Expand Down Expand Up @@ -47,7 +47,7 @@ class MedicalShiftDashboard < Administrate::BaseDashboard
start_hour
hospital_name
user
payd
paid
shift
workload
title
Expand All @@ -64,7 +64,7 @@ class MedicalShiftDashboard < Administrate::BaseDashboard
start_hour
hospital_name
user
payd
paid
workload
].freeze

Expand Down
2 changes: 1 addition & 1 deletion app/models/event_procedure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class EventProcedure < ApplicationRecord
accepts_nested_attributes_for :health_insurance

scope :by_month, EventProcedures::ByMonthQuery
scope :by_payd, EventProcedures::ByPaydQuery
scope :by_paid, EventProcedures::ByPaidQuery
scope :by_year, EventProcedures::ByYearQuery
scope :date_between, EventProcedures::ByDateBetween
scope :by_hospital_name, EventProcedures::ByHospitalNameQuery
Expand Down
2 changes: 1 addition & 1 deletion app/models/medical_shift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MedicalShift < ApplicationRecord
scope :by_hospital, MedicalShifts::ByHospitalQuery
scope :by_month, MedicalShifts::ByMonthQuery
scope :by_year, MedicalShifts::ByYearQuery
scope :by_payd, MedicalShifts::ByPaydQuery
scope :by_paid, MedicalShifts::ByPaidQuery

validates :workload, presence: true
validates :start_date, presence: true
Expand Down
6 changes: 3 additions & 3 deletions app/operations/event_procedures/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def apply_all_filters(query)
query = apply_year_filter(query)
query = apply_hospital_filter(query)
query = apply_health_insurance_filter(query)
apply_payd_filter(query)
apply_paid_filter(query)
end

def apply_month_filter(query)
Expand All @@ -36,8 +36,8 @@ def apply_year_filter(query)
params[:year].present? ? query.by_year(year: params[:year]) : query
end

def apply_payd_filter(query)
%w[true false].include?(params[:payd]) ? query.by_payd(payd: params[:payd]) : query
def apply_paid_filter(query)
%w[true false].include?(params[:paid]) ? query.by_paid(paid: params[:paid]) : query
end

def apply_hospital_filter(query)
Expand Down
6 changes: 3 additions & 3 deletions app/operations/event_procedures/total_amount_cents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class TotalAmountCents < Actor
input :event_procedures

output :total, type: String
output :payd, type: String
output :paid, type: String
output :unpaid, type: String

def call
self.total = calculate_amount(event_procedures)
self.payd = calculate_amount(event_procedures.select(&:payd))
self.unpaid = calculate_amount(event_procedures.reject(&:payd))
self.paid = calculate_amount(event_procedures.select(&:paid))
self.unpaid = calculate_amount(event_procedures.reject(&:paid))
end

def convert_money(amount_cents)
Expand Down
6 changes: 3 additions & 3 deletions app/operations/medical_shifts/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def filtered_query
query = apply_month_filter(query)
query = apply_year_filter(query)
query = apply_hospital_filter(query)
apply_payd_filter(query)
apply_paid_filter(query)
end

def apply_month_filter(query)
Expand All @@ -33,8 +33,8 @@ def apply_hospital_filter(query)
params[:hospital_name].present? ? query.by_hospital(hospital_name: params[:hospital_name]) : query
end

def apply_payd_filter(query)
%w[true false].include?(params[:payd]) ? query.by_payd(payd: params[:payd]) : query
def apply_paid_filter(query)
%w[true false].include?(params[:paid]) ? query.by_paid(paid: params[:paid]) : query
end
end
end
6 changes: 3 additions & 3 deletions app/operations/medical_shifts/total_amount_cents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class TotalAmountCents < Actor
input :medical_shifts

output :total, type: String
output :payd, type: String
output :paid, type: String
output :unpaid, type: String

def call
self.total = Money.new(medical_shifts.sum(&:amount_cents), "BRL").format
self.payd = Money.new(medical_shifts.select(&:payd).sum(&:amount_cents), "BRL").format
self.unpaid = Money.new(medical_shifts.reject(&:payd).sum(&:amount_cents), "BRL").format
self.paid = Money.new(medical_shifts.select(&:paid).sum(&:amount_cents), "BRL").format
self.unpaid = Money.new(medical_shifts.reject(&:paid).sum(&:amount_cents), "BRL").format
end
end
end
2 changes: 1 addition & 1 deletion app/pdfs/event_procedures_report_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def truncate_text(text, length = 85)
end

def item_paid?(item)
item.payd ? "Pago" : "A Receber"
item.paid ? "Pago" : "A Receber"
end

def item_date(item)
Expand Down
2 changes: 1 addition & 1 deletion app/pdfs/footer_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def generate
pdf.move_down @footer_spacing

pdf.text_box "Recebidos", at: [0, pdf.cursor], size: @footer_font_size, align: :left, overflow: :shrink_to_fit
pdf.text_box amount.payd, at: [pdf.bounds.width - @right_text_offset, pdf.cursor], size: @footer_font_size,
pdf.text_box amount.paid, at: [pdf.bounds.width - @right_text_offset, pdf.cursor], size: @footer_font_size,
align: :right, overflow: :shrink_to_fit
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/pdfs/medical_shifts_report_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ def item_start_hour(item)
end

def item_paid?(item)
item.payd ? "Pago" : "A Receber"
item.paid ? "Pago" : "A Receber"
end
end
16 changes: 16 additions & 0 deletions app/queries/event_procedures/by_paid_query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module EventProcedures
class ByPaidQuery < ApplicationQuery
attr_reader :paid, :relation

def initialize(paid:, relation: EventProcedure)
@paid = paid
@relation = relation
end

def call
paid == "true" ? relation.where(paid: true) : relation.where(paid: false)
end
end
end
16 changes: 0 additions & 16 deletions app/queries/event_procedures/by_payd_query.rb

This file was deleted.

16 changes: 16 additions & 0 deletions app/queries/medical_shifts/by_paid_query.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module MedicalShifts
class ByPaidQuery < ApplicationQuery
attr_reader :paid, :relation

def initialize(paid:, relation: MedicalShift)
@paid = paid
@relation = relation
end

def call
paid == "true" ? relation.where(paid: true) : relation.where(paid: false)
end
end
end
16 changes: 0 additions & 16 deletions app/queries/medical_shifts/by_payd_query.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/serializers/event_procedure_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class EventProcedureSerializer < ActiveModel::Serializer
attributes :id, :cbhpm_id, :procedure, :patient, :hospital, :health_insurance, :patient_service_number, :date,
:room_type, :payment, :urgency, :payd, :total_amount_cents, :precedure_value, :precedure_description
:room_type, :payment, :urgency, :paid, :total_amount_cents, :precedure_value, :precedure_description

def total_amount_cents
object.total_amount.format
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/medical_shift_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class MedicalShiftSerializer < ActiveModel::Serializer
attributes :id, :hospital_name, :workload, :date, :hour, :amount_cents, :payd, :shift, :title
attributes :id, :hospital_name, :workload, :date, :hour, :amount_cents, :paid, :shift, :title

def date
object.start_date.strftime("%d/%m/%Y")
Expand Down
24 changes: 24 additions & 0 deletions db/migrate/20250410123456_correct_payd_to_paid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

class CorrectPaydToPaid < ActiveRecord::Migration[7.1]
def up
rename_column :event_procedures, :payd, :paid

rename_column :medical_shifts, :payd, :paid

return unless index_exists?(:medical_shifts, :paid, name: "index_medical_shifts_on_payd")

remove_index :medical_shifts, name: "index_medical_shifts_on_payd"
add_index :medical_shifts, :paid, name: "index_medical_shifts_on_paid"
end

def down
if index_exists?(:medical_shifts, :paid, name: "index_medical_shifts_on_paid")
remove_index :medical_shifts, name: "index_medical_shifts_on_paid"
add_index :medical_shifts, :payd, name: "index_medical_shifts_on_payd"
end

rename_column :medical_shifts, :paid, :payd
rename_column :event_procedures, :paid, :payd
end
end
8 changes: 4 additions & 4 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading