Patient Identifier

Bahmni uses OpenMRS ID Gen module for patient ID management & generation.

There are two configuration required for automatically generating the patient identifier. If you are doing it for the first time it is likely you need to configure the patient identifier source first. For each identifier source you can define multiple identifier sequences. Bahmni currently doesn't support more than one identifier source. The user interface for ID gen module is broken hence you would need to set this by directly using the SQL in database.

Choosing the primary identifier type

Please refer to this video on Patient Identifier Configuration in Bahmni.


Bahmni uses a global property called 'bahmni.primaryIdentifierType'. It accepts the UUID of the identifier type you want to use in the application. Bahmni uses this UUID to fetch the list of identifier sources. Please make sure to uncheck 'Is required' field in other identifier types if you have any. Also set Location behaviour to 'Not used' in the identifier type. Please refer OpenMRS wiki for details about identifier sources and types.

Till 0.88 bahmni.primaryIdentifierType was called as emr.primaryIdentifierType

Note: by default Bahmni ships with Bahmni Id. Implementations can change it.

Creating a New Patient Identifier Source

You will need to fire the following SQL query to create an Identifier Source. 

Please check if it already exists. If so, then instead of the INSERT query, fire an appropriate UPDATE query. 

SQL Query for creating an identifier source
-- Note that "ANC" and "ID Sequence source for patients in ANC" are the PREFIX, and the DESCRIPTION respectively. 
-- You can change them as you need
 
insert into idgen_identifier_source (uuid, name, description, identifier_type, date_created, creator) 
values (uuid(), 'ANC', 'ID sequence source for patients in ANC', (select patient_identifier_type_id 
from patient_identifier_type where name = 'Bahmni Id'), now(), 1);

Create a New Identifier Sequence

 Now you need to specify the details about the Identifier sequence number. The ID sequence format is controlled by the table "idgen_seq_id_gen" where  Here is an explanation: 

AttributeExplanation
next_sequence_valueStores the value of the next sequence number to be generated
first_identifier_baseDetermines the starting value from which sequence should start. Set this to a value of current ID number to generate future ID numbers that are higher than this. Useful when you have existing numbering system and want to keep new patient ids separate
prefixAllows you to define the prefix for the ID - can be used to denote a health center / department e.g. SEA, or ANC, etc.
suffixAllows to define a fixed value that can be appended (in the end) to the ID like a year e.g. /14
min_lengthAllows for defining minimum length of the ID generated. This includes the length of Prefix and suffix so if you have min 4 digits as id but have a Prefix and suffix like given above then min_length should be 3+4+3 = 10
max_lengthAllows for defining maximum length of the ID generated. This includes the length of Prefix and suffix so if you have max of 7 digits as ID but have a Prefix and suffix like given above then max_length should be 3+7+3 = 13

Please check if it already exists. If so, then instead of the INSERT query, fire an appropriate UPDATE query. 

SQL for specifying Identifier details
-- Set the values appropriately
-- Example here:
-- next_sequence_value = '200001'
-- base_character_set = '0123456789'
-- first_identifier_base = '200000'
-- prefix = 'ANC'
-- suffix = '' (nothing)
-- min_length = 9 digits
-- max_length = 9 digits
 
insert into idgen_seq_id_gen (id, next_sequence_value, base_character_set, first_identifier_base, prefix, 
suffix, min_length, max_length) values ((select id from idgen_identifier_source where name = 'ANC'), 
200001, 0123456789, 200000, 'ANC', '', 9, 9);


Resetting or Modifying the ID Numbering Scheme Used in Bahmni

If you want to reset the patient ID generator, so that it starts again from a Fixed number, then you can fire the below UPDATE query. Here for instance, the suffix is being changed to /15 (to indicate year 2015 has started), and the patient id is being reset to number 1.

Sequence and suffix reset query
UPDATE `openmrs`.`idgen_seq_id_gen` SET `next_sequence_value`='1', `suffix`='/15' WHERE `id`='1';


Auto Increment Logic for Registration Numbers

Auto generation of ID's in registration page works based on the last generated sequence number. But, it also looks at Manuallyentered IDs, to ensure an auto generated ID doesn't clash with a manually entered id. The logic is such that if the system detects a manually entered ID greater than the last auto generated id, then the next generated id starts from 1 more than the last manually entered id.  

Scenario 1: If the manually entered Id is lesser than the auto generated sequence, then the next auto generated Id will continue to follow the auto generated Id. For example: Suppose last auto generated Id is "200070" and after this there was a patient created with manual Id "200060". Now if a patient is created with auto generated Id, the new ID would be "200071".

Scenario 2: If the manually entered Id is greater than the auto generated Id, then the next sequence will respect the manual Id. For example: Lets say the last auto generated Id is "200070" and after this a patient was created with Id manually entered as "200080". Now if a patient is created with auto generated Id, the Id would be "200081".


Creating extra identifierTypes (or secondary identifiers)

Very often users may want to store extra identifiers against a patient, like National Health ID, or Social Security Number, etc. besides the Bahmni generated patient ID. This can be achieved by using OpenMRS's extraIdentifierTypes, which allows you to choose one or more OpenMRS Identifiers as "extraIdentifier". Once you define these identifiers in OpenMRS (along with constraints like Globally Unique, or Regular Expressions / pattern, or Mandatory/Optional), you can the configure Bahmni to show these extra Identifier fields in Patient Registration Page.

OpenMRS Admin UI, in Bahmni, has a global property called 'bahmni.extraPatientIdentifierTypes'. It accepts the list of UUIDs of the Patient Identifier Type that one want to use in Bahmni. Bahmni uses this UUID to fetch the list of identifier sources.  Please refer OpenMRS wiki for details about Identifier sources and types.

Also see this example, where India's ABHA Number (Health Number) is being captured as an extra Identifier. Link:

  1. Liquibase entries to add ABHA Number into Database: https://github.com/BahmniIndiaDistro/openmrs-module-hip/blob/master/api/src/main/resources/liquibase.xml#L27
  2. Bahmni clinic-config specifying extraIdentifiers as read only: https://github.com/BahmniIndiaDistro/clinic-config/blob/main/openmrs/apps/registration/app.json#L26

You can also modify clinical dashboard / patient queue search to show or search patients based on this additional identifier. See:

  1. Patient Context Display Control
  2. https://github.com/BahmniIndiaDistro/clinic-config/blob/main/openmrs/apps/clinical/extension.json#L22
  3. Configure Patient Search & Display Attributes

Till 0.88 bahmni.extraPatientIdentifierTypes was called as emr.extraPatientIdentifierTypes

Where are the extra Identifiers seen?

The extra identifiers will be listed in registration page along side primary identifier type.

The extra identifier names should not be "Patient Identifier" because it is currently reserved for primary identifier.

The Bahmni documentation is licensed under Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)