Client assigned IDs #1175
Replies: 4 comments 2 replies
-
This will require a series of DB migrations:
|
Beta Was this translation helpful? Give feedback.
-
While this is not implemented, it could be a good idea to validate the incoming ID so the server doesn't respond with 500: Searchable:
|
Beta Was this translation helpful? Give feedback.
-
We do a lot of importing from other systems so feel free to reach out if you're looking for beta testers and feedback on the implementation. |
Beta Was this translation helpful? Give feedback.
-
I tried to sketch out a rough migration plan to allow for client-assigned IDs. This would add a new
ALTER TABLE "Patient" ADD COLUMN IF NOT EXISTS _id TEXT NOT NULL;
const resourceID = resource.id ?? randomUUID();
const projectID = resource.meta.project;
await new InsertQuery('Patient', [{
id: uuid.v5('Patient/'+resourceID, projectID),
_id: resourceID,
lastUpdated: new Date(),
content: resource,
projectId: projectID,
// ...
}]).execute(db); On read: let resource = JSON.parse(row.content);
if (row._id) {
resource = { ...resource, id: row._id };
}
let hasRows = true;
while hasRows {
await db.query('BEGIN')
const rows = await db.query('SELECT id, projectId FROM "Patient" WHERE _id = '' LIMIT 1000 FOR UPDATE');
for (const row of rows) {
const newID = uuid.v5('Patient/'+row.id, row.projectId);
await db.query('UPDATE "Patient" SET id = $1, _id = $2 WHERE id = $2', newID, row.id);
}
await db.query('COMMIT')
hasRows = rows.length > 0;
} |
Beta Was this translation helpful? Give feedback.
-
At present, the Medplum FHIR server only allows server assigned ID's. The FHIR spec optionally allows client assigned ID's using "Update as Create" (reference).
Topics for discussion:
Pros/Cons
Pros:
StructureDefinition/Patient
)Cons:
TEXT
orVARCHAR
column, which will inherently have worse performance thanUUID
In my mind, the pros outweigh the cons, and this seems like an inevitable architectural decision. So the question is more "when" than "if".
Technical considerations
If we pursue client assigned IDs, here is a list of required changes:
UUID
, then this could be the currentid
value, because they are all server assigned(projectId, fhirId)
- this will be the main index for "read by id" operationsTEXT
vsVARCHAR
try/catch
block, so it's probably a washprojectId
fhirId
Open questions
Experiments to run
C
orPOSIX
) on the resource ID column?md4sums
index be better?Recommended reading
Beta Was this translation helpful? Give feedback.
All reactions