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

BAH-2647 | Already active Visits not allowed to create again #564

Merged
merged 14 commits into from
Jul 31, 2023
13 changes: 13 additions & 0 deletions ui/app/common/domain/services/visitService.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ angular.module('bahmni.common.domain')
});
};

this.checkIfActiveVisitExists = function (patientUuid, visitLocationUuid) {
return $http.get(Bahmni.Common.Constants.visitUrl,
{
params: {
includeInactive: false,
patient: patientUuid,
location: visitLocationUuid
},
withCredentials: true
}
);
};

this.getVisitSummary = function (visitUuid) {
return $http.get(Bahmni.Common.Constants.visitSummaryUrl,
{
Expand Down
6 changes: 5 additions & 1 deletion ui/app/common/models/visitControl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

Bahmni.Common.VisitControl = function (visitTypes, defaultVisitTypeName, encounterService,
$translate, visitService) {
$translate, visitService) {
var self = this;
self.visitTypes = visitTypes;
self.defaultVisitTypeName = defaultVisitTypeName;
Expand All @@ -18,6 +18,10 @@ Bahmni.Common.VisitControl = function (visitTypes, defaultVisitTypeName, encount
self.selectedVisitType = visitType;
};

self.checkIfActiveVisitExists = function (patientUuid, visitLocationUuid) {
return visitService.checkIfActiveVisitExists(patientUuid, visitLocationUuid);
};

self.createVisitOnly = function (patientUuid, visitLocationUuid) {
var visitType = self.selectedVisitType || self.defaultVisitType;
var visitDetails = {patient: patientUuid, visitType: visitType.uuid, location: visitLocationUuid};
Expand Down
1 change: 1 addition & 0 deletions ui/app/i18n/registration/locale_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
"MESSAGE_DIALOG_OPTION_COPY" : "Copy Error",
"MESSAGE_DIALOG_OPTION_OKAY": "OK",
"NO_LOCATION_TAGGED_TO_VISIT_LOCATION": "No location tagged to Visit Location Found",
"VISIT_OF_THIS_PATIENT_AT_SAME_LOCATION_EXISTS": "An active visit for this patient already exists for this location. The system cannot create a duplicate visit.",
"REGISTRATION_ADDTIONAL_IDENTIFIERS": "Additional Identifiers",
"REGISTRATION_FORM_ERRORS_MESSAGE_KEY": "Please enter a value in the mandatory fields or correct the value in the highlighted fields to proceed",
"OBS_BOOLEAN_YES_KEY":"Yes",
Expand Down
3 changes: 2 additions & 1 deletion ui/app/i18n/registration/locale_es.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"MESSAGE_DIALOG_OPTION_OKAY": "OK",
"NO_LOCATION_TAGGED_TO_VISIT_LOCATION": "No hay ubicación puesta para la Ubicacion de la Visita Encontrada",
"REGISTRATION_ADDTIONAL_IDENTIFIERS": "Identificadores Adicionales",
"REGISTRATION_ADDTIONAL_IDENTIFIERS": "Identificadores Adicionales",
"REGISTRATION_FORM_ERRORS_MESSAGE_KEY": "Por favor ingrese un valor en los campos obligatorios o corriga el valor en los campos resaltados para continuar",
"OBS_BOOLEAN_YES_KEY": "Sí",
"OBS_BOOLEAN_NO_KEY": "No",
Expand Down Expand Up @@ -121,4 +122,4 @@
"PATIENT_ATTRIBUTE_GIVEN_NAME_LOCAL": "First Name in Arabic",
"PATIENT_ATTRIBUTE_FAMILY_NAME_LOCAL": "Last Name in Arabic",
"PATIENT_ATTRIBUTE_MIDDLE_NAME_LOCAL": "Middle Name in Arabic"
}
}
3 changes: 2 additions & 1 deletion ui/app/i18n/registration/locale_pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,6 @@
"FILE_UPLOAD_MUST_BE_LESS_THAN": "File size should be less than",
"PATIENT_ATTRIBUTE_GIVEN_NAME_LOCAL": "First Name in Arabic",
"PATIENT_ATTRIBUTE_FAMILY_NAME_LOCAL": "Last Name in Arabic",
"PATIENT_ATTRIBUTE_MIDDLE_NAME_LOCAL": "Middle Name in Arabic"
"PATIENT_ATTRIBUTE_MIDDLE_NAME_LOCAL": "Middle Name in Arabic",
"VISIT_OF_THIS_PATIENT_AT_SAME_LOCATION_EXISTS": "A visita deste paciente no mesmo local já existe"
}
40 changes: 27 additions & 13 deletions ui/app/registration/directives/patientAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ angular.module('bahmni.registration')
'$bahmniCookieStore', 'appService', 'visitService', 'sessionService', 'encounterService',
'messagingService', '$translate', 'auditLogService',
function ($window, $location, $state, spinner, $rootScope, $stateParams,
$bahmniCookieStore, appService, visitService, sessionService, encounterService,
messagingService, $translate, auditLogService) {
$bahmniCookieStore, appService, visitService, sessionService, encounterService,
messagingService, $translate, auditLogService) {
var controller = function ($scope) {
var self = this;
var uuid = $stateParams.patientUuid;
Expand Down Expand Up @@ -138,24 +138,38 @@ angular.module('bahmni.registration')
return _.isEmpty($rootScope.visitLocation);
};

var checkIfActiveVisitExists = function (patientProfileData) {
return $scope.visitControl.checkIfActiveVisitExists(patientProfileData.patient.uuid, $rootScope.visitLocation).then(function (response) {
var checkExists = response.data.results.length;
if (checkExists === 0) {
return false;
} else {
return true;
}
});
};
var createVisit = function (patientProfileData, forwardUrl) {
if (isEmptyVisitLocation()) {
$state.go('patient.edit', {patientUuid: $scope.patient.uuid}).then(function () {
messagingService.showMessage("error", "NO_LOCATION_TAGGED_TO_VISIT_LOCATION");
});
return;
}
spinner.forPromise($scope.visitControl.createVisitOnly(patientProfileData.patient.uuid, $rootScope.visitLocation).then(function (response) {
auditLogService.log(patientProfileData.patient.uuid, "OPEN_VISIT", {visitUuid: response.data.uuid, visitType: response.data.visitType.display}, 'MODULE_LABEL_REGISTRATION_KEY');
if (forwardUrl) {
var updatedForwardUrl = appService.getAppDescriptor().formatUrl(forwardUrl, {'patientUuid': patientProfileData.patient.uuid});
$window.location.href = updatedForwardUrl;
} else {
goToVisitPage(patientProfileData);
}
}, function () {
$state.go('patient.edit', {patientUuid: $scope.patient.uuid});
}));
checkIfActiveVisitExists(patientProfileData).then(function (exists) {
if (exists) return messagingService.showMessage("error", "VISIT_OF_THIS_PATIENT_AT_SAME_LOCATION_EXISTS");

spinner.forPromise($scope.visitControl.createVisitOnly(patientProfileData.patient.uuid, $rootScope.visitLocation).then(function (response) {
auditLogService.log(patientProfileData.patient.uuid, "OPEN_VISIT", { visitUuid: response.data.uuid, visitType: response.data.visitType.display }, 'MODULE_LABEL_REGISTRATION_KEY');
if (forwardUrl) {
var updatedForwardUrl = appService.getAppDescriptor().formatUrl(forwardUrl, { 'patientUuid': patientProfileData.patient.uuid });
$window.location.href = updatedForwardUrl;
} else {
goToVisitPage(patientProfileData);
}
}, function () {
$state.go('patient.edit', { patientUuid: $scope.patient.uuid });
}));
});
};

init();
Expand Down
9 changes: 5 additions & 4 deletions ui/test/unit/registration/directives/patientAction.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ describe('PatientAction', function () {
appDescriptor = jasmine.createSpyObj('appDescriptor', ['getExtensions', 'getConfigValue', 'formatUrl']);
appDescriptor.getExtensions.and.returnValue(input.appDescriptor.getExtensions);
appDescriptor.getConfigValue.and.callFake(function (value) {
if (value == 'defaultVisitType') {
if (value === 'defaultVisitType') {
return input.appDescriptor.getConfigValue.defaultVisitType;
} else if (value == 'showStartVisitButton') {
} else if (value === 'showStartVisitButton') {
return input.appDescriptor.getConfigValue.showStartVisitButton;
} else if (value == 'forwardUrlsForVisitTypes') {
} else if (value === 'forwardUrlsForVisitTypes') {
return input.appDescriptor.getConfigValue.forwardUrls;
}
});
Expand All @@ -40,10 +40,11 @@ describe('PatientAction', function () {
return {uuid: "uuid"};
});
$location = jasmine.createSpyObj('$location', ['path']);
visitService = jasmine.createSpyObj('visitService', ['search', 'createVisit']);
visitService = jasmine.createSpyObj('visitService', ['search', 'createVisit', 'checkIfActiveVisitExists']);
visitService.search.and.returnValue(specUtil.simplePromise(input.visitSearchResults));
var visitResponse = {uuid: "visitUuid", visitType: {display: 'OPD'}};
visitService.createVisit.and.returnValue(specUtil.simplePromise({data: visitResponse}));
visitService.checkIfActiveVisitExists.and.returnValue(specUtil.simplePromise({ data: { "results": [] } }));
encounterService = jasmine.createSpyObj('encounterService', ['']);
sessionService = jasmine.createSpyObj('sessionService', ['']);
messagingService = jasmine.createSpyObj('messagingService', ['showMessage', 'clearAll']);
Expand Down