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

Phani, Bindu | BAH-3117 | Ability to add, display and update Notes section in OT Scheduling #647

Merged
merged 18 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Bindu, Phani | BAH-3117 | Integrate Update API to the UI
  • Loading branch information
binduak committed Jul 20, 2023
commit ee6c6b1aa9c1abda58bbc61a101a75791c656eaf
1 change: 1 addition & 0 deletions ui/app/i18n/ot/locale_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"DATE": "Date",
"DISCARD": "Discard",
"SAVE": "Save",
"UPDATE": "Update",

"ADD_SURGICAL_APPOINTMENT": "Add Surgery",
"EDIT_SURGICAL_APPOINTMENT": "Edit Surgery",
Expand Down
60 changes: 33 additions & 27 deletions ui/app/ot/controller/otCalendarController.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,34 @@ angular.module('bahmni.ot')
if (notes) {
$scope.emptyNoteError = false;
}
if (notes.id) {
$scope.notesId = notes.id;
}
};
$scope.saveNotes = async function () {
var notesInputValidation = function () {
if ($scope.startDateBeforeEndDateError || $scope.dateOutOfRangeError) {
return;
}
if (!$scope.otNotesField) {
$scope.emptyNoteError = true;
return;
}
};

$scope.saveNotes = async function () {
notesInputValidation();
if ($scope.isDayView) {
await surgicalAppointmentService.saveNoteForADay($scope.viewDate, $scope.otNotesField);
} else
await surgicalAppointmentService.saveNoteForADay($scope.notesStartDate, $scope.otNotesField, $scope.notesEndDate);
} else {
await surgicalAppointmentService.saveNoteForADay($scope.notesStartDate, $scope.otNotesField, $scope.notesEndDate);
}
$state.go("otScheduling", {viewDate: $scope.viewDate}, {reload: true});
};

$scope.noteForTheDay = ''; // "Note";
$scope.notesForWeek = {
// 2: 'note for 2nd July',
// 4: 'note for 3rd July'
$scope.updateNotes = async function () {
notesInputValidation();
await surgicalAppointmentService.updateNoteForADay($scope.noteId, $scope.otNotesField);
$state.go("otScheduling", {viewDate: $scope.viewDate}, {reload: true});
};

var heightPerMin = 120 / $scope.dayViewSplit;
Expand All @@ -129,12 +137,10 @@ angular.module('bahmni.ot')
const getNotes = function () {
if ($scope.weekOrDay === 'day') {
return surgicalAppointmentService.getNotes(new Date($scope.viewDate));
} else if ($scope.weekOrDay === 'week') {
return surgicalAppointmentService.getNotes($scope.weekStartDate, getWeekDate(7));
}
else if ($scope.weekOrDay === 'week') {
return surgicalAppointmentService.getNotes($scope.weekStartDate, getWeekDate(7) );
}

};
};
var init = function () {
var dayStart = ($scope.dayViewStart || Bahmni.OT.Constants.defaultCalendarStartTime).split(':');
var dayEnd = ($scope.dayViewEnd || Bahmni.OT.Constants.defaultCalendarEndTime).split(':');
Expand Down Expand Up @@ -164,9 +170,10 @@ angular.module('bahmni.ot')
});
if (response[3] && response[3].status === 200) {
$scope.noteForTheDay = response[3].data.length > 0 ? response[3].data[0].noteText : '';
}
else {
$scope.noteId = response[3].data.length > 0 ? response[3].data[0].noteId : '';
} else {
$scope.noteForTheDay = '';
$scope.noteId = '';
}
var providerNames = appService.getAppDescriptor().getConfigValue("primarySurgeonsForOT");
$scope.surgeons = surgicalAppointmentHelper.filterProvidersByName(providerNames, response[2].data.results);
Expand All @@ -181,18 +188,17 @@ angular.module('bahmni.ot')
});
});

$scope.getNotesForWeek = function (weekStartDate, index) {
const date = new Date(weekStartDate);
return _.filter(response[3].data, function (note) {
return new Date(note.noteDate).getDate() === (date.getDate() + index);
});
};

$scope.getNotesForWeek = function (weekStartDate, index) {
const date = new Date(weekStartDate);
return _.filter(response[3].data, function (note) {
return new Date(note.noteDate).getDate() === (date.getDate() + index);
});
}

$scope.getNotesForDay = function (weekStartDate, index) {
var notes = $scope.getNotesForWeek(weekStartDate, index);
return notes.length > 0 ? notes[0].noteText : '';
}
$scope.getNotesForDay = function (weekStartDate, index) {
var notes = $scope.getNotesForWeek(weekStartDate, index);
return notes.length > 0 ? notes[0].noteText : '';
};

$scope.blockedOtsOfTheWeek = getBlockedOtsOfTheWeek();
showToolTipForNotes();
Expand All @@ -213,8 +219,8 @@ angular.module('bahmni.ot')
};

$scope.isSurgicalBlockActiveOnGivenDate = function (surgicalBlock, weekDate) {
return Bahmni.Common.Util.DateUtil.isSameDate(moment(surgicalBlock.startDatetime).startOf('day').toDate(), weekDate)
|| moment(surgicalBlock.endDatetime).toDate() > weekDate;
return Bahmni.Common.Util.DateUtil.isSameDate(moment(surgicalBlock.startDatetime).startOf('day').toDate(), weekDate) ||
moment(surgicalBlock.endDatetime).toDate() > weekDate;
};

$scope.intervals = function () {
Expand Down
19 changes: 12 additions & 7 deletions ui/app/ot/services/surgicalAppointmentService.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,30 @@ angular.module('bahmni.ot')
var constructPayload = function (noteDate, note, noteEndDate) {
const payload = [];
const currentDate = new Date(noteDate);
while ( currentDate <= noteEndDate) {
// eslint-disable-next-line no-unmodified-loop-condition
while (currentDate <= noteEndDate) {
payload.push({
noteTypeName: "OT module",
noteDate: new Date(currentDate),
noteText: note
})
});
currentDate.setDate(currentDate.getDate() + 1);
}
return payload;
}
};

this.saveNoteForADay = function (noteDate, note, noteEndDate) {
const payload = noteEndDate != null ? constructPayload(noteDate, note, noteEndDate) : [{
noteTypeName: "OT module",
noteDate: noteDate,
noteText: note
}];
noteTypeName: "OT module",
noteDate: noteDate,
noteText: note
}];
const headers = {"Accept": "application/json", "Content-Type": "application/json"};
return $http.post(Bahmni.OT.Constants.notesUrl, payload, headers);
};

this.updateNoteForADay = function (noteId, note) {
const headers = {"Accept": "application/json", "Content-Type": "application/json"};
return $http.post(Bahmni.OT.Constants.notesUrl + "/" + noteId, note, headers);
};
}]);
5 changes: 3 additions & 2 deletions ui/app/ot/views/notesModal.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h6 style="color: black">{{'TO' | translate}}</h6>
</div>
</div>
<button class="cancel-button" ng-click="closeNotes()">{{'OT_CANCEL_KEY' | translate}}</button>
<button class="save-button" ng-click="saveNotes()">{{'SAVE' | translate}}</button>
<button ng-if="!noteId" class="save-button" ng-click="saveNotes()">{{'SAVE' | translate}}</button>
<button ng-if="noteId" class="save-button" ng-click="updateNotes()">{{'UPDATE' | translate}}</button>
</div>
</div>
</div>