lh-ehr icon indicating copy to clipboard operation
lh-ehr copied to clipboard

Possible duplicate PID generated when patient is deleted

Open muarachmann opened this issue 5 years ago • 4 comments

Deleted a patient and choosed delete and log which ran successfully. Afterwards created another patient and want to delete this -> Choosed delete and log. I get this error

screen shot 2019-01-21 at 1 27 22 am

This happens because it is trying to insert in to the patients recycler the same patient with the same PID.

  • How can this be possible when i deleted the user? I think the PID generation starts back from where it left off of which i think it should continue changing no matter whether the user was deleted or not

muarachmann avatar Jan 21 '19 00:01 muarachmann

When a patient gets deleted, the PID generation starts back from 154801 . That is what i noticed Isn't the PID generation be unique?

muarachmann avatar Jan 21 '19 00:01 muarachmann

There is a function called GEN_ID or something like that...quite terrible frankly. We have another thing used for encounter ID's that is an index value stored in a table called "sequences". If deleting the pid results in the autoincrement value dropping by one (meaning you deleted the last patient entered) then this behavior could result. Deleting any other would cause no issue.

Desired behavior on part of the "undeleter" would be to check for the pid in patient_data, then, if it exists, MAX+1 the patient_data table values (or id of patient_data), then use that variable in the insert query, then use the original pid or row to delete the backup version.

aethelwulffe avatar Jan 22 '19 14:01 aethelwulffe

@aethelwulffe how is the PID different from the id column in the patient_data table?

muarachmann avatar Jan 22 '19 15:01 muarachmann

It just can be. Normally they are in sync, but old databases have gotten out of sync in the past due to the GEN_ID function being a stupid idea. id, pid, and pubpid can be the same...but don't count on it. You can plainly see that the deleter itself will cause this.

aethelwulffe avatar Jan 22 '19 15:01 aethelwulffe