Skip to content

Commit

Permalink
fix(patient): activity report uses proper ids
Browse files Browse the repository at this point in the history
This commit fixes the patient activity report so that it uses proper
identifiers.  Note: there are some improvements that can be made to
better MySQL performance - moving the LEFT JOIN out of the UNION and
using the cached ids in the document_map.

Closes #129.
  • Loading branch information
Jonathan Niles committed Jan 21, 2017
1 parent ca955d8 commit 10407a8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 35 deletions.
1 change: 0 additions & 1 deletion client/src/css/angular-chart.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 21 additions & 17 deletions server/controllers/finance/debtors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,35 +258,39 @@ function balance(req, res, next) {


/**
* @method financial Patient
* @method financialPatient
*
* @description
* This function allows to know the reports' Patient Financial Activity
* matching parameters provided in the debtorUuid parameter.
*
* @todo - move the LEFT JOIN outside the UNION
*/
function financialPatient(debtorUuid) {
const buid = db.bid(debtorUuid);

// build the main part of the SQL query
let sql = `
SELECT transaction.trans_id, transaction.entity_uuid, transaction.description, transaction.trans_date, sum(transaction.credit_equiv) as credit, sum(transaction.debit_equiv) as debit,
transaction.reference, transaction.abbr
SELECT transaction.trans_id, BUID(transaction.entity_uuid) as entity_uuid, transaction.description,
BUID(transaction.record_uuid) AS record_uuid, transaction.trans_date,
SUM(transaction.credit_equiv) AS credit, SUM(transaction.debit_equiv) AS debit,
IF(ISNULL(transaction.reference), '', CONCAT_WS('.', '${identifiers.INVOICE.key}', transaction.abbr, transaction.reference)) AS reference
FROM (
SELECT posting_journal.trans_id, BUID(posting_journal.entity_uuid) AS entity_uuid, posting_journal.description,
posting_journal.trans_date, posting_journal.debit_equiv, posting_journal.credit_equiv, invoice.reference, project.abbr
FROM posting_journal
LEFT JOIN invoice ON invoice.uuid = posting_journal.record_uuid
LEFT JOIN project ON invoice.project_id = project.id
WHERE posting_journal.entity_uuid = ?
SELECT posting_journal.trans_id, posting_journal.entity_uuid, posting_journal.description, posting_journal.record_uuid,
posting_journal.trans_date, posting_journal.debit_equiv, posting_journal.credit_equiv, invoice.reference, project.abbr
FROM posting_journal
LEFT JOIN invoice ON invoice.uuid = posting_journal.record_uuid
LEFT JOIN project ON invoice.project_id = project.id
WHERE posting_journal.entity_uuid = ?
UNION
SELECT general_ledger.trans_id, BUID(general_ledger.entity_uuid) AS entity_uuid, general_ledger.description,
general_ledger.trans_date, general_ledger.debit_equiv, general_ledger.credit_equiv, invoice.reference, project.abbr
FROM general_ledger
LEFT JOIN invoice ON invoice.uuid = general_ledger.record_uuid
LEFT JOIN project ON invoice.project_id = project.id
WHERE general_ledger.entity_uuid = ?
) as transaction
GROUP BY transaction.trans_id
SELECT general_ledger.trans_id, general_ledger.entity_uuid, general_ledger.description, general_ledger.record_uuid,
general_ledger.trans_date, general_ledger.debit_equiv, general_ledger.credit_equiv, invoice.reference, project.abbr
FROM general_ledger
LEFT JOIN invoice ON invoice.uuid = general_ledger.record_uuid
LEFT JOIN project ON invoice.project_id = project.id
WHERE general_ledger.entity_uuid = ?
) AS transaction
GROUP BY transaction.record_uuid
ORDER BY transaction.trans_date ASC, transaction.trans_id;`;

return db.exec(sql, [buid, buid]);
Expand Down
24 changes: 10 additions & 14 deletions server/controllers/finance/reports/financial.patient.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<h4 class="text-center">{{translate "PATIENT_RECORDS.FINANCIAL_ACTIVITY.ACCOUNT"}} : {{ debtor.number }} </h4>

<section>
<table class="table table-condensed table-striped table-report table-bordered ">
<table class="table table-condensed table-striped table-bordered table-report">
<thead>
<tr class="text-capitalize text-center" style="background-color: #ccc;">
<tr class="text-capitalize text-center" style="background-color: #ccc;" >
<th style="width: 5%;">{{translate "TABLE.COLUMNS.INVOICE_ID" }}</th>
<th style="width: 15%;">{{translate "TABLE.COLUMNS.TRANSACTION_ID" }}</th>
<th style="width: 15%;">{{translate "TABLE.COLUMNS.DATE" }}</th>
Expand All @@ -24,26 +24,22 @@
<tbody>
{{#each patients}}
<tr>
<td>{{this.abbr}}{{this.reference}}</td>
<td>{{this.trans_id}}</td>
<td class="text-right">{{this.reference}}</td>
<td class="text-right">{{this.trans_id}}</td>
<td>{{date this.date}}</td>
<td>{{this.description}}</td>
<td>{{currency this.debit ../metadata.enterprise.currency_id}}</td>
<td>{{currency this.credit ../metadata.enterprise.currency_id}}</td>
<td class="text-right">{{currency this.debit ../metadata.enterprise.currency_id}}</td>
<td class="text-right">{{currency this.credit ../metadata.enterprise.currency_id}}</td>
</tr>
{{else}}
<tr>
<td colspan="6" class="text-center">
{{translate "TABLE.COLUMNS.EMPTY"}}
</td>
</tr>
{{>emptyTable columns=6}}
{{/each}}
</tbody>
<tfoot>
<tr style="background-color: #ededed;">
<td colspan="4">{{translate "FORM.LABELS.TOTAL" }}</td>
<td>{{currency sum.debit metadata.enterprise.currency_id}}</td>
<td>{{currency sum.credit metadata.enterprise.currency_id}}</td>
<th colspan="4">{{translate "FORM.LABELS.TOTAL" }}</th>
<th class="text-right">{{currency sum.debit metadata.enterprise.currency_id}}</th>
<th class="text-right">{{currency sum.credit metadata.enterprise.currency_id}}</th>
</tr>
<tr style="background-color: #ededed;">
<th colspan="6" class="text-right">{{translate "FORM.LABELS.BALANCE" }} {{currency sum.balance metadata.enterprise.currency_id}}</th>
Expand Down
5 changes: 2 additions & 3 deletions server/lib/template/partials/head.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
<link href="{{absolutePath}}/vendor/components-font-awesome/css/font-awesome.css" rel="stylesheet">
<script src="{{absolutePath}}/vendor/JsBarcode.all.min.js"></script>
<style>
thead {
thead {
display : table-header-group;
}
tr {
tr {
page-break-inside : avoid;
}
</style>
Expand Down

0 comments on commit 10407a8

Please sign in to comment.