OpenMRS ID - Patient Identifier Usage outside OpenMRS

I am looking for the class that is used to generate the OpenMRS ID within code.

Has anyone been able to use this ID generation outside OpenMRS?

Are you looking for a REST API for generating new patient identifiers?

@dkayiwa I was looking for the code in core to understand how it works

However the REST API can also help in this to understand how it would work

Is this good enough for you? https://qa-refapp.openmrs.org/openmrs/ws/rest/v1/idgen/nextIdentifier?source=1

Thanks Daniel that is very helpful, where is the class that generates that ID? I cannot seem to trace it through the code

Are you looking for this? openmrs-module-idgen/SequenceIdentifierResource.java at master · openmrs/openmrs-module-idgen · GitHub

Thanks Stephen and Daniel. Interesting conversation here.

@dkayiwa the link you shared is great. It would be good to know if its possible to extend the generation of the OpenMRS ID on a custom application. Basically I would want clients on a custom app with IDs that are similar to the OpenMRS ID.

Is the a step by step guide on how to set this up?

OpenMRS ID are generated by translating a monotonically increasing integer into the alphabet “0123456789ACDEFGHJKLMNPRTUVWXY” following the Luhn Mod N with a check digit. There are some sample implementations in various languages on the Wikipedia page. The algorithm we use can easily generate overlapping IDs if you don’t have a single source of truth for the monotonically increasing integer and that’s basically the service the identifier source in the ID Gen module provides.

If you just want OpenMRS-like IDs, the above should be enough. If you actually want to integrate those identifiers with an OpenMRS instance, your client should probably just grab a set of identifiers via the REST API and use those.

1 Like

Accidentally issuing the same identifier to more than one patient can create a maintenance nightmare and put patients at risk, so all care must be made to never let this happen (the reason for having a single authority to ensure identifiers are only issued once).

If there is ever doubt, it’s better to throw away an identifier than risk giving it out to a second patient.

Many thanks @ibacher for the feedback.

Yes I will just want OpenMRS like IDs. When I review the Luhn mod N algorithm - Wikipedia, it just only captures check digit algorithms and not how to generate OpenMRS like IDs.

Is there a guide on how to generate OpenMRS like IDs?

Please look at the link that @dkayiwa posted earlier in this thread.

Thanks @ibacher . Yes I saw @dkayiwa 's response.

My challenge is that the code references other OpenMRS classes.

I will want to implement this functionality on a custom app which does not have OpenMRS in the code base.

Please advise.