...
 
Commits (4)
......@@ -7,7 +7,7 @@ import PatientValidation from 'hospitalrun/utils/patient-validation';
export default AbstractModel.extend(CanEditRequested, DateFormat, {
// Attributes
prescriptionDate: DS.attr('date'),
requestedBy: DS.attr('string'),
// requestedBy: DS.attr('string'),
// Asociations
patient: DS.belongsTo('patient'),
......
import { inject as controller } from '@ember/controller';
import { Promise as EmberPromise } from 'rsvp';
// import { isEmpty } from '@ember/utils';
import AddNewPatient from 'hospitalrun/mixins/add-new-patient';
import AbstractEditController from 'hospitalrun/controllers/abstract-edit-controller';
// import Ember from 'ember';
import PatientSubmodule from 'hospitalrun/mixins/patient-submodule';
import UserSession from 'hospitalrun/mixins/user-session';
let toothList = [];
const BUTTONS_GROUP_ID = ['fractura', 'obturacion', 'extraccion', 'extraer', 'puente', 'borrar'];
export default AbstractEditController.extend(PatientSubmodule, UserSession, {
export default AbstractEditController.extend(AddNewPatient, PatientSubmodule, UserSession, {
findPatientVisits: false,
showUpdateButton: true,
odontogramController: controller('odontogram'),
......@@ -39,6 +41,8 @@ export default AbstractEditController.extend(PatientSubmodule, UserSession, {
let element = document.getElementById(id);
let parent = element.parentElement;
let btnActive = this.setBtnActive(procedureTypes);
let ftooth = undefined;
let stooth = undefined;
let tooth = {
code: toothCode,
......@@ -171,6 +175,11 @@ export default AbstractEditController.extend(PatientSubmodule, UserSession, {
case 'extraer':
break;
case 'puente':
if (!ftooth) {
ftooth = toothCode;
} else if (!stooth) {
stooth = toothCode;
}
break;
case 'borrar':
break;
......@@ -189,10 +198,6 @@ export default AbstractEditController.extend(PatientSubmodule, UserSession, {
}
},
/**
* Devuelve el elemento html del procedimiento cuyo boton esta activo
* @param {*} procedureTypes
*/
setBtnActive(procedureTypes) {
for (let i = 0; i < procedureTypes.children.length; i++) {
if (procedureTypes.children[i].classList.contains('active')) {
......@@ -244,6 +249,67 @@ export default AbstractEditController.extend(PatientSubmodule, UserSession, {
}
},
beforeUpdate() {
// return new EmberPromise(function(resolve, reject) {
// if (this.get('model.isNew')) {
// let newOdontogram = this.get('model');
// return newOdontogram.validate().then(() => {
// if (newOdontogram.get('isValid')) {
// let patient = newOdontogram.get('patient');
// if (isEmpty(patient)) {
// this.addNewPatient();
// return reject({
// ignore: true,
// message: 'creating new patient first'
// });
// }
// this.set('model.prescriptionDate', new Date());
// this.set('model.requestedBy', this.getUserName());
// console.log(newOdontogram);
// }
// });
// } else {
// resolve();
// }
// }.bind(this));
if (this.get('model.isNew')) {
return new EmberPromise(function(resolve, reject) {
let odontogram = this.get('model');
let tooths = [];
toothList.map((t) => {
let tooth = this.get('store').createRecord('tooth', {
code: t.code,
odontogram: odontogram.get('id')
});
let procs = [];
t.procedures.map((p) => {
let procedure = this.get('store').createRecord('dentistry-procedure', {
tooth: tooth.id,
type: p.type,
bottom: (p.regions.indexOf('b') >= 0) ? true : false,
center: (p.regions.indexOf('c') >= 0) ? true : false,
left: (p.regions.indexOf('l') >= 0) ? true : false,
right: (p.regions.indexOf('r') >= 0) ? true : false,
top: (p.regions.indexOf('t') >= 0) ? true : false
});
procs.push(procedure);
});
tooth.set('procedures', procs);
tooths.push(tooth);
});
odontogram.set('tooths', tooths);
odontogram.save().then(() => {
resolve(odontogram);
}).catch((err) => {
reject(err);
});
}.bind(this));
}
},
deleteToGlobalList(tooth) {
if (toothList.length !== 0) {
toothList.map((t) => {
......@@ -260,40 +326,5 @@ export default AbstractEditController.extend(PatientSubmodule, UserSession, {
editNewItem() {
this.send('editItem', this.get('model.id'));
},
update() {
if (this.get('model.isNew')) {
let odontogram = this.get('store').createRecord('odontogram', {
patient: this.get('model').get('patient')
});
let tooths = [];
toothList.map((t) => {
let tooth = this.get('store').createRecord('tooth', {
code: t.code,
odontogram: odontogram.get('id')
});
let procs = [];
t.procedures.map((p) => {
let procedure = this.get('store').createRecord('dentistry-procedure', {
tooth: tooth.id,
type: p.type,
bottom: (p.regions.indexOf('b') >= 0) ? true : false,
center: (p.regions.indexOf('c') >= 0) ? true : false,
left: (p.regions.indexOf('l') >= 0) ? true : false,
right: (p.regions.indexOf('r') >= 0) ? true : false,
top: (p.regions.indexOf('t') >= 0) ? true : false
});
procs.push(procedure);
});
tooth.set('procedures', procs);
tooths.push(tooth);
});
odontogram.set('tooths', tooths);
this.set('odontogram', odontogram);
this.saveModel();
}
}
});
\ No newline at end of file
import AbstractEditRoute from 'hospitalrun/routes/abstract-edit-route';
import AddToPatientRoute from 'hospitalrun/mixins/add-to-patient-route';
import ChargeRoute from 'hospitalrun/mixins/charge-route';
import Ember from 'ember';
import moment from 'moment';
import PatientListRoute from 'hospitalrun/mixins/patient-list-route';
import { translationMacro as t } from 'ember-i18n';
import { resolve } from 'rsvp';
import { isEmpty } from '@ember/utils';
export default AbstractEditRoute.extend(AddToPatientRoute, ChargeRoute, PatientListRoute, {
editTitle: t('odontogram.titles.editTitle'),
......@@ -21,9 +21,27 @@ export default AbstractEditRoute.extend(AddToPatientRoute, ChargeRoute, PatientL
},
getNewData() {
return Ember.RSVP.resolve({
selectPatient: true,
prescriptionDate: moment().startOf('day').toDate()
});
let newData = {
selectPatient: false,
prescriptionDate: new Date()
};
return resolve(newData);
},
model(params) {
let idParam = this.get('idParam');
let modelId = params[idParam];
if (!isEmpty(idParam) && (modelId.indexOf('new') === 0)) {
if (!isEmpty(params.forPatientId)) {
let modelPromise = this._super(params);
return this._setPatientOnModel(modelPromise, params.forPatientId);
} else {
return this._createNewRecord(params);
}
} else {
return this._super(params);
}
}
});
\ No newline at end of file
......@@ -468,7 +468,7 @@
<div class="panel-heading">
<button type="button" class="btn btn-primary align-right" {{action "newOdontogram" bubbles=false}}>
<span class="octicon octicon-plus"></span>{{t 'patients.buttons.newOdontogram'}}
</button>
</button>&nbsp;
</div>
{{/if}}
<div class="panel-body detail-section-content">
......
<table class="table">
<tr class="table-header">
<th>{{t 'labels.date'}}</th>
<th>{{t 'labels.requestedBy'}}</th>
<th>{{t 'visits.labels.examiner'}}</th>
<th>{{t 'labels.actions'}}</th>
</tr>
{{#each patientOdontograms as |odontogram|}}
{{#each model.odontograms as |odontogram|}}
<tr {{action "editOdontogram" odontogram}} class="{{if odontogram.canEdit (if canAddOdontogram "clickable")}}">
<td>{{date-format odontogram.prescriptionDate}}</td>
<td>{{odontogram.status}}</td>
<td>{{odontogram.prescription}}</td>
<td>{{odontogram.requestedBy}}</td>
<td>
{{#if odontogram.canEdit}}
{{#if canAddOdontogram}}
......
......@@ -5,14 +5,14 @@ PORT="5984"
if [ -z "${1}" ] || [ -z "${2}" ]; then
HOST="http://$URL:$PORT"
curl -X PUT $HOST/_config/admins/hradmin -d '"test"'
SECUREHOST="http://hradmin:test@$URL:$PORT"
curl -X PUT $HOST/_config/admins/couchadmin -d '"test"'
SECUREHOST="http://couchadmin:test@$URL:$PORT"
else
SECUREHOST="http://$1:$2@$URL:$PORT"
fi
echo "Setting up security on _users db"
curl -X PUT $SECUREHOST/_users/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": ["admin"]}}'
curl -X PUT $SECUREHOST/_users/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": []}}'
echo "Setting up HospitalRun config DB"
curl -X PUT $SECUREHOST/config
curl -X PUT $SECUREHOST/config/_security -d '{ "admins": { "names": [], "roles": ["admin"]}, "members": { "names": [], "roles": []}}'
......