In our implementation we are loading encounter types via MDS packages, however the encounter_type_id is not maintained as expected, but rather a new auto-increment id is used. My expectation was that metadata deploy should preserve these ids as we use them in SQL querying etc.
The import type is set to mirror, which means the import overwrites local data with that on the import. Any way we can change to ensure expected behavior as the import can fail due if the key already exists or to overrwrite existing data.
@ssmusoke, actually the Metadata Sharing module and the Metadata Deploy module do not preserve primary key ids (for anything), and there’s really no way to do this (by design), nor does the OpenMRS API really support this.
Broadly speaking, you should avoid relying on having primary keys be the same across different server installations, because this is only going to get you in trouble in the long run. Instead, you should do something like what PIH does here and here. Then, when you’re generating the SQL for a report, you would fetch the relevant encounter type from the DB by UUID and substitute its primary key id into the SQL. (@mseaton, can you provide a quick link to an example of this?)
If you truly want to mirror including primary keys, then you should consider the approach that @raff introduced in the dataexchange module. See usage here.
Not sure what @darius was referring to @ssmusoke, but a few examples I can think of:
Thanks Mike, this is exactly what I meant, e.g.
sql = replace(sql, "phoneType", mrp.getTelephoneNumberPersonAttributeType());