diff --git a/ui/app/i18n/ot/locale_en.json b/ui/app/i18n/ot/locale_en.json index e28eb4726d..97029a8246 100644 --- a/ui/app/i18n/ot/locale_en.json +++ b/ui/app/i18n/ot/locale_en.json @@ -95,5 +95,7 @@ "OT_SURGICAL_BLOCK_DIALOG_DURATION": "Duration", "OT_FILTER_KEY": "Filter", "OT_SURGICAL_APPOINTMENT_DIALOG_DETAILS": "Surgical Appointment Details", - "OT_SURGICAL_APPOINTMENT_ACTUAL_TIME": "Actual Time" + "OT_SURGICAL_APPOINTMENT_ACTUAL_TIME": "Actual Time", + "OT_SAVE_ANYWAY_KEY": "Save Anyway", + "OT_SURGICAL_BLOCK_MULTIPLE_DAYS_DIALOG_TITLE": "Warning - Creating Surgical Block" } diff --git a/ui/app/ot/controller/calendarViewController.js b/ui/app/ot/controller/calendarViewController.js index d3378e418d..1862efc9ff 100644 --- a/ui/app/ot/controller/calendarViewController.js +++ b/ui/app/ot/controller/calendarViewController.js @@ -214,6 +214,7 @@ angular.module('bahmni.ot') $scope.cancelDisabled = true; $scope.surgicalBlockSelected = surgicalBlock; $scope.surgicalAppointmentSelected = {}; + $scope.showEndDate = (Bahmni.Common.Util.DateUtil.diffInDaysRegardlessOfTime(surgicalBlock.startDatetime, surgicalBlock.endDatetime) != 0); var surgicalBlockWithCompletedAppointments = function () { return _.find(surgicalBlock.surgicalAppointments, function (appointment) { @@ -241,6 +242,7 @@ angular.module('bahmni.ot') $scope.addActualTimeDisabled = true; $scope.surgicalBlockSelected = {}; $scope.surgicalAppointmentSelected = {}; + $scope.showEndDate = false; }; $scope.$on("event:surgicalBlockDeselect", function (event) { diff --git a/ui/app/ot/controller/listViewController.js b/ui/app/ot/controller/listViewController.js index bec32eb520..b2b66e8581 100644 --- a/ui/app/ot/controller/listViewController.js +++ b/ui/app/ot/controller/listViewController.js @@ -77,6 +77,15 @@ angular.module('bahmni.ot') } return mappedAppointment; }); + surgicalBlock.surgicalAppointments = _.filter(surgicalBlock.surgicalAppointments, function (surgicalAppointment) { + if (surgicalAppointment.derivedAttributes.expectedStartTime) { + var surgicalAppointmentStartDateTime = surgicalAppointment.derivedAttributes.expectedStartTime; + var surgicalAppointmentEndDateTime = Bahmni.Common.Util.DateUtil.addMinutes(surgicalAppointmentStartDateTime, surgicalAppointment.derivedAttributes.duration); + return surgicalAppointmentStartDateTime < endDatetime && surgicalAppointmentEndDateTime > startDatetime; + } + return surgicalAppointment.derivedAttributes.expectedStartDate <= endDatetime + && surgicalAppointment.derivedAttributes.expectedStartDate >= startDatetime; + }); return surgicalBlock; }); @@ -100,7 +109,7 @@ angular.module('bahmni.ot') $scope.cancelDisabled = true; $scope.reverseSort = false; $scope.sortColumn = ""; - return $q.all([surgicalAppointmentService.getSurgicalBlocksInDateRange(startDatetime, endDatetime, true)]).then(function (response) { + return $q.all([surgicalAppointmentService.getSurgicalBlocksInDateRange(startDatetime, endDatetime, true, true)]).then(function (response) { $scope.surgicalBlocks = response[0].data.results; filterSurgicalBlocksAndMapAppointmentsForDisplay($scope.surgicalBlocks); }); diff --git a/ui/app/ot/controller/otCalendarController.js b/ui/app/ot/controller/otCalendarController.js index 146a55f483..84076d4658 100644 --- a/ui/app/ot/controller/otCalendarController.js +++ b/ui/app/ot/controller/otCalendarController.js @@ -27,7 +27,7 @@ angular.module('bahmni.ot') updateBlocksStartDatetimeAndBlocksEndDatetime(); $scope.rows = $scope.getRowsForCalendar(); return $q.all([locationService.getAllByTag('Operation Theater'), - surgicalAppointmentService.getSurgicalBlocksInDateRange($scope.blocksStartDatetime, $scope.blocksEndDatetime)]).then(function (response) { + surgicalAppointmentService.getSurgicalBlocksInDateRange($scope.blocksStartDatetime, $scope.blocksEndDatetime, false, true)]).then(function (response) { $scope.locations = response[0].data.results; $scope.weekDates = $scope.getAllWeekDates(); $scope.surgicalBlocksByLocation = _.map($scope.locations, function (location) { @@ -37,13 +37,18 @@ angular.module('bahmni.ot') }); $scope.surgicalBlocksByDate = _.map($scope.weekDates, function (weekDate) { return _.filter(response[1].data.results, function (surgicalBlock) { - return Bahmni.Common.Util.DateUtil.isSameDate(moment(surgicalBlock.startDatetime).startOf('day').toDate(), weekDate); + return $scope.isSurgicalBlockActiveOnGivenDate(surgicalBlock, weekDate); }); }); $scope.blockedOtsOfTheWeek = getBlockedOtsOfTheWeek(); }); }; + $scope.isSurgicalBlockActiveOnGivenDate = function (surgicalBlock, weekDate) { + return Bahmni.Common.Util.DateUtil.isSameDate(moment(surgicalBlock.startDatetime).startOf('day').toDate(), weekDate) + || moment(surgicalBlock.endDatetime).toDate() > weekDate; + }; + $scope.intervals = function () { var dayStart = ($scope.dayViewStart || '00:00').split(':'); var dayEnd = ($scope.dayViewEnd || '23:59').split(':'); diff --git a/ui/app/ot/controller/surgicalBlockController.js b/ui/app/ot/controller/surgicalBlockController.js index ade02c3952..d73aeebaae 100644 --- a/ui/app/ot/controller/surgicalBlockController.js +++ b/ui/app/ot/controller/surgicalBlockController.js @@ -65,6 +65,18 @@ angular.module('bahmni.ot') return true; }; + $scope.closeDialog = function () { + ngDialog.close(); + }; + + $scope.saveAnywaysFlag = false; + + $scope.saveAnyways = function (surgicalForm) { + $scope.saveAnywaysFlag = true; + $scope.save(surgicalForm); + ngDialog.close(); + }; + $scope.save = function (surgicalForm) { if (!$scope.isFormValid()) { messagingService.showMessage('error', "{{'OT_ENTER_MANDATORY_FIELDS' | translate}}"); @@ -74,16 +86,27 @@ angular.module('bahmni.ot') messagingService.showMessage('error', "{{'OT_SURGICAL_APPOINTMENT_EXCEEDS_BLOCK_DURATION' | translate}}"); return; } - $scope.updateSortWeight(surgicalForm); - var surgicalBlock = new Bahmni.OT.SurgicalBlockMapper().mapSurgicalBlockUIToDomain(surgicalForm); - var saveOrupdateSurgicalBlock = _.isEmpty(surgicalBlock.uuid) ? surgicalAppointmentService.saveSurgicalBlock : surgicalAppointmentService.updateSurgicalBlock; - spinner.forPromise(saveOrupdateSurgicalBlock(surgicalBlock)).then(function (response) { - $scope.surgicalForm = new Bahmni.OT.SurgicalBlockMapper().map(response.data, $scope.attributeTypes, $scope.surgeons); - $scope.surgicalForm.surgicalAppointments = surgicalAppointmentHelper.filterSurgicalAppointmentsByStatus( - $scope.surgicalForm.surgicalAppointments, [Bahmni.OT.Constants.scheduled, Bahmni.OT.Constants.completed]); - messagingService.showMessage('info', "{{'OT_SAVE_SUCCESS_MESSAGE_KEY' | translate}}"); - $state.go('editSurgicalAppointment', {surgicalBlockUuid: response.data.uuid}); - }); + if ($scope.saveAnywaysFlag || Bahmni.Common.Util.DateUtil.isSameDate(surgicalForm.startDatetime, surgicalForm.endDatetime)) { + $scope.updateSortWeight(surgicalForm); + var surgicalBlock = new Bahmni.OT.SurgicalBlockMapper().mapSurgicalBlockUIToDomain(surgicalForm); + var saveOrupdateSurgicalBlock = _.isEmpty(surgicalBlock.uuid) ? surgicalAppointmentService.saveSurgicalBlock : surgicalAppointmentService.updateSurgicalBlock; + spinner.forPromise(saveOrupdateSurgicalBlock(surgicalBlock)).then(function (response) { + $scope.surgicalForm = new Bahmni.OT.SurgicalBlockMapper().map(response.data, $scope.attributeTypes, $scope.surgeons); + $scope.surgicalForm.surgicalAppointments = surgicalAppointmentHelper.filterSurgicalAppointmentsByStatus( + $scope.surgicalForm.surgicalAppointments, [Bahmni.OT.Constants.scheduled, Bahmni.OT.Constants.completed]); + messagingService.showMessage('info', "{{'OT_SAVE_SUCCESS_MESSAGE_KEY' | translate}}"); + $state.go('editSurgicalAppointment', {surgicalBlockUuid: response.data.uuid}); + }); + $scope.saveAnywaysFlag = false; + } else { + ngDialog.open({ + template: 'views/surgicalBlockMultipleDaysDialog.html', + className: 'ngdialog-theme-default', + closeByNavigation: true, + data: { surgicalForm: surgicalForm }, + scope: $scope + }); + } }; var addOrUpdateTheSurgicalAppointment = function (surgicalAppointment) { diff --git a/ui/app/ot/directives/otCalendarSurgicalAppointment.js b/ui/app/ot/directives/otCalendarSurgicalAppointment.js index 4c1e69e5a1..7d2676f805 100644 --- a/ui/app/ot/directives/otCalendarSurgicalAppointment.js +++ b/ui/app/ot/directives/otCalendarSurgicalAppointment.js @@ -31,7 +31,7 @@ angular.module('bahmni.ot') }; var getHeightForSurgicalAppointment = function () { - return $scope.surgicalAppointment.derivedAttributes.duration * $scope.heightPerMin; + return $scope.surgicalAppointment.derivedAttributes.height * $scope.heightPerMin; }; $scope.selectSurgicalAppointment = function ($event) { diff --git a/ui/app/ot/directives/otCalendarSurgicalBlock.js b/ui/app/ot/directives/otCalendarSurgicalBlock.js index cfd5fb6224..7d72a27382 100644 --- a/ui/app/ot/directives/otCalendarSurgicalBlock.js +++ b/ui/app/ot/directives/otCalendarSurgicalBlock.js @@ -18,7 +18,7 @@ angular.module('bahmni.ot') left: $scope.weekOrDay === 'week' ? getLeftPositionForSurgicalBlock() : 0, color: getColorForProvider(), appointmentHeightPerMin: (surgicalBlockHeight - heightForSurgeonName) / Bahmni.Common.Util.DateUtil.diffInMinutes( - $scope.surgicalBlock.startDatetime, $scope.surgicalBlock.endDatetime) + getSurgicalBlockStartDateTimeBasedOnCalendarStartDateTime(), getSurgicalBlockEndDateTimeBasedOnCalendarEndDateTime()) }; }; @@ -50,12 +50,13 @@ angular.module('bahmni.ot') }; var getHeightForSurgicalBlock = function () { return Bahmni.Common.Util.DateUtil.diffInMinutes( - $scope.surgicalBlock.startDatetime, $scope.surgicalBlock.endDatetime) * surgicalBlockHeightPerMin; + getSurgicalBlockStartDateTimeBasedOnCalendarStartDateTime(), getSurgicalBlockEndDateTimeBasedOnCalendarEndDateTime()) * surgicalBlockHeightPerMin; }; var getTopForSurgicalBlock = function () { - return Bahmni.Common.Util.DateUtil.diffInMinutes( - getCalendarStartDateTime($scope.surgicalBlock.startDatetime), $scope.surgicalBlock.startDatetime) * surgicalBlockHeightPerMin; + var top = Bahmni.Common.Util.DateUtil.diffInMinutes( + getCalendarStartDateTime($scope.viewDate), $scope.surgicalBlock.startDatetime) * surgicalBlockHeightPerMin; + return top > 0 ? top : 0; }; var getCalendarStartDateTime = function (date) { var dayStart = ($scope.dayViewStart || Bahmni.OT.Constants.defaultCalendarStartTime).split(':'); @@ -66,6 +67,17 @@ angular.module('bahmni.ot') var dayEnd = ($scope.dayViewEnd || Bahmni.OT.Constants.defaultCalendarEndTime).split(':'); return Bahmni.Common.Util.DateUtil.addMinutes(moment(date).startOf('day'), (dayEnd[0] * 60 + parseInt(dayEnd[1]))); }; + + var getSurgicalBlockStartDateTimeBasedOnCalendarStartDateTime = function () { + return moment($scope.surgicalBlock.startDatetime).toDate() < getCalendarStartDateTime($scope.viewDate) + ? getCalendarStartDateTime($scope.viewDate) : $scope.surgicalBlock.startDatetime; + }; + + var getSurgicalBlockEndDateTimeBasedOnCalendarEndDateTime = function () { + return getCalendarEndDateTime($scope.viewDate) < moment($scope.surgicalBlock.endDatetime).toDate() + ? getCalendarEndDateTime($scope.viewDate) : $scope.surgicalBlock.endDatetime; + }; + var calculateEstimatedAppointmentDuration = function () { var surgicalAppointments = _.filter($scope.surgicalBlock.surgicalAppointments, function (surgicalAppointment) { return $scope.isValidSurgicalAppointment(surgicalAppointment); @@ -78,6 +90,12 @@ angular.module('bahmni.ot') surgicalAppointment.derivedAttributes.expectedStartDatetime = nextAppointmentStartDatetime; surgicalAppointment.derivedAttributes.expectedEndDatetime = Bahmni.Common.Util.DateUtil.addMinutes(nextAppointmentStartDatetime, surgicalAppointment.derivedAttributes.duration); + surgicalAppointment.derivedAttributes.height = Bahmni.Common.Util.DateUtil.diffInMinutes( + surgicalAppointment.derivedAttributes.expectedStartDatetime < getCalendarStartDateTime($scope.viewDate) + ? getCalendarStartDateTime($scope.viewDate) : surgicalAppointment.derivedAttributes.expectedStartDatetime, + getCalendarEndDateTime($scope.viewDate) < surgicalAppointment.derivedAttributes.expectedEndDatetime + ? getCalendarEndDateTime($scope.viewDate) : surgicalAppointment.derivedAttributes.expectedEndDatetime + ); nextAppointmentStartDatetime = surgicalAppointment.derivedAttributes.expectedEndDatetime; return surgicalAppointment; }); @@ -87,6 +105,12 @@ angular.module('bahmni.ot') return surgicalAppointment.status !== Bahmni.OT.Constants.cancelled && surgicalAppointment.status !== Bahmni.OT.Constants.postponed; }; + $scope.canShowInCalendarView = function (surgicalAppointment) { + return $scope.isValidSurgicalAppointment(surgicalAppointment) + && surgicalAppointment.derivedAttributes.expectedStartDatetime < getCalendarEndDateTime($scope.viewDate) + && surgicalAppointment.derivedAttributes.expectedEndDatetime > getCalendarStartDateTime($scope.viewDate); + }; + $scope.selectSurgicalBlock = function ($event) { $scope.$emit("event:surgicalBlockSelect", $scope.surgicalBlock); $event.stopPropagation(); @@ -119,7 +143,8 @@ angular.module('bahmni.ot') dayViewEnd: "=", dayViewSplit: "=", filterParams: "=", - weekOrDay: "=" + weekOrDay: "=", + viewDate: "=" }, templateUrl: "../ot/views/calendarSurgicalBlock.html" }; diff --git a/ui/app/ot/services/surgicalAppointmentService.js b/ui/app/ot/services/surgicalAppointmentService.js index 60ed62c73d..fdd9e91918 100644 --- a/ui/app/ot/services/surgicalAppointmentService.js +++ b/ui/app/ot/services/surgicalAppointmentService.js @@ -50,13 +50,14 @@ angular.module('bahmni.ot') }); }; - this.getSurgicalBlocksInDateRange = function (startDatetime, endDatetime, includeVoided) { + this.getSurgicalBlocksInDateRange = function (startDatetime, endDatetime, includeVoided, activeBlocks) { return $http.get(Bahmni.OT.Constants.addSurgicalBlockUrl, { method: "GET", params: { startDatetime: Bahmni.Common.Util.DateUtil.parseLongDateToServerFormat(startDatetime), endDatetime: Bahmni.Common.Util.DateUtil.parseLongDateToServerFormat(endDatetime), includeVoided: includeVoided || false, + activeBlocks: activeBlocks || false, v: "custom:(id,uuid," + "provider:(uuid,person:(uuid,display),attributes:(attributeType:(display),value,voided))," + "location:(uuid,name),startDatetime,endDatetime,surgicalAppointments:(id,uuid,patient:(uuid,display,person:(age))," + diff --git a/ui/app/ot/views/addActualTimeDialog.html b/ui/app/ot/views/addActualTimeDialog.html index f7aa887620..07e8334d69 100644 --- a/ui/app/ot/views/addActualTimeDialog.html +++ b/ui/app/ot/views/addActualTimeDialog.html @@ -2,12 +2,18 @@
- + + + +
- + + + +
@@ -18,4 +24,4 @@
{{'OT_PATIENT' | translate}}: {{getPatientDisplayLabel(ngDialogData)}}
{{'OT_SURGICAL_BLOCK_DIALOG_LOCATION' | translate}}: {{surgicalBlockSelected.location.name}}
-{{'OT_SURGICAL_APPOINTMENT_ESTIMATED_TIME' | - translate}}: {{ngDialogData.derivedAttributes.expectedStartDatetime | bahmniTime}} - - {{ngDialogData.derivedAttributes.expectedEndDatetime | bahmniTime}}
+{{'OT_SURGICAL_APPOINTMENT_ESTIMATED_TIME' | translate}}: + {{ngDialogData.derivedAttributes.expectedStartDatetime | date : 'dd MMM, '}}{{ngDialogData.derivedAttributes.expectedStartDatetime | bahmniTime}} - + {{ngDialogData.derivedAttributes.expectedEndDatetime | date : 'dd MMM, '}}{{ngDialogData.derivedAttributes.expectedEndDatetime | bahmniTime}}
{{'OT_SURGICAL_APPOINTMENT_PROCEDURE' | translate}}: {{attributes.procedure}}
{{'OT_SURGICAL_APPOINTMENT_ANAESTHETIST' | translate}}: {{attributes.anaesthetist}}
{{'OT_SURGICAL_APPOINTMENT_NOTES' | translate}}: {{attributes.notes}}
{{'OT_SURGICAL_APPOINTMENT_ACTUAL_TIME' | translate}}:
- {{ngDialogData.actualStartDatetime | bahmniTime}} - {{ngDialogData.actualEndDatetime | bahmniTime}}
Are you sure you want to create a surgical block across days?
+