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

registration search: strip registration prefix from registration number if present #16

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions ui/app/registration/controllers/searchController.js
Expand Up @@ -197,6 +197,16 @@ angular.module('bahmni.registration')
$scope.results = [];

var patientIdentifier = $scope.searchParameters.registrationNumber;

// strip off the identifier prefix from the identifier itself if it exists
$scope.identifierSources.forEach(function (identifierSource) {
var regex = new RegExp('^' + identifierSource.prefix, 'i');
if (regex.test(patientIdentifier)) {
patientIdentifier = patientIdentifier.replace(regex, '');
$scope.searchParameters.identifierPrefix = identifierSource; // make sure that the identifier prefix search parameter is set to the prefix we found
}
});

preferences.identifierPrefix = $scope.searchParameters.identifierPrefix ? $scope.searchParameters.identifierPrefix.prefix : "";

$location.search({
Expand Down
Expand Up @@ -268,6 +268,37 @@ describe('SearchPatientController', function () {
expect(patientResource.search).not.toHaveBeenCalled();
});

it('should strip prefix from registrationNumber if present', function () {
scope.searchParameters.identifierPrefix = {};
scope.searchParameters.identifierPrefix.prefix = "GAN";
scope.searchParameters.registrationNumber = "gan20001"; // match should case-insensitive
var defaultSearchAddressField = undefined;
scope.searchById();

expect(patientResource.search).toHaveBeenCalledWith(undefined, "20001", "GAN", defaultSearchAddressField, undefined, undefined, undefined, undefined, undefined, undefined);
});

it('should strip prefix from registrationNumber even if not selected prefix', function () {
scope.searchParameters.identifierPrefix = {};
scope.searchParameters.identifierPrefix.prefix = "GAN";
scope.searchParameters.registrationNumber = "sem20001"; // match should case-insensitive
var defaultSearchAddressField = undefined;
scope.searchById();

expect(patientResource.search).toHaveBeenCalledWith(undefined, "20001", "SEM", defaultSearchAddressField, undefined, undefined, undefined, undefined, undefined, undefined);
});

it('should not strip prefix from registrationNumber if found elsewhere than as a prefix', function () {
scope.searchParameters.identifierPrefix = {};
scope.searchParameters.identifierPrefix.prefix = "GAN";
scope.searchParameters.registrationNumber = "20001gan";
var defaultSearchAddressField = undefined;
scope.searchById();

expect(patientResource.search).toHaveBeenCalledWith(undefined, "20001gan", "GAN", defaultSearchAddressField, undefined, undefined, undefined, undefined, undefined, undefined);
});


describe("on success", function () {
beforeEach(function () {
scope.searchParameters.identifierPrefix = {};
Expand Down