From 58ca50c33f47a81a8c4f6eb3ba333f9eaa40155f Mon Sep 17 00:00:00 2001 From: Will Droste Date: Mon, 9 Dec 2013 19:17:18 -0600 Subject: [PATCH] Issue #9 -Added new/established report --- .../report/ReportController.groovy | 46 +++++----- .../org/sacredheart/PatientVisit.groovy | 1 + grails-app/i18n/messages.properties | 1 + .../sacredheart/PatientVisitService.groovy | 59 +++++++++++++ grails-app/views/patient/show.gsp | 2 +- grails-app/views/report/_patientList.gsp | 30 +++++++ grails-app/views/report/establishedReport.gsp | 88 +++++++++++++++++++ 7 files changed, 205 insertions(+), 22 deletions(-) create mode 100644 grails-app/views/report/_patientList.gsp create mode 100644 grails-app/views/report/establishedReport.gsp diff --git a/grails-app/controllers/org/sacredheart/report/ReportController.groovy b/grails-app/controllers/org/sacredheart/report/ReportController.groovy index 871a9a4..a6bee7d 100644 --- a/grails-app/controllers/org/sacredheart/report/ReportController.groovy +++ b/grails-app/controllers/org/sacredheart/report/ReportController.groovy @@ -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) { @@ -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. */ @@ -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 ] } @@ -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 ] } diff --git a/grails-app/domain/org/sacredheart/PatientVisit.groovy b/grails-app/domain/org/sacredheart/PatientVisit.groovy index 1752604..9e822d4 100644 --- a/grails-app/domain/org/sacredheart/PatientVisit.groovy +++ b/grails-app/domain/org/sacredheart/PatientVisit.groovy @@ -15,6 +15,7 @@ class PatientVisit implements Serializable { static mapping = { provider ignoreNotFound: true + sort 'dateOfVisit':'desc' } static belongsTo = [patient: Patient] diff --git a/grails-app/i18n/messages.properties b/grails-app/i18n/messages.properties index d85eb1e..ca7a826 100644 --- a/grails-app/i18n/messages.properties +++ b/grails-app/i18n/messages.properties @@ -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 diff --git a/grails-app/services/org/sacredheart/PatientVisitService.groovy b/grails-app/services/org/sacredheart/PatientVisitService.groovy index 1ede8f9..d5befdb 100644 --- a/grails-app/services/org/sacredheart/PatientVisitService.groovy +++ b/grails-app/services/org/sacredheart/PatientVisitService.groovy @@ -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. */ diff --git a/grails-app/views/patient/show.gsp b/grails-app/views/patient/show.gsp index a47635b..a9b7cf1 100644 --- a/grails-app/views/patient/show.gsp +++ b/grails-app/views/patient/show.gsp @@ -262,7 +262,7 @@ - + diff --git a/grails-app/views/report/_patientList.gsp b/grails-app/views/report/_patientList.gsp new file mode 100644 index 0000000..e563ab4 --- /dev/null +++ b/grails-app/views/report/_patientList.gsp @@ -0,0 +1,30 @@ +
+
+

${tableHeader}

+ + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+
diff --git a/grails-app/views/report/establishedReport.gsp b/grails-app/views/report/establishedReport.gsp new file mode 100644 index 0000000..63b92ad --- /dev/null +++ b/grails-app/views/report/establishedReport.gsp @@ -0,0 +1,88 @@ +<%@ page import="org.sacredheart.report.VisitReport" %> + + + + + <g:message code="report.setup.label"/> + + + + +
+ +
+ +
+ + + + + + + + + + + + + + + + + +
New Patients:${newPatients.size()}
Established Patients:${estPatients.size()}
New Patients Visits:${newVisits}
Established Patients Visits:${estVisits}
+
+
+
+
+
+
+ + + + + + // 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); +} + + +