diff --git a/app/patients/delete/controller.js b/app/patients/delete/controller.js index e92ca64a5c..6a4c1b18da 100644 --- a/app/patients/delete/controller.js +++ b/app/patients/delete/controller.js @@ -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'), @@ -31,9 +29,9 @@ 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'), @@ -41,7 +39,7 @@ export default AbstractDeleteController.extend(PatientVisitsMixin, PatientInvoic 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 @@ -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'); @@ -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'), diff --git a/tests/acceptance/patients-test.js b/tests/acceptance/patients-test.js index 6c00d4c926..0c4ffd0430 100644 --- a/tests/acceptance/patients-test.js +++ b/tests/acceptance/patients-test.js @@ -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() {