Skip to content

Commit

Permalink
Issue #9 -Added new/established report
Browse files Browse the repository at this point in the history
  • Loading branch information
wdroste committed Dec 10, 2013
1 parent 5a3f6a5 commit 58ca50c
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import org.sacredheart.PatientVisit
*/
class ReportController {

def patientVisitService

def index() {
[reports: ['visitReport', 'screeningResultsReport']]
[reports: ['visitReport', 'screeningResultsReport', 'establishedReport']]
}

def run(ReportRunCommand cmd) {
Expand All @@ -20,6 +22,11 @@ class ReportController {
forward(action:cmd.reportId, params:params)
}

def establishedReport(ReportRunCommand cmd) {
def map = patientVisitService.establishedPatientVisitReport(cmd.start, cmd.end)
return map
}

/**
* Determine the total number of visits between start/end date. Determine the distinct patients.
*/
Expand All @@ -29,11 +36,11 @@ class ReportController {
map[visitType] = PatientVisit.countByTypeOfVisitAndDateOfVisitBetween(visitType, cmd.start, cmd.end)
}
[
'startDate': cmd.start,
'endDate': cmd.end,
'totalVisits':totalPatientVisits(cmd),
'distinctPatientCount':distinctPatientCount(cmd),
'results':map
'startDate': cmd.start,
'endDate': cmd.end,
'totalVisits':totalPatientVisits(cmd),
'distinctPatientCount':distinctPatientCount(cmd),
'results':map
]
}

Expand All @@ -42,23 +49,20 @@ class ReportController {
*/
def screeningResultsReport(ReportRunCommand cmd) {
def map = [:]
Patient.SCREENING_RESULTS.each { result ->
map[result] = PatientVisit.withCriteria {
projections {
countDistinct('patient')
}
patient {
eq('screeningResult', result)
}
between('dateOfVisit', cmd.start, cmd.end)
}[0]

// make a map of patients that are before and after start date..
def visits = PatientVisit.withCriteria {



}

[
'startDate': cmd.start,
'endDate': cmd.end,
'totalVisits':totalPatientVisits(cmd),
'distinctPatientCount':distinctPatientCount(cmd),
'results':map
'startDate': cmd.start,
'endDate': cmd.end,
'totalVisits':totalPatientVisits(cmd),
'distinctPatientCount':distinctPatientCount(cmd),
'results':map
]
}

Expand Down
1 change: 1 addition & 0 deletions grails-app/domain/org/sacredheart/PatientVisit.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class PatientVisit implements Serializable {

static mapping = {
provider ignoreNotFound: true
sort 'dateOfVisit':'desc'
}

static belongsTo = [patient: Patient]
Expand Down
1 change: 1 addition & 0 deletions grails-app/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ report.setup.label=Base Reports

report.static.select.visitReport=Visit Report
report.static.select.screeningResultsReport=Screening Results Report
report.static.select.establishedReport=New/Established Patients Report

provider.label=Provider
provider.license.label=License
Expand Down
59 changes: 59 additions & 0 deletions grails-app/services/org/sacredheart/PatientVisitService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,65 @@ class PatientVisitService {

static transactional = true

def establishedPatientVisitReport(Date start, Date end) {
// all the patients for the month..
def patients = Patient.withCriteria {
projections {
distinct()
}
visits {
between('dateOfVisit', start, end)
}
}

// determine the established patients..
def estPatients = PatientVisit.withCriteria {
projections {
distinct('patient')
}
lt('dateOfVisit', start)
inList('patient', patients)
}

// determine the new patients..
def newPatients = PatientVisit.withCriteria {
projections {
distinct('patient')
}
not {
lt('dateOfVisit', start)
inList('patient', estPatients)
}
}

// determine the number of visits by est
def estVisits = PatientVisit.withCriteria {
projections {
count()
}
inList('patient', estPatients)
between('dateOfVisit', start, end)
}

def newVisits = PatientVisit.withCriteria {
projections {
count()
}
inList('patient', newPatients)
between('dateOfVisit', start, end)
}

[
'startDate':start,
'endDate':end,
'patients':patients,
'estPatients':estPatients,
'newPatients':newPatients,
'estVisits':estVisits[0],
'newVisits':newVisits[0]
]
}

/**
* Import CSV data from Medkind.
*/
Expand Down
2 changes: 1 addition & 1 deletion grails-app/views/patient/show.gsp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
</tr>
</thead>
<tbody>
<g:each in="${patientInstance.visits}" var="patientVisitInstance">
<g:each in="${patientInstance.visits.sort{new Date() - it.dateOfVisit}}" var="patientVisitInstance">
<tr>
<td>
<g:link action="edit" controller="patientVisit" id="${patientVisitInstance.id}">
Expand Down
30 changes: 30 additions & 0 deletions grails-app/views/report/_patientList.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div class="row-fluid">
<div class="offset3 span9">
<h3>${tableHeader}</h3>
<table class="table table-striped" data-provides="rowlink">
<thead>
<tr>
<g:sortableColumn property="patientId" title="${message(code: 'patient.patientId.label')}"/>
<g:sortableColumn property="dateOfBirth" title="${message(code: 'patient.dateOfBirth.label')}"/>
<g:sortableColumn property="lastName" title="${message(code: 'patient.lastName.label')}"/>
<g:sortableColumn property="firstName" title="${message(code: 'patient.firstName.label')}"/>
<th></th>
</tr>
</thead>
<tbody>
<g:each in="${patients}" var="patientInstance">
<tr>
<td>
<g:link action="show" id="${patientInstance.id}">
<f:display bean="${patientInstance}" property="patientId"/>
</g:link>
</td>
<td><f:display bean="${patientInstance}" property="dateOfBirth"/></td>
<td><f:display bean="${patientInstance}" property="lastName"/></td>
<td><f:display bean="${patientInstance}" property="firstName"/></td>
</tr>
</g:each>
</tbody>
</table>
</div>
</div>
88 changes: 88 additions & 0 deletions grails-app/views/report/establishedReport.gsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<%@ page import="org.sacredheart.report.VisitReport" %>
<!doctype html>
<html>
<head>
<meta name="layout" content="bootstrap">
<title><g:message code="report.setup.label"/></title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
</head>

<body>
<div class="row-fluid">
<g:render template="nav"/>
<div class="span9">
<div class="page-header">
<h1>
<g:message code="report.static.select.establishedReport"/>:
<g:formatDate date="${startDate}" type="date" style="SHORT"/> -
<g:formatDate date="${endDate}" type="date" style="SHORT"/>
</h1>
<table>
<tr>
<td>Total Visits: ${estVisits + newVisits}</td>
</tr>
<tr>
<td>Total distinct patients: ${estPatients.size() + newPatients.size()}</td>
</tr>
</table>
</div>
<div class="span3">
<table class="table">
<tr>
<td>New Patients:</td>
<td>${newPatients.size()}</td>
</tr>
<tr>
<td>Established Patients:</td>
<td>${estPatients.size()}</td>
</tr>
<tr>
<td>New Patients Visits:</td>
<td>${newVisits}</td>
</tr>
<tr>
<td>Established Patients Visits:</td>
<td>${estVisits}</td>
</tr>
</table>
</div>
<div class="span6">
<div id="chart"></div>
</div>
</div>
</div>
<g:render template="patientList" model="${[tableHeader:'New Patients', patients:newPatients]}"/>
<g:render template="patientList" model="${[tableHeader:'Established Patients', patients:estPatients]}"/>

<!--Load the AJAX API-->
<r:script>
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {'packages':['corechart']});

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);

function drawChart() {
var data = google.visualization.arrayToDataTable([
['Type', 'Established', 'New' ],
['Visits', ${estVisits}, ${newVisits}],
['Patients', ${estPatients.size()}, ${newPatients.size()}]
]);

var options = { width: '100%', height: 200,
legend: {
position: 'top',
maxLines: 3
},
bar: {
groupWidth: '75%'
},
isStacked: true
};
// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.BarChart(document.getElementById('chart'));
chart.draw(data, options);
}
</r:script>
</body>
</html>

0 comments on commit 58ca50c

Please sign in to comment.