Skip to content

Commit

Permalink
Refactor code to conform with style guide
Browse files Browse the repository at this point in the history
  • Loading branch information
adeolabadmus committed Mar 15, 2017
1 parent ad1d00e commit 7895b24
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 101 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
language: node_js
node_js:
- '4'
- "4"

branches:
only:
Expand All @@ -21,8 +21,8 @@ before_install:
- phantomjs --version

install:
- npm install
- bower install
- npm install
- bower install

script:
- travis_retry npm test
6 changes: 3 additions & 3 deletions app/mixins/patient-submodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ export default Ember.Mixin.create(PatientVisits, {
}.property('model.patient.id', 'newVisitAdded'),

patientProcedures: Ember.computed('patientVisits.[]', function() {
let patient = this.get('model.patient');
let patient = get(this, 'model.patient');
return DS.PromiseArray.create({
promise: this.get('patientVisits').then((patientVisits) => {
return patient.get('operationReports').then((operationReports) => {
promise: get(this, 'patientVisits').then((patientVisits) => {
return get(patient, 'operationReports').then((operationReports) => {
return this._getPatientProcedures(operationReports, patientVisits);
});
})
Expand Down
18 changes: 8 additions & 10 deletions app/mixins/patient-visits.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export default Ember.Mixin.create(PouchDbMixin, {
},

getPatientFutureAppointment(visit, outPatient) {
let patientId = visit.get('patient.id');
let visitDate = visit.get('startDate');
let maxValue = this.get('maxValue');
let patientId = get(visit, 'patient.id');
let visitDate = get(visit, 'startDate');
let maxValue = get(this, 'maxValue');
let promise = this.store.query('appointment', {
options: {
startkey: [patientId, null, null, 'appointment_'],
Expand All @@ -34,18 +34,16 @@ export default Ember.Mixin.create(PouchDbMixin, {
mapReduce: 'appointments_by_patient'
}).then(function(result) {
let futureAppointments = result.filter(function(data) {
let startDate = data.get('startDate');
let startDate = get(data, 'startDate');
return startDate && moment(startDate).isAfter(moment(visitDate), 'day');
}).sortBy('startDate');
if (!futureAppointments.length) {
return '';
return null;
}
if (!outPatient) {
let [appointment] = futureAppointments;
return appointment;
return futureAppointments;
} else {
let res = futureAppointments.slice(0, 3);
return res;
return futureAppointments.slice(0, 3);
}

});
Expand All @@ -56,7 +54,7 @@ export default Ember.Mixin.create(PouchDbMixin, {
let returnList = [];
if (!Ember.isEmpty(visits)) {
visits.forEach(function(visit) {
visit.get(name).then(function(items) {
get(visit, name).then(function(items) {
returnList.addObjects(items);
});
});
Expand Down
1 change: 0 additions & 1 deletion app/models/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export default AbstractModel.extend({
reportDate: DS.attr('date'),
customForms: DS.attr('custom-forms'),
reportType: DS.attr('string'),
nextAppointment: DS.attr('date'),
surgeon: DS.attr('string'),

// Associations
Expand Down
4 changes: 2 additions & 2 deletions app/procedures/edit/route.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import AddToPatient from 'hospitalrun/mixins/add-to-patient-route';
import AddToPatientRoute from 'hospitalrun/mixins/add-to-patient-route';
import ChargeRoute from 'hospitalrun/mixins/charge-route';
import Ember from 'ember';
import { translationMacro as t } from 'ember-i18n';

export default AbstractEditRoute.extend(AddToPatient, ChargeRoute, {
export default AbstractEditRoute.extend(AddToPatientRoute, ChargeRoute, {
editTitle: t('procedures.titles.edit'),
modelName: 'procedure',
newTitle: t('procedures.titles.new'),
Expand Down
28 changes: 18 additions & 10 deletions app/reports/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import PatientSubmodule from 'hospitalrun/mixins/patient-submodule';
import PatientDiagnosis from 'hospitalrun/mixins/patient-diagnosis';
import PouchDbMixin from 'hospitalrun/mixins/pouchdb';

const {
get,
set
} = Ember;

export default AbstractEditController.extend(PatientSubmodule, PatientDiagnosis, PouchDbMixin, {
lookupListsToUpdate: [{
name: 'physicianList',
Expand All @@ -26,7 +31,7 @@ export default AbstractEditController.extend(PatientSubmodule, PatientDiagnosis,
diagnosisList: Ember.computed.alias('visitsController.diagnosisList'),

additionalButtons: Ember.computed('model.{isNew}', function() {
let isNew = this.get('model.isNew');
let isNew = get(this, 'model.isNew');
if (!isNew) {
return [{
class: 'btn btn-primary on-white',
Expand All @@ -40,23 +45,26 @@ export default AbstractEditController.extend(PatientSubmodule, PatientDiagnosis,
updateCapability: 'add_report',

beforeUpdate() {
return new Ember.RSVP.Promise(function(resolve) {
if (this.get('model.isNew')) {
if (this.get('model.visit.outPatient')) {
this.get('model').set('reportType', 'OPD Report');
return new Ember.RSVP.Promise((resolve) => {
let model = get(this, 'model');
if (get(model, 'isNew')) {
if (get(this, 'model.visit.outPatient')) {
set(model, 'reportType', 'OPD Report');
} else {
this.get('model').set('reportType', 'Discharge Report');
set(model, 'reportType', 'Discharge Report');
}
}
resolve();
}.bind(this));
});
},

afterUpdate() {
let alertTitle = this.get('i18n').t('reports.titles.saved');
let alertMessage = this.get('i18n').t('reports.messages.saved');
let alertTitle = get(this, 'i18n').t('reports.titles.saved');
let alertMessage = get(this, 'i18n').t('reports.messages.saved');
this.saveVisitIfNeeded(alertTitle, alertMessage);
let editTitle = this.get('model.visit.outPatient') ? this.get('i18n').t('reports.opd.titles.edit') : this.get('i18n').t('reports.discharge.titles.edit');
let opdTitle = get(this, 'i18n').t('reports.opd.titles.edit');
let dischargeTitle = get(this, 'i18n').t('reports.discharge.titles.edit');
let editTitle = get(this, 'model.visit.outPatient') ? opdTitle : dischargeTitle;
let sectionDetails = {};
sectionDetails.currentScreenTitle = editTitle;
this.send('setSectionHeader', sectionDetails);
Expand Down
41 changes: 23 additions & 18 deletions app/reports/edit/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import Ember from 'ember';
import { translationMacro as t } from 'ember-i18n';
import PatientVisits from 'hospitalrun/mixins/patient-visits';

const {
get,
set
} = Ember;

export default AbstractEditRoute.extend(AddToPatientRoute, PatientVisits, {
modelName: 'report',
customForms: Ember.inject.service(),
Expand All @@ -13,51 +18,51 @@ export default AbstractEditRoute.extend(AddToPatientRoute, PatientVisits, {
reportDate: new Date(),
customForms: Ember.Object.create()
};
let customForms = this.get('customForms');
let customForms = get(this, 'customForms');
return customForms.setDefaultCustomForms(['opdReport', 'dischargeReport'], newReportData);
},

getScreenTitle(model) {
let state = model.get('isNew') ? 'new' : 'edit';
let type = model.get('visit.outPatient') ? 'opd' : 'discharge';
let state = get(model, 'isNew') ? 'new' : 'edit';
let type = get(model, 'visit.outPatient') ? 'opd' : 'discharge';
return t(`reports.${type}.titles.${state}`);
},

getDiagnosisContainer(visit) {
if (visit.get('outPatient')) {
if (get(visit, 'outPatient')) {
return visit;
}
return null;
},

getCurrentOperativePlan(patient) {
let operativePlans = patient.get('operativePlans');
let operativePlans = get(patient, 'operativePlans');
return operativePlans.findBy('isPlanned', true);
},

afterModel(model) {
if (!model.get('isNew')) {
let patient = model.get('visit.patient');
model.set('patient', patient);
if (!get(model, 'isNew')) {
let patient = get(model, 'visit.patient');
set(model, 'patient', patient);
}
if (!model.get('visit')) {
if (!get(model, 'visit')) {
return this.transitionTo('patients');
}
},

setupController(controller, model) {
this._super(controller, model);
let visit = model.get('visit');
let patient = model.get('patient');
let isOutPatient = visit.get('outPatient');
controller.set('visit', visit);
controller.set('isOutPatient', isOutPatient);
controller.set('diagnosisContainer', this.getDiagnosisContainer(visit));
controller.set('currentOperativePlan', this.getCurrentOperativePlan(patient));
let visit = get(model, 'visit');
let patient = get(model, 'patient');
let isOutPatient = get(visit, 'outPatient');
set(controller, 'visit', visit);
set(controller, 'isOutPatient', isOutPatient);
set(controller, 'diagnosisContainer', this.getDiagnosisContainer(visit));
set(controller, 'currentOperativePlan', this.getCurrentOperativePlan(patient));
if (isOutPatient) {
controller.set('nextAppointments', this.getPatientFutureAppointment(model.get('visit'), true));
set(controller, 'nextAppointments', this.getPatientFutureAppointment(visit, true));
} else {
controller.set('nextAppointment', this.getPatientFutureAppointment(model.get('visit')));
set(controller, 'nextAppointment', this.getPatientFutureAppointment(visit));
}
}
});
22 changes: 12 additions & 10 deletions app/reports/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,18 @@
{{/if}}

{{#if visit.patientNotes}}
<label class="ps-info-label">{{t 'reports.form.notes.title' }}</label>
<ul>
{{#each visit.patientNotes as |note|}}
<li>
<b>{{t 'reports.form.notes.date' }}:</b> {{date-format note.date}}<br>
<b>{{t 'reports.form.notes.author' }}:</b> {{note.authoredBy}}<br>
<b>{{note.noteType}}: {{note.content}}</b>
</li>
{{/each}}
</ul>
<div class="ps-info-group test-notes">
<label class="ps-info-label test-notes-label">{{t 'reports.form.notes.title' }}</label>
<ul>
{{#each visit.patientNotes as |note|}}
<li class="test-notes-data">
<b>{{t 'reports.form.notes.date' }}:</b> {{date-format note.date}}<br>
<b>{{t 'reports.form.notes.author' }}:</b> {{note.authoredBy}}<br>
<b>{{note.noteType}}: {{note.content}}</b>
</li>
{{/each}}
</ul>
</div>
{{/if}}

{{#if nextAppointment}}
Expand Down
7 changes: 4 additions & 3 deletions app/services/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import UnauthorizedError from 'hospitalrun/utils/unauthorized-error';
import enviroment from './../config/environment';

const {
get,
isEmpty
} = Ember;

Expand All @@ -23,13 +24,13 @@ export default Ember.Service.extend({
this.set('setMainDB', true);
})
.then(() => {
this.createSampleDocs([enviroment.hospitalInfoDoc]);
this.createOptionHeader([enviroment.hospitalInfoDoc]);
});
},

createSampleDocs(docs) {
createOptionHeader(docs) {
return new Ember.RSVP.Promise((resolve, reject) => {
let mainDB = this.get('mainDB');
let mainDB = get(this, 'mainDB');
let ids = docs.map((doc) => {
return doc._id;
});
Expand Down
8 changes: 6 additions & 2 deletions app/users/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import Ember from 'ember';
import UserRoles from 'hospitalrun/mixins/user-roles';
import uuid from 'npm:uuid';

const {
get
} = Ember;

export default AbstractEditController.extend(UserRoles, {
usersController: Ember.inject.controller('users/index'),
updateCapability: 'add_user',
Expand Down Expand Up @@ -39,8 +43,8 @@ export default AbstractEditController.extend(UserRoles, {
updateModel.set('userPrefix', prefix);
}
updateModel.save().then(() => {
this.displayAlert(this.get('i18n').t('messages.userSaved'), this.get('i18n').t('messages.userHasBeenSaved'));
let editTitle = this.get('i18n').t('labels.editUser');
this.displayAlert(get(this, 'i18n').t('messages.userSaved'), get(this, 'i18n').t('messages.userHasBeenSaved'));
let editTitle = get(this, 'i18n').t('labels.editUser');
let sectionDetails = {};
sectionDetails.currentScreenTitle = editTitle;
this.send('setSectionHeader', sectionDetails);
Expand Down
8 changes: 5 additions & 3 deletions app/visits/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export default AbstractEditController.extend(AddNewPatient, ChargeActions, Diagn
return [buttonProps];
}
}),

noReport: false,

canAddAppointment: computed('model.isNew', function() {
return (!this.get('model.isNew') && this.currentUserCan('add_appointment'));
}),
Expand Down Expand Up @@ -65,9 +67,9 @@ export default AbstractEditController.extend(AddNewPatient, ChargeActions, Diagn
return this.currentUserCan('add_vitals');
}.property(),

canAddReport: function() {
canAddReport: computed('hasReport', function() {
return this.currentUserCan('add_report') && !this.get('hasReport');
}.property('hasReport'),
}),

canDeleteImaging: function() {
return this.currentUserCan('delete_imaging');
Expand Down Expand Up @@ -406,7 +408,7 @@ export default AbstractEditController.extend(AddNewPatient, ChargeActions, Diagn
},

editReport(report) {
report.set('returnToVisit', this.get('model.id'));
set(report, 'returnToVisit', get(this, 'model.id'));
this.transitionToRoute('reports.edit', report);
},

Expand Down
20 changes: 13 additions & 7 deletions app/visits/edit/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import PatientListRoute from 'hospitalrun/mixins/patient-list-route';
import PatientVisit from 'hospitalrun/mixins/patient-visits';
import DS from 'ember-data';

const {
get,
set,
isEmpty
} = Ember;

export default AbstractEditRoute.extend(ChargeRoute, PatientListRoute, PatientVisit, {
customForms: Ember.inject.service(),
editTitle: t('visits.titles.editVisit'),
Expand All @@ -14,11 +20,11 @@ export default AbstractEditRoute.extend(ChargeRoute, PatientListRoute, PatientVi
pricingCategory: 'Ward',

model(params) {
let idParam = this.get('idParam');
if (!Ember.isEmpty(idParam) && params[idParam] === 'checkin') {
let idParam = get(this, 'idParam');
if (!isEmpty(idParam) && params[idParam] === 'checkin') {
return this.getNewData().then((newData) => {
newData.checkIn = true;
let newVisit = this.get('store').createRecord('visit', newData);
let newVisit = get(this, 'store').createRecord('visit', newData);
return newVisit;
});
} else {
Expand Down Expand Up @@ -47,14 +53,14 @@ export default AbstractEditRoute.extend(ChargeRoute, PatientListRoute, PatientVi
setupController(controller, model) {
let promise = this.store.query('report', {
options: {
key: model.get('id')
key: get(model, 'id')
},
mapReduce: 'report_by_visit'
}).then((reports) => {
controller.set('noReport', Ember.isEmpty(reports));
return Ember.isEmpty(reports) ? '' : reports.get('firstObject');
set(controller, 'noReport', isEmpty(reports));
return isEmpty(reports) ? '' : get(reports, 'firstObject');
});
controller.set('report', DS.PromiseObject.create({ promise }));
set(controller, 'report', DS.PromiseObject.create({ promise }));
this._super(controller, model);
},

Expand Down
Loading

0 comments on commit 7895b24

Please sign in to comment.