This is what we have tried to do in EHR.Network. All the external IDs including the hospital IDs are mapped to the subject_id in the demographic service. This subject_id is in turn linked to the ehr_id. This ensures that we are able to maintain one unique ehr_id for a person.
However the merging of ehr_ids when multiple ones have been created accidentally is a more complex problem. For the sake of clinical accuracy and audit, this will need a workflow and decisions outside the EHR system to validate and document this change before actually doing it within the system. The actual process of merge is implementation specific as it may involve changes to multiple services such as EHR index, EHR and possibly other services that support the clinical application.