Skip to content

Commit

Permalink
Add measurement charts
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejb2k committed Nov 5, 2023
1 parent 843a86a commit 10559b7
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 98 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@import "pages/measurements";
@import "pages/measurement_raports";
@import "pages/measurements_by_day";
@import "pages/measurements_all";
@import "pages/measurement";
@import "pages/accounts";
@import "pages/account";
Expand Down
58 changes: 58 additions & 0 deletions app/assets/stylesheets/pages/_measurements_all.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.page-measurements-all {
&__content {
padding: 30px 0;
display: flex;
gap: 50px;
}

&__left,
&__right {
width: 50%;
}

.measurements-group {
&:not(:last-child) {
margin-bottom: 30px;
}

&__title {
font-size: var(--18px);
font-weight: 500;
color: $dash-text-dark;
margin-bottom: 20px;
display: flex;
align-items: center;
gap: 10px;

&__icon {
color: $dash-text-light;
}
}
}

.measurements-chart {
background: #ffffff;
border: 1px solid $dash-base-border;
border-radius: 3px;
padding: 20px 20px;

&:not(:last-child) {
margin-bottom: 30px;
}

&__title {
font-size: var(--18px);
font-weight: 500;
color: $dash-text-dark;
}

&__desc {
margin-bottom: 20px;
font-size: var(--14px);
color: $dash-text-light;
}

&__drawing {
}
}
}
159 changes: 80 additions & 79 deletions app/assets/stylesheets/pages/_measurements_by_day.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,99 +2,100 @@
&__content {
padding: 30px 0;
}
}

.measurements-list {
max-width: 500px;
display: flex;
flex-direction: column;
gap: 10px;
}
.measurements-list {
max-width: 500px;
display: flex;
flex-direction: column;
gap: 10px;
}

