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

Arjun,Ashish,Sowmya,Phani | Navigation feature in consultation tabs #943

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ angular.module('bahmni.clinical')
};

$scope.$on('$stateChangeStart', function () {
if ($scope.bacteriologyForm.$dirty) {
if ($scope.bacteriologyForm && $scope.bacteriologyForm.$dirty) {
$state.dirtyConsultationForm = true;
}
});
Expand Down
77 changes: 55 additions & 22 deletions ui/app/clinical/consultation/controllers/consultationController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ angular.module('bahmni.clinical').controller('ConsultationController',
'ngDialog', '$filter', 'configurations', 'visitConfig', 'conditionsService', 'configurationService', 'auditLogService', 'confirmBox',
'virtualConsultService', 'adhocTeleconsultationService',
function ($scope, $rootScope, $state, $location, $translate, clinicalAppConfigService, diagnosisService, urlHelper, contextChangeHandler,
spinner, encounterService, messagingService, sessionService, retrospectiveEntryService, patientContext, $q,
patientVisitHistoryService, $stateParams, $window, visitHistory, clinicalDashboardConfig, appService,
ngDialog, $filter, configurations, visitConfig, conditionsService, configurationService, auditLogService, confirmBox,
virtualConsultService, adhocTeleconsultationService) {
spinner, encounterService, messagingService, sessionService, retrospectiveEntryService, patientContext, $q,
patientVisitHistoryService, $stateParams, $window, visitHistory, clinicalDashboardConfig, appService,
ngDialog, $filter, configurations, visitConfig, conditionsService, configurationService, auditLogService, confirmBox,
virtualConsultService, adhocTeleconsultationService) {
var ERROR = 1;
var DateUtil = Bahmni.Common.Util.DateUtil;
var getPreviousActiveCondition = Bahmni.Common.Domain.Conditions.getPreviousActiveCondition;
Expand All @@ -23,7 +23,6 @@ angular.module('bahmni.clinical').controller('ConsultationController',
};
$scope.showComment = true;
$scope.showSaveAndContinueButton = true;

$scope.visitHistory = visitHistory;
$scope.consultationBoardLink = clinicalAppConfigService.getConsultationBoardLink();
$scope.showControlPanel = false;
Expand Down Expand Up @@ -181,7 +180,7 @@ angular.module('bahmni.clinical').controller('ConsultationController',

var initialize = function () {
var appExtensions = clinicalAppConfigService.getAllConsultationBoards();
$scope.adtNavigationConfig = {forwardUrl: Bahmni.Clinical.Constants.adtForwardUrl, title: $translate.instant("CLINICAL_GO_TO_DASHBOARD_LABEL"), privilege: Bahmni.Clinical.Constants.adtPrivilege };
$scope.adtNavigationConfig = { forwardUrl: Bahmni.Clinical.Constants.adtForwardUrl, title: $translate.instant("CLINICAL_GO_TO_DASHBOARD_LABEL"), privilege: Bahmni.Clinical.Constants.adtPrivilege };
$scope.availableBoards = $scope.availableBoards.concat(appExtensions);
$scope.showSaveConfirmDialogConfig = appService.getAppDescriptor().getConfigValue('showSaveConfirmDialog');
var adtNavigationConfig = appService.getAppDescriptor().getConfigValue('adtNavigationConfig');
Expand All @@ -203,7 +202,7 @@ angular.module('bahmni.clinical').controller('ConsultationController',
event.preventDefault();
spinner.hide(toState.spinnerToken);
ngDialog.close();
$scope.toStateConfig = {toState: toState, toParams: toParams};
$scope.toStateConfig = { toState: toState, toParams: toParams };
$scope.displayConfirmationDialog();
}
}
Expand All @@ -212,7 +211,7 @@ angular.module('bahmni.clinical').controller('ConsultationController',
});

$scope.adtNavigationURL = function (visitUuid) {
return appService.getAppDescriptor().formatUrl($scope.adtNavigationConfig.forwardUrl, {'patientUuid': $scope.patient.uuid, 'visitUuid': visitUuid});
return appService.getAppDescriptor().formatUrl($scope.adtNavigationConfig.forwardUrl, { 'patientUuid': $scope.patient.uuid, 'visitUuid': visitUuid });
};

var cleanUpListenerErrorsOnForm = $scope.$on("event:errorsOnForm", function () {
Expand All @@ -225,7 +224,7 @@ angular.module('bahmni.clinical').controller('ConsultationController',
event.preventDefault();
$scope.targetUrl = event.currentTarget.getAttribute('href');
}
ngDialog.openConfirm({template: '../common/ui-helper/views/saveConfirmation.html', scope: $scope});
ngDialog.openConfirm({ template: '../common/ui-helper/views/saveConfirmation.html', scope: $scope });
}
if ($scope.showTeleConsultationWindow) {
var childScope = {};
Expand All @@ -235,7 +234,7 @@ angular.module('bahmni.clinical').controller('ConsultationController',
event.preventDefault();
confirmBox({
scope: childScope,
actions: [{name: 'ok', display: 'Ok'}],
actions: [{ name: 'ok', display: 'Ok' }],
className: "ngdialog-theme-default delete-program-popup"
});
}
Expand Down Expand Up @@ -351,6 +350,11 @@ angular.module('bahmni.clinical').controller('ConsultationController',
if ($scope.currentBoard === board) {
return;
}
$scope.isObservationPage = board.id == "bahmni.clinical.consultation.observations" ? true : false;
$scope.isSave = false;
if ($scope.currentBoard) {
$scope.isSwitchedFromObservationToOtherPage = $scope.currentBoard.id == "bahmni.clinical.consultation.observations" ? true : false;
}
if (!isFormValid()) {
$scope.$parent.$broadcast("event:errorsOnForm");
return;
Expand Down Expand Up @@ -473,27 +477,56 @@ angular.module('bahmni.clinical').controller('ConsultationController',
_.each($scope.consultation.observationForms, function (observationForm) {
if (valid && observationForm.component) {
var value = observationForm.component.getValue();

if (value.errors) {
messagingService.showMessage('error', "{{'CLINICAL_FORM_ERRORS_MESSAGE_KEY' | translate }}");
valid = false;
if ($state.current !== undefined && $state.current.name === "patient.dashboard.show.observations") {
messagingService.showMessage('error', "{{'CLINICAL_FORM_ERRORS_MESSAGE_KEY' | translate }}");
valid = false;
}
else {
messagingService.showMessage('error', "{{'CLINICAL_FORM_ERRORS_ON_OBSERVATION_TAB_MESSAGE_KEY' | translate }}");
valid = false;
}
}
}
});
return valid;
};

var checkForObservationPageError = function (shouldAllow, contxChange) {
if (!$scope.isSave) {
if ($scope.isSwitchedFromObservationToOtherPage && !shouldAllow) {
$scope.isErrorPresentInObsTab = true;
shouldAllow = $scope.isErrorPresentInObsTab;
} else if ($scope.isSwitchedFromObservationToOtherPage && shouldAllow) {
$scope.isErrorPresentInObsTab = false;
}
} else if ($scope.isSave) {
if ($scope.isErrorPresentInObsTab) {
if (!$scope.isObservationPage) {
var errorMessage = contxChange["errorMessage"] ? contxChange["errorMessage"] : "{{'CLINICAL_FORM_ERRORS_MESSAGE_KEY' | translate }}";
messagingService.showMessage('error', errorMessage);
} else if ($scope.isObservationPage) {
$scope.isErrorPresentInObsTab = false;
}
}
}
return shouldAllow;
};

var isFormValid = function () {
var contxChange = contextChange();
var shouldAllow = contxChange["allow"];
var discontinuedDrugOrderValidationMessage = discontinuedDrugOrderValidation($scope.consultation.discontinuedDrugs);
shouldAllow = checkForObservationPageError(shouldAllow, contxChange);
if (!shouldAllow) {
var errorMessage = contxChange["errorMessage"] ? contxChange["errorMessage"] : "{{'CLINICAL_FORM_ERRORS_MESSAGE_KEY' | translate }}";
messagingService.showMessage('error', errorMessage);
} else if (discontinuedDrugOrderValidationMessage) {
var errorMessage = discontinuedDrugOrderValidationMessage;
messagingService.showMessage('error', errorMessage);
}
return shouldAllow && !discontinuedDrugOrderValidationMessage && isObservationFormValid();
return shouldAllow && !discontinuedDrugOrderValidationMessage;
};

var copyConsultationToScope = function (consultationWithDiagnosis) {
Expand All @@ -510,7 +543,8 @@ angular.module('bahmni.clinical').controller('ConsultationController',
});

$scope.save = function (toStateConfig) {
if (!isFormValid()) {
$scope.isSave = true;
if (!isFormValid() || !isObservationFormValid() || $scope.isErrorPresentInObsTab) {
$scope.$parent.$parent.$broadcast("event:errorsOnForm");
return $q.when({});
}
Expand All @@ -535,13 +569,12 @@ angular.module('bahmni.clinical').controller('ConsultationController',
$rootScope.cdssAlerts = cdssAlerts;
}
preSaveEvents();
return spinner.forPromise($q.all([preSavePromise(),
encounterService.getEncounterType($state.params.programUuid, sessionService.getLoginLocationUuid())]).then(function (results) {
var encounterData = results[0];
encounterData.encounterTypeUuid = results[1].uuid;
var params = angular.copy($state.params);
params.cachebuster = Math.random();
return encounterService.create(encounterData)
return spinner.forPromise($q.all([preSavePromise(), encounterService.getEncounterType($state.params.programUuid, sessionService.getLoginLocationUuid())]).then(function (results) {
var encounterData = results[0];
encounterData.encounterTypeUuid = results[1].uuid;
var params = angular.copy($state.params);
params.cachebuster = Math.random();
return encounterService.create(encounterData)
.then(function (saveResponse) {
$state.dirtyConsultationForm = false;
$state.orderRemoved = false;
Expand Down Expand Up @@ -583,7 +616,7 @@ angular.module('bahmni.clinical').controller('ConsultationController',
var message = Bahmni.Clinical.Error.translate(error) || "{{'CLINICAL_SAVE_FAILURE_MESSAGE_KEY' | translate}}";
messagingService.showMessage('error', message);
});
}));
}));
} catch (error) {
var displayErrors = function (error) {
if (angular.isArray(error)) {
Expand Down
16 changes: 14 additions & 2 deletions ui/app/common/concept-set/directives/conceptSet.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

angular.module('bahmni.common.conceptSet')
.directive('conceptSet', ['contextChangeHandler', 'appService', 'observationsService', 'messagingService', 'conceptSetService', 'conceptSetUiConfigService', 'spinner',
function (contextChangeHandler, appService, observationsService, messagingService, conceptSetService, conceptSetUiConfigService, spinner) {
.directive('conceptSet', ['contextChangeHandler', 'appService', 'observationsService', 'messagingService', 'conceptSetService', 'conceptSetUiConfigService', 'spinner', '$state',
function (contextChangeHandler, appService, observationsService, messagingService, conceptSetService, conceptSetUiConfigService, spinner, $state) {
var controller = function ($scope) {
var conceptSetName = $scope.conceptSetName;
var ObservationUtil = Bahmni.Common.Obs.ObservationUtil;
Expand Down Expand Up @@ -412,6 +412,18 @@ angular.module('bahmni.common.conceptSet')
deregisterAddMore();
cleanUpListenerShowPrevious();
});

$scope.$on('$stateChangeStart', function () {
if ($scope.obsForm && $scope.obsForm.$dirty) {
$state.dirtyConsultationForm = true;
}
});

$scope.$on("event:changes-saved", function () {
if ($scope.obsForm) {
$scope.obsForm.$dirty = false;
}
});
};

return {
Expand Down
Loading
Loading