Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Fix patient deletion
Browse files Browse the repository at this point in the history
Fixes #1049
  • Loading branch information
jkleinsc committed Apr 11, 2017
1 parent cdb7040 commit 279abd7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
18 changes: 8 additions & 10 deletions app/patients/delete/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import Ember from 'ember';
import { translationMacro as t } from 'ember-i18n';
import { task, taskGroup, all } from 'ember-concurrency';

const MAX_CONCURRENCY = 5;

export default AbstractDeleteController.extend(PatientVisitsMixin, PatientInvoicesMixin, PouchDbMixin, ProgressDialog, PatientAppointmentsMixin, {
title: t('patients.titles.delete'),
progressTitle: t('patients.titles.deletePatientRecord'),
Expand All @@ -31,17 +29,17 @@ export default AbstractDeleteController.extend(PatientVisitsMixin, PatientInvoic
}
let deleteRecordTask = this.get('deleteRecordTask');
let archivePromises = [];
for (let recordToDelete of resolvedArray) {
resolvedArray.forEach((recordToDelete) => {
archivePromises.push(deleteRecordTask.perform(recordToDelete));
}
});
return yield all(archivePromises, 'async array deletion');
}).group('deleting'),

deleteRecordTask: task(function* (recordToDelete) {
recordToDelete.set('archived', true);
yield recordToDelete.save();
return yield recordToDelete.unloadRecord();
}).maxConcurrency(MAX_CONCURRENCY).enqueue().group('deleting'),
}).group('deleting'),

// Override delete action on controller; we must delete
// all related records before deleting patient record
Expand Down Expand Up @@ -71,10 +69,10 @@ export default AbstractDeleteController.extend(PatientVisitsMixin, PatientInvoic

deleteVisitsTask: task(function* (visits) {
let pendingTasks = [];
for (let visit of visits) {
let labs = yield visit.get('labs');
let procedures = yield visit.get('procedures');
let imaging = yield visit.get('imaging');
visits.forEach((visit) => {
let labs = visit.get('labs');
let procedures = visit.get('procedures');
let imaging = visit.get('imaging');
let procCharges = procedures.get('charges');
let labCharges = labs.get('charges');
let imagingCharges = imaging.get('charges');
Expand All @@ -89,7 +87,7 @@ export default AbstractDeleteController.extend(PatientVisitsMixin, PatientInvoic
pendingTasks.push(this.deleteMany(imaging));
pendingTasks.push(this.deleteMany(imagingCharges));
pendingTasks.push(this.deleteMany(visitCharges));
}
});
yield all(pendingTasks);
return yield this.deleteMany(visits);
}).group('deleting'),
Expand Down
23 changes: 23 additions & 0 deletions tests/acceptance/patients-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,29 @@ test('Adding a new patient record', function(assert) {
});
});

test('Delete a patient record', function(assert) {
runWithPouchDump('patient', function() {
authenticateUser();
visit('/patients');
andThen(() =>{
assert.equal(currentURL(), '/patients', 'Patient listing url is correct');
assert.equal(find('tr.clickable td:contains(Joe)').length, 1, 'One patient exists to delete.');
click('tr.clickable button:contains(Delete)');
waitToAppear('.modal-dialog');
});
andThen(() =>{
assert.equal(find('.modal-title').text(), 'Delete Patient', 'Delete Patient ');
assert.equal(find('.modal-body').text().trim(), 'Are you sure you wish to delete Joe Bagadonuts?', 'Patient information appears in modal');
click('.modal-footer button:contains(Delete)');
waitToDisappear('.modal-dialog');
waitToDisappear('tr.clickable td:contains(Joe)');
});
andThen(function() {
assert.equal(find('tr.clickable td:contains(Joe)').length, 0, 'Patient has been successfully deleted.');
});
});
});

function testSimpleReportForm(reportName) {
test(`View reports tab | ${reportName} shows start and end dates`, function(assert) {
runWithPouchDump('default', function() {
Expand Down

0 comments on commit 279abd7

Please sign in to comment.