Skip to content

Commit

Permalink
Tarun, Gopi | BAH-1170 | Add support to create surgical blocks across…
Browse files Browse the repository at this point in the history
… days (#51) (#354) (#370)

* Tarun | MOBN-1628 | Add confirmation popup for creating surgical block across multiple days

* Tarun | MOBN-1628 | Fix day view to show surgical blocks created across days

* Gopi ,Tarun | MOBN-1628 | Removed Syntax Error Which Is Causing Error PopUp on OT Page Load

* Tarun, Gopi | MOBN-1628 | Fix week view to show surgical blocks created across days

* Tarun, Gopi | MOBN-1628 | Fix list view to show surgical appointments created across days

* Gopi,Tarun | MOBN-1628 | Fixed Existing UI Tests

* Tarun, Gopi | MOBN-1628 | Show both startdate and enddate in surgical block dialog if both dates are different

* Gopi,Tarun | MOBN-1628 | Fixed Remaining UI Tests

* Tarun, Gopi | MOBN-1628 | Add date input field in actual time dialog

* Tarun, Gopi | MOBN-1628 | Add date in est & actual time fields in appointment details dialog

* Tarun, Gopi | MOBN-1628 | Show surgical block end date if block end on a different date

* Tarun, Gopi | MOBN-1628 | Correct typo issue

* Tarun, Gopi | MOBN-1628 | Handle code review changes

* Tarun, Gopi | MOBN-1628 | Handle code review changes

Co-authored-by: gopikrishna-yaramothu <65332533+gopikrishna-yaramothu@users.noreply.github.com>
Co-authored-by: gopikrishna-yaramothu <gopikrishna.y@thoughtworks.com>

Co-authored-by: gopikrishna-yaramothu <65332533+gopikrishna-yaramothu@users.noreply.github.com>
Co-authored-by: gopikrishna-yaramothu <gopikrishna.y@thoughtworks.com>

Co-authored-by: tarunkumar-tw <58736833+tarunkumar-tw@users.noreply.github.com>
Co-authored-by: gopikrishna-yaramothu <65332533+gopikrishna-yaramothu@users.noreply.github.com>
Co-authored-by: gopikrishna-yaramothu <gopikrishna.y@thoughtworks.com>
  • Loading branch information
4 people authored Aug 30, 2021
1 parent 2ef0320 commit 718bdf6
Show file tree
Hide file tree
Showing 22 changed files with 154 additions and 49 deletions.
4 changes: 3 additions & 1 deletion ui/app/i18n/ot/locale_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
2 changes: 2 additions & 0 deletions ui/app/ot/controller/calendarViewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -241,6 +242,7 @@ angular.module('bahmni.ot')
$scope.addActualTimeDisabled = true;
$scope.surgicalBlockSelected = {};
$scope.surgicalAppointmentSelected = {};
$scope.showEndDate = false;
};

$scope.$on("event:surgicalBlockDeselect", function (event) {
Expand Down
11 changes: 10 additions & 1 deletion ui/app/ot/controller/listViewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});

Expand All @@ -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);
});
Expand Down
9 changes: 7 additions & 2 deletions ui/app/ot/controller/otCalendarController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(':');
Expand Down
43 changes: 33 additions & 10 deletions ui/app/ot/controller/surgicalBlockController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}}");
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/ot/directives/otCalendarSurgicalAppointment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 30 additions & 5 deletions ui/app/ot/directives/otCalendarSurgicalBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
};
};

Expand Down Expand Up @@ -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(':');
Expand All @@ -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);
Expand All @@ -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;
});
Expand All @@ -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();
Expand Down Expand Up @@ -119,7 +143,8 @@ angular.module('bahmni.ot')
dayViewEnd: "=",
dayViewSplit: "=",
filterParams: "=",
weekOrDay: "="
weekOrDay: "=",
viewDate: "="
},
templateUrl: "../ot/views/calendarSurgicalBlock.html"
};
Expand Down
3 changes: 2 additions & 1 deletion ui/app/ot/services/surgicalAppointmentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))," +
Expand Down
12 changes: 9 additions & 3 deletions ui/app/ot/views/addActualTimeDialog.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
<h4 class="ot-actual-time-person-display"> {{'OT_SURGICAL_APPOINTMENT_ADD_ACTUAL_TIME_FOR' | translate}} {{patientDisplayLabel}}</h4>
<p>
<label class="ot-actual-time-label">{{'OT_START_TIME_KEY' | translate}}</label>
<input class= "ot-actual-time-input" ng-required="isActualTimeRequired()" type="time" ng-model="actualStartTime"/>
<span class="ot-actual-datetime-input">
<input class= "ot-actual-time-input" ng-required="isActualTimeRequired()" type="date" ng-model="actualStartTime"/>
<input class= "ot-actual-time-input" ng-required="isActualTimeRequired()" type="time" ng-model="actualStartTime"/>
</span>
</p>

<p>
<label class="ot-actual-time-label">{{'OT_END_TIME_KEY' | translate}}</label>
<input class="ot-actual-time-input" ng-required="isActualTimeRequired()" type="time" ng-model="actualEndTime"/>
<span class="ot-actual-datetime-input">
<input class= "ot-actual-time-input" ng-required="isActualTimeRequired()" type="date" ng-model="actualEndTime"/>
<input class= "ot-actual-time-input" ng-required="isActualTimeRequired()" type="time" ng-model="actualEndTime"/>
</span>
</p>
<p>
<label class="ot-actual-time-label">{{'OT_SURGICAL_APPOINTMENT_NOTES' | translate}}</label>
Expand All @@ -18,4 +24,4 @@ <h4 class="ot-actual-time-person-display"> {{'OT_SURGICAL_APPOINTMENT_ADD_ACTUAL
<input type="button" class="button" value="{{'OT_CANCEL_KEY' | translate}}" ng-click="close()"/>
</p>

</form>
</form>
2 changes: 1 addition & 1 deletion ui/app/ot/views/calendarSurgicalBlock.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
week-or-day="weekOrDay"
operation-theatre="operationTheatre"
background-color="blockDimensions.color"
ng-if="isValidSurgicalAppointment(surgicalAppointment)"
ng-if="canShowInCalendarView(surgicalAppointment)"
height-per-min="blockDimensions.appointmentHeightPerMin"
filter-params="filterParams"></ot-calendar-surgical-appointment>

Expand Down
1 change: 1 addition & 0 deletions ui/app/ot/views/otCalendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
day-view-split="::dayViewSplit"
filter-params="filterParams"
week-or-day="::weekOrDay"
view-date="::viewDate"
></ot-calendar-surgical-block>
</div>
<hr class="current-day-line"
Expand Down
1 change: 1 addition & 0 deletions ui/app/ot/views/otWeeklyCalendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
day-view-split="::dayViewSplit"
filter-params="filterParams"
week-or-day="::weekOrDay"
view-date="::weekDates[blockIndex]"
></ot-calendar-surgical-block>
</div>
<hr class="current-day-line"
Expand Down
Loading

0 comments on commit 718bdf6

Please sign in to comment.