Permalink
Browse files

1. Added methods to calculate patients seen per DAY of shift

2. Changed uploader to allow multiple file uploads
3. Display results in /billings/
  • Loading branch information...
1 parent c0dfb6e commit fc83e8563f6dc0d970163860894866d9f233122f @tareko committed Dec 19, 2012
@@ -8,27 +8,69 @@ class BillingsController extends AppController {
function index() {
+ $i = 0;
$this->loadModel('BillingsItem');
- $perDay = $this->BillingsItem->distinctPatientsPerDayAnnualAverage(array('healthcare_provider' => 10800));
- debug ($perDay);
+ $this->loadModel('Shift');
+
+ $conditions = array();
+ if (isset($this->request->query['id'])) {
+ $conditions = $conditions + array('user_id' => $this->request->query['id']);
+ }
+ if (isset($this->request->query['start_date'])) {
+ $conditions = $conditions + array('Shift.date >=' => $this->request->query['start_date']);
+ }
+ if (isset($this->request->query['end_date'])) {
+ $conditions = $conditions + array('Shift.date <=' => $this->request->query['end_date']);
+ }
+
+
+ $shiftsWorked = $this->Shift->getShiftList($conditions);
+ foreach($shiftsWorked as $shift) {
+ $patientsSeen[$i] = $shift;
+ $patientsPerShift = $this->BillingsItem->distinctPatientsPerShift($shift);
+ if ($patientsPerShift) {
+ $patientsSeen[$i]['Billing'] = $patientsPerShift['0'];
+ }
+ else {
+ $patientsSeen[$i]['Billing']['count'] = 'Unavailable';
+ }
+ $i = $i + 1;
+ }
+ $this->set(compact('patientsSeen'));
$this->render();
}
/* Upload function
*
*/
function upload() {
+ $status = array();
if ($this->request->isPost()) {
- $data = $this->Billing->import($this->request->data['Billing']['upload']['tmp_name']);
- if ($this->Billing->saveAll($data, array('deep' => true))) {
- return $this->Session->setFlash('Successfully imported file \'' .$this->request->data['Billing']['upload']['name'] . '\'');
+ $failure = false;
+ foreach ($this->data['Billing']['upload'] as $upload) {
+ $data = $this->Billing->import($upload['tmp_name']);
+ if ($this->Billing->saveAll($data, array('deep' => true))) {
+ $status[] = $upload['name'] ." saved successfully";
+ }
+ else {
+ debug($this->Billing->validationErrors);
+ debug($data);
+ $status[] = $upload['name'] ." failed to save";
+ $failure = true;
+ }
+ }
+ if ($failure == true) {
+ $this->set(compact('status'));
+ $this->Session->setFlash('I\'m sorry. One or more files did not successfully import.');
+ return $this->render();
}
else {
- debug($this->Billing->validationErrors);
- debug($data);
- return $this->Session->setFlash('I\'m sorry. This file did not successfully import.');
+ $this->set(compact('status'));
+ $this->Session->setFlash('Import successful.');
+ return $this->render();
}
-
- }
+ }
+ debug($status);
+ $this->set(compact('status'));
$this->render();
}
@@ -197,5 +197,4 @@ public function recombineBilling ($data) {
}
return $output;
}
-
}
@@ -53,7 +53,8 @@ public function dateFormatBeforeSave($dateString) {
}
public function distinctPatientsPerDay ($conditions = array()) {
- $i = 0;
+ $i = 0;
+ $output = array();
$data = $this->find('all', array(
'fields' => array('Billing.healthcare_provider', 'service_date', 'COUNT(DISTINCT billing_id)'),
'conditions' => $conditions,
@@ -68,7 +69,7 @@ public function distinctPatientsPerDay ($conditions = array()) {
}
return $output;
}
-
+
public function distinctPatientsPerDayAnnualAverage ($conditions = array()) {
$i = 0;
$data = $this->find('all', array(
@@ -85,5 +86,14 @@ public function distinctPatientsPerDayAnnualAverage ($conditions = array()) {
}
return $output;
}
+
+ public function distinctPatientsPerShift ($shift) {
+ $conditions = array(
+ 'service_date' => $shift['Shift']['date'],
+ 'Billing.healthcare_provider' => $shift['User']['Profile']['cb_ohip'],
+ );
+ $output = $this->distinctPatientsPerDay($conditions);
+ return $output;
+ }
}
View
@@ -115,7 +115,7 @@ function getShiftList($conditions) {
'User' => array(
'fields' => array('name'),
'Profile' => array(
- 'fields' => array('cb_displayname')
+ 'fields' => array('cb_displayname', 'cb_ohip')
))),
'conditions' => $conditions,
'recursive' => '2',
@@ -173,4 +173,48 @@ function getMasterSet ($id = NULL) {
}
return $masterSet;
}
-}
+
+ /**
+ * The shifts worked by a physician (or several physicians) by OHIP Number
+ *
+ * @param unknown_type $healthcare_provider
+ * @param unknown_type $start_date
+ * @param unknown_type $end_date
+ * @param array $conditions
+ * @return array $output
+ */
+ function shiftsWorkedbyOhipNumber ($healthcare_provider = NULL, $start_date = NULL, $end_date = NULL, $conditions = array()) {
+ $conditionsProfile = array_merge($conditions, array(
+ 'Profile.cb_ohip' => $healthcare_provider,
+ ));
+ $conditionsShift = array();
+ if ($start_date) {
+ $conditionsShift = array_merge($conditionsShift, array(
+ 'Shift.date >=' => $start_date
+ ));
+ }
+ if ($end_date) {
+ $conditionsShift = array_merge($conditionsShift, array(
+ 'Shift.date <=' => $end_date,
+ ));
+ }
+
+ return $this->User->Profile->find('all', array(
+ 'contain' => array(
+ 'Shift' => array(
+ 'fields' => array('id', 'date'),
+ 'conditions' => $conditionsShift,
+ 'ShiftsType' => array(
+ 'fields' => array('id', 'shift_start', 'shift_end'),
+ 'Location' => array(
+ 'fields' => 'location')),
+ 'User' => array(
+ 'fields' => array('name'),
+ ))),
+ 'fields' => array('cb_ohip'),
+ 'conditions' => $conditionsProfile,
+ 'recursive' => '3',
+ ));
+
+ }
+}
@@ -1,121 +1,16 @@
-In your whole career, you saw: <?php $total_patients ?> patients
-Your annual average is: <?php $annual_average ?> patients
-Your daily average is: <?php $daily_average ?> patients
-
-The group daily average is:
-
-
-<!-- <style>
-body {
- font: 10px sans-serif;
-}
-
-.axis path,
-.axis line {
- fill: none;
- stroke: #000;
- shape-rendering: crispEdges;
-}
-
-.dot {
- stroke: #000;
+<table>
+ <tr><th>Physician</th><th>Date</th><th>Location</th><th>Shift</th><th>Patients seen</th></tr>
+<?php
+
+foreach ($patientsSeen as $shift) {
+ echo "<tr>";
+ echo "<td>".$shift['User']['name']."</td>";
+ echo "<td>".$shift['Shift']['date']."</td>";
+ echo "<td>".$shift['ShiftsType']['Location']['location']."</td>";
+ echo "<td>".$shift['ShiftsType']['shift_start']." - ".$shift['ShiftsType']['shift_end'] ."</td>";
+ echo "<td>".$shift['Billing']['count']."</td>";
+ echo "</tr>";
}
-</style>
-<script src="http://d3js.org/d3.v3.min.js"></script>
-<script>
-
-var margin = {top: 20, right: 20, bottom: 30, left: 40},
- width = 960 - margin.left - margin.right,
- height = 500 - margin.top - margin.bottom;
-
-var x = d3.time.scale()
- .range([0, width]);
-
-var y = d3.scale.linear()
- .range([height, 0]);
-
-var color = d3.scale.category10();
-
-var xAxis = d3.svg.axis()
- .scale(x)
- .orient("bottom");
-
-var yAxis = d3.svg.axis()
- .scale(y)
- .orient("left");
-
-var svg = d3.select("body").append("svg")
- .attr("width", width + margin.left + margin.right)
- .attr("height", height + margin.top + margin.bottom)
- .append("g")
- .attr("transform", "translate(" + margin.left + "," + margin.top + ")");
-
-d3.csv("http://127.0.0.1/kitab/billings/patientsPerDay.csv", function(error, data) {
-
- data = data.map( function (d) {
- return {
- provider: +d.Provider, // the + sign will coerce strings to number values
- date: new Date(d['Service date']),
- patients: +d['Unique patients seen'] };
- });
-
- providers = d3.nest().key(function(d) { return d.provider; }).entries(data);
-
- x.domain(d3.extent(data, function(d) { return d.date; })).nice();
- y.domain(d3.extent(data, function(d) { return d.patients; })).nice();
-
- svg.append("g")
- .attr("class", "x axis")
- .attr("transform", "translate(0," + height + ")")
- .call(xAxis)
- .append("text")
- .attr("class", "label")
- .attr("x", width)
- .attr("y", -6)
- .style("text-anchor", "end")
- .text("Sepal Width (cm)");
-
- svg.append("g")
- .attr("class", "y axis")
- .call(yAxis)
- .append("text")
- .attr("class", "label")
- .attr("transform", "rotate(-90)")
- .attr("y", 6)
- .attr("dy", ".71em")
- .style("text-anchor", "end")
- .text("Sepal Length (cm)")
-
- svg.selectAll(".dot")
- .data(data)
- .enter().append("circle")
- .attr("class", "dot")
- .attr("r", 3.5)
- .attr("cx", function(d) { return x(d.date); })
- .attr("cy", function(d) { return y(d.patients); })
- .style("fill", function(d) { return color(d.provider); });
-
- var legend = svg.selectAll(".legend")
- .data(color.domain())
- .enter().append("g")
- .attr("class", "legend")
- .attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
-
- legend.append("rect")
- .attr("x", width - 18)
- .attr("width", 18)
- .attr("height", 18)
- .style("fill", color);
-
- legend.append("text")
- .attr("x", width - 24)
- .attr("y", 9)
- .attr("dy", ".35em")
- .style("text-anchor", "end")
- .text(function(d) { return d; });
-
-});
-
-</script>
--->
+?>
+</table>
@@ -1,9 +1,17 @@
<h1>MOHLTC Billing submission uploader</h1>
<p>Please note that this uploader will take any MOHLTC standard billing submission file and import it to your database</p>
<?php
+if (!empty($status)) {
+ foreach ($status as $status) {
+ echo $status . "<br/>";
+ }
+}
+
+
echo $this->Form->create('Billing', array('type' => 'file'));
-echo $this->Form->input('upload', array(
- 'type' => 'file'
+echo $this->Form->input('upload.', array(
+ 'type' => 'file',
+ 'multiple'
));
echo $this->Form->end('Submit');
?>

0 comments on commit fc83e85

Please sign in to comment.