Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed bug that has to do with page header title #13

Merged
merged 13 commits into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/admin/custom-forms/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ export default AbstractEditController.extend({
'patient',
'socialwork',
'visit',
'opdReport'
'opdReport',
'dischargeReport'
],

formTypes: computed(function() {
Expand Down
9 changes: 6 additions & 3 deletions app/locales/en/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export default {
text: 'Text',
textarea: 'Large Text',
visitFormType: 'Visit',
opdReportFormType: 'Outpatient Report'
opdReportFormType: 'Outpatient Report',
dischargeReportFormType: 'Discharge Report'
},
messages: {
deleteForm: 'Are you sure you want to delete this custom form?',
Expand Down Expand Up @@ -1104,11 +1105,13 @@ export default {
},
reports: {
titles: {
preview: 'Preview Report',
followup: 'Create Followup appointment',
saved: 'The report has been saved'
},
form: {
visitDate: 'Date of Visit',
dischargeDate: 'Date of Discharge',
notes: 'Notes',
primaryDiagnosis: 'Primary Diagnosis',
secondaryDiagnosis: 'Secondary Diagnosis',
procedures: 'Procedures',
Expand All @@ -1130,7 +1133,7 @@ export default {
}
},
messages: {
deleteMedication: 'Are you sure you want to delete this medication?',
followup: 'Create new followup appointment for the discharge report',
delete: 'Are you sure you wish to delete this report?',
saved: 'The report has been saved.'
}
Expand Down
28 changes: 27 additions & 1 deletion app/mixins/patient-visits.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Ember from 'ember';
import PouchDbMixin from 'hospitalrun/mixins/pouchdb';
import VisitStatus from 'hospitalrun/utils/visit-statuses';

import DS from 'ember-data';
import moment from 'moment';
const {
isEmpty
} = Ember;
Expand All @@ -20,6 +21,31 @@ export default Ember.Mixin.create(PouchDbMixin, {
});
},

getPatientFutureAppointment(visit) {
let patientId = visit.get('patient.id');
let visitDate = visit.get('startDate');
let maxValue = this.get('maxValue');
let promise = this.store.query('appointment', {
options: {
startkey: [patientId, null, null, 'appointment_'],
endkey: [patientId, maxValue, maxValue, maxValue]
},
mapReduce: 'appointments_by_patient'
}).then(function(result) {
let futureAppointments = result.filter(function(data) {
let startDate = data.get('startDate');
return startDate && moment(startDate).isAfter(moment(visitDate), 'day');
}).sortBy('startDate');
if (!futureAppointments.length) {
return '';
}
let [appointment] = futureAppointments;
let res = appointment.get('startDate');
return res;
});
return DS.PromiseObject.create({ promise });
},

checkoutVisit(visit, status) {
visit.set('status', status);
visit.set('endDate', new Date());
Expand Down
11 changes: 10 additions & 1 deletion app/models/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default AbstractModel.extend({
customForms: DS.attr('custom-forms'),
reportType: DS.attr('string'),
nextAppointment: DS.attr('date'),
diagnosis: DS.attr(),
surgeon: DS.attr('string'),

// Associations
visit: DS.belongsTo('visit', { async: false }),
Expand All @@ -19,6 +19,15 @@ export default AbstractModel.extend({

reportDate: {
presence: true
},

surgeon: {
presence: {
'if'(object) {
return !object.get('visit.outPatient');
},
message: 'Please select a surgeon'
}
}
}
});
44 changes: 12 additions & 32 deletions app/reports/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import Ember from 'ember';
import PatientSubmodule from 'hospitalrun/mixins/patient-submodule';
import PatientDiagnosis from 'hospitalrun/mixins/patient-diagnosis';
import PouchDbMixin from 'hospitalrun/mixins/pouchdb';
import DS from 'ember-data';
import moment from 'moment';
import PatientVisit from 'hospitalrun/mixins/patient-visits';

export default AbstractEditController.extend(PatientSubmodule, PatientDiagnosis, PouchDbMixin, {
lookupListsToUpdate: [],
export default AbstractEditController.extend(PatientSubmodule, PatientDiagnosis, PouchDbMixin, PatientVisit, {
lookupListsToUpdate: [{
name: 'physicianList',
property: 'model.surgeon',
id: 'physician_list'
}],

visitsController: Ember.inject.controller('visits'),
newReport: false,
physicianList: Ember.computed.alias('visitsController.physicianList'),

visitController: Ember.inject.controller('visits'),

Expand All @@ -29,32 +34,10 @@ export default AbstractEditController.extend(PatientSubmodule, PatientDiagnosis,
}),

nextAppointment: Ember.computed('model', function() {
let patientId = this.get('model.visit.patient.id');
let visitDate = this.get('model.visit.startDate');
let maxValue = this.get('maxValue');
let promise = this.store.query('appointment', {
options: {
startkey: [patientId, null, null, 'appointment_'],
endkey: [patientId, maxValue, maxValue, maxValue]
},
mapReduce: 'appointments_by_patient'
}).then(function(result) {
let futureAppointments = result.filter(function(data) {
let startDate = data.get('startDate');
return startDate && moment(startDate).isAfter(moment(visitDate), 'day');
}).sortBy('startDate');
if (!futureAppointments.length) {
return '';
}
let [appointment] = futureAppointments;
let res = appointment.get('startDate');
return res;
});
return DS.PromiseObject.create({ promise });
return this.getPatientFutureAppointment(this.get('model.visit'));
}),

additionalButtons: Ember.computed('model.{isNew}', function() {
// let i18n = get(this, 'i18n');
let isNew = this.get('model.isNew');
if (!isNew) {
return [{
Expand All @@ -71,14 +54,11 @@ export default AbstractEditController.extend(PatientSubmodule, PatientDiagnosis,
beforeUpdate() {
return new Ember.RSVP.Promise(function(resolve) {
if (this.get('model.isNew')) {

let appointmentDate = this.get('nextAppointment').get('content');
this.get('model').set('nextAppointment', appointmentDate);
if (this.get('model.visit.outPatient')) {
this.get('model').set('reportType', 'OPD Report');
let appointmentDate = this.get('nextAppointment').get('content');
this.get('model').set('nextAppointment', appointmentDate);
this.get('model').set('diagnosis', this.get('diagnosis'));
} else {
// update discharge report properties
this.get('model').set('reportType', 'Discharge Report');
}
}
Expand Down
20 changes: 19 additions & 1 deletion app/reports/edit/route.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import Ember from 'ember';
import { translationMacro as t } from 'ember-i18n';

export default AbstractEditRoute.extend({
modelName: 'report',
Expand All @@ -11,7 +12,24 @@ export default AbstractEditRoute.extend({
customForms: Ember.Object.create()
};
let customForms = this.get('customForms');
return customForms.setDefaultCustomForms(['opdReport'], newReportData);
return customForms.setDefaultCustomForms(['opdReport', 'dischargeReport'], newReportData);
},

afterModel(model) {
if (model.get('isNew')) {
let visit = this.modelFor('visits.edit');
if (!visit) {
return this.transitionTo('patients');
}
model.set('visit', visit);
}
model.setProperties({ returnToVisit: model.get('visit.id') });
},

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

setupController(controller, model) {
Expand Down
43 changes: 36 additions & 7 deletions app/reports/edit/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<span>{{headerLine3}}</span><br>
{{/if}}
</div>
{{#if model.visit.outPatient}}
<div class="opd-report">
{{#edit-panel editPanelProps=editPanelProps}}
{{#em-form model=model submitButton=false }}
Expand All @@ -35,6 +34,34 @@
</div>
{{/if}}

{{#unless model.visit.outPatient}}
<div class="ps-info-group">
<p class="ps-info-label">{{t 'reports.form.dischargeDate' }}</p>
{{date-format model.reportDate format="DD/MM/YYYY hh:mm a"}}
</div>
{{/unless}}

{{#unless model.visit.outPatient}}
<div class="row">
{{select-or-typeahead className="col-sm-4" property="surgeon"
label=(t "operativePlan.labels.surgeon") list=physicianList
selection=model.surgeon
class="plan-surgeon"
}}
</div>
{{/unless}}

{{#unless model.visit.outPatient}}
{{#if model.visit.notes}}
<div class="ps-info-group">
<label class="ps-info-label">{{t 'reports.form.notes' }}</label>
<ul>
<li>{{model.visit.notes}}</li>
</ul>
</div>
{{/if}}
{{/unless}}

{{#if diagnosis.primary.length}}
<div class="ps-info-group">
<label class="ps-info-label">{{t 'reports.form.primaryDiagnosis' }}</label>
Expand Down Expand Up @@ -62,7 +89,7 @@
<label class="ps-info-label">{{t 'reports.form.procedures' }}</label>
<ul>
{{#each model.visit.procedures as |item|}}
<li>{{item.description}}</li>
<li>{{item.description}} {{#if item.procedureDate }} - {{date-format item.procedureDate format="DD/MM/YYYY"}} {{/if}}</li>
{{/each}}
</ul>
</div>
Expand Down Expand Up @@ -111,12 +138,14 @@
</div>
{{/if}}

{{custom-form-manager model=model formType="opdReport"}}
{{#if model.visit.outPatient}}
{{custom-form-manager model=model formType="opdReport"}}
{{else}}
{{custom-form-manager model=model formType="dischargeReport"}}
{{/if}}



{{/em-form}}
{{/edit-panel}}
</div>

{{else}}

{{/if}}
27 changes: 11 additions & 16 deletions app/visits/edit/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import PatientSubmodule from 'hospitalrun/mixins/patient-submodule';
import UserSession from 'hospitalrun/mixins/user-session';
import VisitStatus from 'hospitalrun/utils/visit-statuses';
import VisitTypes from 'hospitalrun/mixins/visit-types';
import { translationMacro as t } from 'ember-i18n';

const {
computed,
Expand Down Expand Up @@ -38,6 +37,7 @@ export default AbstractEditController.extend(AddNewPatient, ChargeActions, Diagn
}
}),
noReport: false,
nextAppointment: null,
canAddAppointment: computed('model.isNew', function() {
return (!this.get('model.isNew') && this.currentUserCan('add_appointment'));
}),
Expand Down Expand Up @@ -437,24 +437,19 @@ export default AbstractEditController.extend(AddNewPatient, ChargeActions, Diagn
},

newReport() {
let that = this;
this._addChildObject('reports.edit', (newRoute) => {
let controller = newRoute.controllerFor('visits');
let isOutPatient = that.get('model').get('outPatient');
controller.set('currentScreenTitle', isOutPatient ? t('reports.opd.titles.new') : t('reports.discharge.titles.new'));
});
let next = this.get('nextAppointment.content');
if (!this.get('model.outPatient') && !next) {
let i18n = this.get('i18n');
let updateMesage = i18n.t('reports.messages.followup');
let updateTitle = i18n.t('reports.titles.followup');
this.displayAlert(updateTitle, updateMesage);
return false;
}
this._addChildObject('reports.edit');
},

editReport() {
let that = this;
this.transitionToRoute('reports.edit', this.get('report.id'))
.then(function(newRoute) {
let controller = newRoute.controllerFor('visits');
newRoute.currentModel.setProperties({ returnToVisit: that.get('model.id')
});
let isOutPatient = that.get('model').get('outPatient');
controller.set('currentScreenTitle', isOutPatient ? t('reports.opd.titles.edit') : t('reports.discharge.titles.edit'));
});
this.transitionToRoute('reports.edit', this.get('report.id'));
},

newAppointment() {
Expand Down
4 changes: 3 additions & 1 deletion app/visits/edit/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import ChargeRoute from 'hospitalrun/mixins/charge-route';
import Ember from 'ember';
import PatientListRoute from 'hospitalrun/mixins/patient-list-route';
import PatientVisit from 'hospitalrun/mixins/patient-visits';
import DS from 'ember-data';

export default AbstractEditRoute.extend(ChargeRoute, PatientListRoute, {
export default AbstractEditRoute.extend(ChargeRoute, PatientListRoute, PatientVisit, {
customForms: Ember.inject.service(),
editTitle: t('visits.titles.editVisit'),
modelName: 'visit',
Expand Down Expand Up @@ -58,6 +59,7 @@ export default AbstractEditRoute.extend(ChargeRoute, PatientListRoute, {
return Ember.isEmpty(reports) ? '' : reports.get('firstObject');
});
controller.set('report', DS.PromiseObject.create({ promise }));
controller.set('nextAppointment', this.getPatientFutureAppointment(model));
this._super(controller, model);
},

Expand Down