diff options
| author | mo khan <mo.khan@gmail.com> | 2020-03-28 15:08:36 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-03-28 15:08:36 -0600 |
| commit | d4f7bc4fcc5c2bdf2e7c07141109e6b330fa3242 (patch) | |
| tree | 9376855ea48dd1a6e196d8f4b2032e6f24e1bf38 /rvh | |
| parent | 5eb83f62ff2649e0c2b16c1217cd4eb698198a2e (diff) | |
Answer final question of module 2
Diffstat (limited to 'rvh')
| -rw-r--r-- | rvh/app/models/physician.rb | 2 | ||||
| -rw-r--r-- | rvh/app/models/staff.rb | 16 | ||||
| -rw-r--r-- | rvh/app/models/treatment.rb | 2 | ||||
| -rw-r--r-- | rvh/erd.dot | 14 |
4 files changed, 25 insertions, 9 deletions
diff --git a/rvh/app/models/physician.rb b/rvh/app/models/physician.rb index 58c7fdb..85d6605 100644 --- a/rvh/app/models/physician.rb +++ b/rvh/app/models/physician.rb @@ -1,2 +1,4 @@ class Physician < Staff + has_many :patients + has_many :treatmeants, through: :patients end diff --git a/rvh/app/models/staff.rb b/rvh/app/models/staff.rb index 8ac92cd..b462431 100644 --- a/rvh/app/models/staff.rb +++ b/rvh/app/models/staff.rb @@ -8,3 +8,19 @@ class Staff < ApplicationRecord delegate :phone_number, to: :account delegate :pager_number, to: :account end + +=begin + +Find which physicians performed a treatment each day. + +treatment | day(treatment.occurred_at) | staff.name | count(treatment_id) + +SELECT treatments.id, date(treatments.occurred_at), staff.id, count(treatments.id) +FROM "treatments" +INNER JOIN "patients" ON "patients"."id" = "treatments"."patient_id" +INNER JOIN "staff" ON "staff"."id" = "patients"."physician_id" AND "staff"."type" = $1 +INNER JOIN "accounts" ON "accounts"."id" = "staff"."account_id" +WHERE (occurred_at > '2020-03-14 21:00:39.156746') +GROUP BY "treatments"."id", DATE(treatments.occurred_at), staff.id +ORDER BY "treatments"."id" DESC LIMIT $2 [["type", "Physician"], +=end diff --git a/rvh/app/models/treatment.rb b/rvh/app/models/treatment.rb index 4b64de1..9481aa5 100644 --- a/rvh/app/models/treatment.rb +++ b/rvh/app/models/treatment.rb @@ -1,4 +1,4 @@ class Treatment < ApplicationRecord - has_one :physician, through: :patient belongs_to :patient + has_one :physician, through: :patient end diff --git a/rvh/erd.dot b/rvh/erd.dot index 22fe494..2d1aac5 100644 --- a/rvh/erd.dot +++ b/rvh/erd.dot @@ -41,7 +41,7 @@ m_CareCentre [label = <<table border="0" align="center" cellspacing="0.5" cellpa <table border="0" align="left" cellspacing="2" cellpadding="0" width="134"> <tr><td align="left" width="130" port="location">location <font face="Arial Italic" color="grey60">string</font></td></tr> <tr><td align="left" width="130" port="name">name <font face="Arial Italic" color="grey60">string</font></td></tr> - <tr><td align="left" width="130" port="nurse_id">nurse_id <font face="Arial Italic" color="grey60">integer ∗</font></td></tr> + <tr><td align="left" width="130" port="nurse_id">nurse_id <font face="Arial Italic" color="grey60">integer (8) ∗</font></td></tr> </table> >]; m_Consumption [label = <<table border="0" align="center" cellspacing="0.5" cellpadding="0" width="134"> @@ -50,7 +50,6 @@ m_Consumption [label = <<table border="0" align="center" cellspacing="0.5" cellp | <table border="0" align="left" cellspacing="2" cellpadding="0" width="134"> <tr><td align="left" width="130" port="consumed_at">consumed_at <font face="Arial Italic" color="grey60">datetime ∗</font></td></tr> - <tr><td align="left" width="130" port="physician_id">physician_id <font face="Arial Italic" color="grey60">integer ∗</font></td></tr> <tr><td align="left" width="130" port="quantity">quantity <font face="Arial Italic" color="grey60">integer ∗</font></td></tr> <tr><td align="left" width="130" port="total_cost">total_cost <font face="Arial Italic" color="grey60">decimal ∗</font></td></tr> </table> @@ -84,8 +83,7 @@ m_Patient [label = <<table border="0" align="center" cellspacing="0.5" cellpaddi | <table border="0" align="left" cellspacing="2" cellpadding="0" width="134"> <tr><td align="left" width="130" port="contacted_at">contacted_at <font face="Arial Italic" color="grey60">datetime ∗</font></td></tr> - <tr><td align="left" width="130" port="physician_id">physician_id <font face="Arial Italic" color="grey60">integer ∗</font></td></tr> - <tr><td align="left" width="130" port="referring_physician_id">referring_physician_id <font face="Arial Italic" color="grey60">integer ∗</font></td></tr> + <tr><td align="left" width="130" port="referring_physician_id">referring_physician_id <font face="Arial Italic" color="grey60">integer (8) ∗</font></td></tr> </table> >]; m_Physician [color = "grey60", fontcolor = "grey60", label = <<table border="0" align="center" cellspacing="0.5" cellpadding="0" width="134"> @@ -97,7 +95,7 @@ m_Shift [label = <<table border="0" align="center" cellspacing="0.5" cellpadding </table> | <table border="0" align="left" cellspacing="2" cellpadding="0" width="134"> - <tr><td align="left" width="130" port="employee_id">employee_id <font face="Arial Italic" color="grey60">integer ∗</font></td></tr> + <tr><td align="left" width="130" port="employee_id">employee_id <font face="Arial Italic" color="grey60">integer (8) ∗</font></td></tr> <tr><td align="left" width="130" port="ended_at">ended_at <font face="Arial Italic" color="grey60">datetime</font></td></tr> <tr><td align="left" width="130" port="started_at">started_at <font face="Arial Italic" color="grey60">datetime ∗</font></td></tr> </table> @@ -144,18 +142,18 @@ m_Volunteer [color = "grey60", fontcolor = "grey60", label = <<table border="0" m_Staff -> m_Technician [color = "grey60", arrowtail = "onormal", arrowhead = "none", arrowsize = "1.2"]; m_Staff -> m_Volunteer [color = "grey60", arrowtail = "onormal", arrowhead = "none", arrowsize = "1.2"]; m_Account -> m_Staff [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "5"]; - m_Laboratory -> m_Staff [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "5"]; + m_Laboratory -> m_Staff [arrowsize = "0.6", arrowhead = "odotnormal", arrowtail = "odot", weight = "5"]; m_Staff -> m_Treatment [arrowsize = "0.6", arrowhead = "odotnormal", arrowtail = "odot", weight = "5"]; + m_Physician -> m_Patient [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "3"]; m_CareCentre -> m_Shift [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "1"]; m_Patient -> m_Consumption [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "1"]; m_Item -> m_Consumption [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "2"]; m_Physician -> m_Consumption [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "1"]; - m_Physician -> m_Treatment [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "1"]; m_Patient -> m_Treatment [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "2"]; + m_Treatment -> m_Physician [style = "dotted", arrowsize = "0.6", arrowhead = "odot", arrowtail = "odot", weight = "1", constraint = "false"]; m_CareCentre -> m_Bed [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "2"]; m_Patient -> m_Bed [arrowsize = "0.6", arrowhead = "odot", arrowtail = "odot", weight = "2"]; m_Patient -> m_Visit [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "1"]; m_Account -> m_Patient [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "1"]; - m_Physician -> m_Patient [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "2"]; m_Nurse -> m_CareCentre [arrowsize = "0.6", arrowhead = "dotnormal", arrowtail = "odot", weight = "1"]; } |
