-
Notifications
You must be signed in to change notification settings - Fork 104
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
Patient document preview #452
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
angular.module('bhima.components') | ||
.component('bhFindDocument', { | ||
controller : FindDocumentComponent, | ||
controllerAs : '$ctrl', | ||
templateUrl : 'partials/templates/bhFindDocument.tmpl.html', | ||
bindings: { | ||
enablePatientDetails : '<', // bind boolean (true|false) : Enable patient details option | ||
enableOptionBar : '<', // bind boolean (true|false) : Enable option for add, display list or display thumbnail in a bar | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can most of these options be bound as attributes |
||
enableSearch : '<', // bind boolean (true|false) : Enable search bar option | ||
display : '@', // bind (list|thumbnail) : Display either in list or thumbnail mode | ||
patientUuid : '<' // Required patient uuid | ||
} | ||
}); | ||
|
||
FindDocumentComponent.$inject = [ | ||
'PatientService', 'ModalService', 'DocumentService', | ||
'NotifyService', 'UserService', '$translate' | ||
]; | ||
|
||
/** | ||
* Find Document Component | ||
* This component is responsible for displaying documents for specific patient given | ||
*/ | ||
function FindDocumentComponent(Patient, Modal, Document, Notify, User, $translate) { | ||
var vm = this; | ||
|
||
/** global variables */ | ||
vm.session = { | ||
patientUuid : this.patientUuid, | ||
enablePatientDetails : Boolean(this.enablePatientDetails), | ||
enableOptionBar : Boolean(this.enableOptionBar), | ||
enableSearch : Boolean(this.enableSearch), | ||
display : this.display, | ||
showAction : false | ||
}; | ||
|
||
/** expose to the view */ | ||
vm.switchDisplay = switchDisplay; | ||
vm.toggleAction = toggleAction; | ||
vm.addDocument = addDocument; | ||
vm.deleteDocument = deleteDocument; | ||
vm.mimeIcon = mimeIcon; | ||
|
||
// startup the component | ||
startup(); | ||
|
||
/** function switchDisplay */ | ||
function switchDisplay(mode) { | ||
vm.session.display = mode; | ||
} | ||
|
||
/** toggle document actions */ | ||
function toggleAction(index) { | ||
vm.selectedIndex = index; | ||
vm.session.showAction = vm.session.showAction === true ? false : true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An easier way to do this in the future would be this: vm.session.showAction = !vm.session.showAction; |
||
} | ||
|
||
/** function add documents modal */ | ||
function addDocument() { | ||
Modal.openUploadDocument({ patient_uuid: vm.session.patientUuid }) | ||
.then(startup); | ||
} | ||
|
||
/** delete document */ | ||
function deleteDocument(uuid) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a delete modal implemented in bootstrap by @lomamech. Here is the code. Could you use it instead? See #150 for the reasons why. |
||
Modal.confirm($translate.instant('FORM.DIALOGS.CONFIRM_DELETE')) | ||
.then(function (ans) { | ||
if (!ans) { return; } | ||
|
||
return Document.remove(vm.session.patientUuid, uuid) | ||
.then(function () { | ||
Notify.success('FORM.INFOS.DELETE_SUCCESS'); | ||
startup(); | ||
}); | ||
|
||
}) | ||
.catch(Notify.handleError); | ||
} | ||
|
||
/** getting patient document */ | ||
function startup() { | ||
if (!vm.session.patientUuid) { return; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why should happen if there is not a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, this is fine for now. I wonder if, in the future, we should include an error message saying the patient cannot be found, and perhaps a link to the patient registry. |
||
|
||
Patient.read(vm.session.patientUuid) | ||
.then(function (patient) { | ||
vm.session.patient = patient; | ||
}) | ||
.catch(Notify.handleError); | ||
|
||
Document.read(vm.session.patientUuid) | ||
.then(function (documents) { | ||
vm.session.patientDocuments = documents; | ||
}) | ||
.catch(Notify.handleError); | ||
} | ||
|
||
/** format the image type */ | ||
function mimeIcon(mimetype) { | ||
var result = {}; | ||
|
||
if (mimetype.indexOf('image') > -1) { | ||
result = { icon : 'fa-file-image-o', label : 'Image' }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the future, these labels could be translated. |
||
} else if (mimetype.indexOf('pdf') > -1) { | ||
result = { icon : 'fa-file-pdf-o', label : 'PDF' }; | ||
} else if (mimetype.indexOf('word') > -1) { | ||
result = { icon : 'fa-file-word-o', label : 'MS WORD' }; | ||
} else if (mimetype.indexOf('sheet') > -1) { | ||
result = { icon : 'fa-file-excel-o', label : 'MS EXCEL' }; | ||
} else if (mimetype.indexOf('presentation') > -1) { | ||
result = { icon : 'fa-file-powerpoint-o', label : 'MS Power Point' }; | ||
} else { | ||
result = { icon : 'fa-file-o', label : 'Fichier' }; | ||
}; | ||
|
||
return result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
angular.module('bhima.filters') | ||
.filter('bytes', BytesFilter); | ||
|
||
BytesFilter.$inject = ['$translate']; | ||
|
||
/** | ||
* Bytes Filter | ||
* Format bytes size to human readable format | ||
*/ | ||
function BytesFilter($translate) { | ||
return function(bytes, precision) { | ||
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) { return '-'; } | ||
if (typeof precision === 'undefined') { precision = 1; } | ||
var units = ['SIZE_BYTES', 'SIZE_KB', 'SIZE_MB', 'SIZE_GB', 'SIZE_TB', 'SIZE_TB'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! Another optimization (not necessary for this PR), would be to move the keys and Like: function BytesFilter($translate) {
var units = ['SIZE_BYTES', 'SIZE_KB', 'SIZE_MB', 'SIZE_GB', 'SIZE_TB', 'SIZE_TB'];
units = units.map(function (u) { return 'FORM.LABELS.' + $translate.instant(u); });
return function (bytes, precision) {
// code ....
};
} Just an idea. :) |
||
number = Math.floor(Math.log(bytes) / Math.log(1024)); | ||
|
||
units = units.map(function (unit) { | ||
return $translate.instant('FORM.LABELS.' + unit); | ||
}); | ||
|
||
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