Skip to content

Commit

Permalink
(Chore) Implement new standards from master; buids
Browse files Browse the repository at this point in the history
This commit bring the receipt core branch up to date with master,
updating all of the outdated references to features that have been
updated.

* Updated invoice receipt example to work with binary uuids
* Resolved conflicts with uuid library
* Removed describe.only from end to end tests

This commit also implements the suggested binary UUID conversion
structure described in
[#321](#321). This
ensures that all controllers using UUIDs to make internal requests can
assume they are working with strings. (Moves conversations to the SQL
query step).
  • Loading branch information
sfount committed Apr 16, 2016
1 parent 7e80c9b commit ea20692
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
2 changes: 1 addition & 1 deletion client/test/e2e/patient/invoice.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var PatientInvoicePage = require('./invoice.page.js');
* - Test for price list
* - Test for discount
*/
describe.only('patient invoice', function () {
describe('patient invoice', function () {
'use strict';

/** @const */
Expand Down
33 changes: 23 additions & 10 deletions server/controllers/finance/patientInvoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,26 @@ function list(req, res, next) {
*
* Find a sale by id in the database.
*
* @param {string} uid - the uuid of the sale in question
* @param {Blob} uid - the uuid of the sale in question
*/
function lookupSale(uid) {
function lookupSale(invoiceUuid) {
'use strict';

var record;

console.log();
console.log('lookupsale got', invoiceUuid);
console.log();

var buid = db.bid(invoiceUuid);

console.log();
console.log('binary id fine');
console.log();

var saleDetailQuery =
'SELECT BUID(sale.uuid) as uuid, CONCAT(project.abbr, sale.reference) AS reference, sale.cost, ' +
'BUID(sale.debtor_uuid) AS debtor_uuid, CONCAT(patient.first_name, " ", patient.last_name) AS debtor_name, ' +
'user_id, discount, date, sale.is_distributable ' +
'BUID(patient.uuid) as patient_uuid, user_id, discount, date, sale.is_distributable ' +
'FROM sale ' +
'LEFT JOIN patient ON patient.debtor_uuid = sale.debtor_uuid ' +
'JOIN project ON project.id = sale.project_id ' +
Expand All @@ -86,14 +95,18 @@ function lookupSale(uid) {
'LEFT JOIN inventory ON sale_item.inventory_uuid = inventory.uuid ' +
'WHERE sale_uuid = ?';

return db.exec(saleDetailQuery, [uid])
return db.exec(saleDetailQuery, [buid])
.then(function (rows) {

if (rows.length === 0) {
throw new NotFound(`Could not find an Inventory with uuid ${uuid.unparse(uid)}`);
console.log('found shit mate');
console.log();

throw new NotFound(`Could not find a sale with uuid ${uuid.unparse(buid)}`);
}

record = rows[0];
return db.exec(saleItemsQuery, [uid]);
return db.exec(saleItemsQuery, [buid]);
})
.then(function (rows) {
record.items = rows;
Expand All @@ -105,9 +118,9 @@ function lookupSale(uid) {
* @todo Read the balance remaining on the debtors account given the sale as an auxillary step
*/
function details(req, res, next) {
var uid = db.bid(req.params.uuid);

lookupSale(uid)

// this assumes a value must be past for this route to initially match
lookupSale(req.params.uuid)
.then(function (record) {
res.status(200).json(record);
})
Expand Down
20 changes: 12 additions & 8 deletions server/controllers/medical/patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ function generatePatientText(patient) {

/** @todo review if this many details should be returned under a patient end point */
function detail(req, res, next) {
const uid = db.bid(req.params.uuid);

handleFetchPatient(uid)
handleFetchPatient(req.params.uuid)
.then(function(patientDetail) {
res.status(200).json(patientDetail);
})
Expand All @@ -179,17 +178,18 @@ function detail(req, res, next) {
function update(req, res, next) {
var updatePatientQuery;
var data = convert(req.body);
var patientId = db.bid(req.params.uuid);
var patientUuid = req.params.uuid;
var buid = db.bid(patientUuid);

// prevent updating the patient's uuid
delete data.uuid;

updatePatientQuery =
'UPDATE patient SET ? WHERE uuid = ?';

db.exec(updatePatientQuery, [data, patientId])
db.exec(updatePatientQuery, [data, buid])
.then(function (result) {
return handleFetchPatient(patientId);
return handleFetchPatient(patientUuid);
})
.then(function (updatedPatient) {
res.status(200).json(updatedPatient);
Expand All @@ -198,7 +198,11 @@ function update(req, res, next) {
.done();
}

function handleFetchPatient(uid) {
function handleFetchPatient(patientUuid) {

// convert uuid to database usable binary uuid
var buid = db.bid(patientUuid);

var patientDetailQuery =
`SELECT BUID(p.uuid) as uuid, p.project_id, BUID(p.debtor_uuid) AS debtor_uuid, p.first_name,
p.last_name, p.middle_name, p.hospital_no, p.sex, p.registration_date, p.email, p.phone, p.dob,
Expand All @@ -211,10 +215,10 @@ function handleFetchPatient(uid) {
ON p.debtor_uuid = d.uuid AND d.group_uuid = dg.uuid AND p.project_id = proj.id
WHERE p.uuid = ?;`;

return db.exec(patientDetailQuery, uid)
return db.exec(patientDetailQuery, buid)
.then(function (rows) {
if (rows.length === 0) {
throw new NotFound(`Could not find a patient with uuid ${uuid.unparse(uid)}`);
throw new NotFound(`Could not find a patient with uuid ${patientUuid}`);
}
return rows[0];
});
Expand Down
6 changes: 5 additions & 1 deletion server/test/api/invoiceReceipt.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ describe('/reports/invoices Receipts Interface', function () {
// utility methods
function expectReportSuccess(result) {
var recipientKeys = ['items', 'recipient', 'enterprise'];

console.log();
console.log();
console.log('report returned', result);
console.log();
console.log();
expect(result).to.have.status(200);
expect(result).to.be.json;
expect(result.body).to.contain.all.keys(recipientKeys);
Expand Down

0 comments on commit ea20692

Please sign in to comment.