Create a unique index in FHIR resource
# support
m
Hi there, We have been migrating our system to Medplum. (to FHIR) I am wondering if we can not only create a unique index in the FHIR resource but also comply with race condition. We are thinking of adding the index in
identifier
, but we just want to double check if there is any way that can deal with the Medplum feature. The reason why we need this feature is, that we create the QR code for each resource that the user creates. - The QR code has a tiny space so we want to indicate information with just few numbers. Thank you for all your help as always. cc @two4zero_63114
c
Hi @minha_1268 - Good question. Unfortunately, at present, we do not support adding uniqueness constraints at the database level. On our longer term roadmap, we have plans for database sharding (https://github.com/medplum/medplum/discussions/6026), custom search parameters, and custom uniqueness constraints. In the short term, if you want transactional guarantees, you can use FHIR "conditional create" / "conditional update", which will be executed within a proper database transaction. You would need to pair that with a Medplum
AccessPolicy
to ensure only authorized users are allowed to modify those fields. If you are self hosting, you could probably author a uniqueness constraint. If a user tried to make a change that violated the constraint, Medplum server would correctly handle the error and return a HTTP 409 Conflict +
OperationOutcome
explaining the constraint. You would be going off the happy path, but it would work.
m
Gotya. Thanks for the response, cody!
248 Views