.measurement-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
background: #ffffff;
border: 1px solid $dash-base-border;
border-radius: 3px;
padding: 10px 10px;
.measurement-item {
display: flex;
align-items: center;
justify-content: space-between;
gap: 20px;
background: #ffffff;
border: 1px solid $dash-base-border;
border-radius: 3px;
padding: 5px 5px;

&--dangerous {
.measurement-item__value {
color: #f15a5a;
}
&--dangerous {
.measurement-item__value {
color: #f15a5a;
}
}

&__warning {
font-size: var(--12px);
text-align: center;
color: $dash-text-light;
padding: 3px 10px;
font-weight: 500;
color: #ffffff;
background: #f15a5a;
border-radius: 3px;
}
&__warning {
font-size: var(--12px);
text-align: center;
color: $dash-text-light;
padding: 3px 8px;
font-weight: 500;
color: #ffffff;
background: #f15a5a;
border-radius: 3px;
}

&__label {
font-size: var(--12px);
text-align: center;
color: $dash-text-light;
padding: 3px 20px;
font-weight: 500;
color: #1d5583;
background: #e9f5ff;
border-radius: 3px;
width: 130px;
}
&__label {
font-size: var(--12px);
text-align: center;
color: $dash-text-light;
padding: 5px 20px;
font-weight: 500;
color: #1d5583;
background: #e9f5ff;
border-radius: 3px;
width: 130px;
}

&__time {
font-size: var(--14px);
color: $dash-text-light;
}
&__time {
font-size: var(--14px);
font-family: monospace;
color: $dash-text-light;
}

&__value {
font-size: var(--14px);
font-weight: 500;
color: $dash-text-dark;
}
&__value {
font-size: var(--14px);
font-weight: 500;
color: $dash-text-dark;
}

&__left {
display: flex;
align-items: center;
gap: 10px;
}
&__left {
display: flex;
align-items: center;
gap: 10px;
}

&--weight {
.measurement-item__label {
color: #36831d;
background: #e5ffdd;
}
&--weight {
.measurement-item__label {
color: #36831d;
background: #e5ffdd;
}
&--blood_pressure {
.measurement-item__label {
color: #531d83;
background: #f4e7ff;
}
}
&--blood_pressure {
.measurement-item__label {
color: #531d83;
background: #f4e7ff;
}
&--heart_beat {
.measurement-item__label {
color: #831d1d;
background: #ffe9e9;
}
}
&--heart_beat {
.measurement-item__label {
color: #831d1d;
background: #ffe9e9;
}
&--sugar {
.measurement-item__label {
color: #685e11;
background: #fffad3;
}
}
&--sugar {
.measurement-item__label {
color: #685e11;
background: #fffad3;
}
&--spo2 {
.measurement-item__label {
color: #1d5583;
background: #e9f5ff;
}
}
&--spo2 {
.measurement-item__label {
color: #1d5583;
background: #e9f5ff;
}
}
}
2 changes: 1 addition & 1 deletion app/controllers/auth/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def create
sign_out(resource)
session[:otp_user_id] = resource.id

redirect_to user_two_factor_authentication_path
redirect_to users_sign_in_otp_path
else
set_flash_message!(:notice, :signed_in)
sign_in(resource_name, resource)
Expand Down
40 changes: 40 additions & 0 deletions app/controllers/measurements_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class MeasurementsController < BaseController
before_action :set_measurement, only: %i[show edit update destroy]
before_action :set_datetime, only: %i[details show_by_day generate_raport_by_day]
before_action :set_measurements, only: %i[all]
before_action :set_breadcrumbs

def index
Expand Down Expand Up @@ -48,6 +49,8 @@ def show_by_day
)
end

def all; end

def new
measurement_type = MeasurementType.find_by!(name: params[:measurement_type])
@measurement = Measurement.new(measurement_type:)
Expand Down Expand Up @@ -116,6 +119,37 @@ def set_datetime
redirect_to measurements_path
end

def set_measurements
measurement_type = MeasurementType.find_by!(name: params[:measurement_type])

common_query =
current_account
.measurements
.includes(measurement_type: :unit)
.joins(measurement_type: :unit)
.where(measurement_type:)

@measurements =
common_query
.order(measurement_date: :desc)
.group_by_week(week_start: :monday, reverse: true, &:measurement_date)

@count_chart =
common_query
.group_by_week(:measurement_date, reverse: true, week_start: :monday)
.count

@monthly_chart =
common_query
.where(measurement_date: 1.month.ago..Time.zone.now)
.order(:measurement_date)
.pluck(:measurement_date, :value)
.map { |date, value| [l(date, format: "%d %b"), value] }
rescue ActiveRecord::RecordNotFound
flash[:error] = t(".invalid_measurement_type")
redirect_to measurements_path
end

def parse_date(date)
Date.parse(date)
rescue TypeError, Date::Error
Expand All @@ -139,6 +173,12 @@ def set_breadcrumbs
t(".breadcrumbs.show_by_day", date: parse_date(params[:day])),
show_by_day_measurements_path(day: params[:day])
)
when :all
add_breadcrumb(
t(".breadcrumbs.all",
measurement_type: I18n.t("activerecord.attributes.measurement_types.#{params[:measurement_type]}")),
all_measurements_path(measurement_type: params[:measurement_type])
)
end
end

Expand Down
9 changes: 0 additions & 9 deletions app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@
<h3 class="dash-stat__title"><%= t(".measurements") %></h3>
</div>
</div>
<div class="dash-stat">
<div class="dash-stat__icon">
<i class="ri-test-tube-line"></i>
</div>
<div class="dash-stat__content">
<p class="dash-stat__text">0</p>
<h3 class="dash-stat__title"><%= t(".lab_results") %></h3>
</div>
</div>
<div class="dash-stat">
<div class="dash-stat__icon">
<i class="ri-sticky-note-line"></i>
Expand Down
2 changes: 1 addition & 1 deletion app/views/disease_symptom_updates/_chart.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= line_chart @disease_symptom_updates.group_by_day(:update_date).average(:intensity), min: 0, max: 5, curve: true %>
<%= line_chart @disease_symptom_updates.where(update_date: 1.week.ago..Time.zone.now).group_by_day(:update_date).average(:intensity), min: 0, max: 5, curve: true %>
Loading

0 comments on commit 10559b7

Please sign in to comment.