there should be a merge operation on the fhir server for this, or you should be able to use the link element on a patient to assign one as the mast record. See https://www.hl7.org/fhir/patient.html or https://www.hl7.org/fhir/patient-operation-merge.html for more info.
We sent the EnsLib.HTTP.GenericService into a process that did this, hope it helps.
Class Component.httpResendMessage Extends Ens.BusinessProcess
{
Method OnRequest(pRequest As EnsLib.HTTP.GenericMessage, Output pResponse As EnsLib.HTTP.GenericMessage) As %Status
{
set tSC=$$$OK
s namespace = $REPLACE(pRequest.HTTPHeaders.GetAt("IParams_1"),"namespace=","")
s ClientDocGUID= $REPLACE(pRequest.HTTPHeaders.GetAt("IParams_2"),"ClientDocGUID=","")
s pResponse=##class(EnsLib.HTTP.GenericMessage).%New()
set pResponseBody=##Class(%Stream.GlobalCharacter).%New()
d pResponseBody.Write("<HTML><HEAD>Uh oh.</HEAD><BODY><BR><STRONG>Error: Invalid Patient ID</STRONG></BODY></HTML>")
do pResponseBody.Rewind()
d pResponse.HTTPHeaders.SetAt("HTTP/1.1 400 Bad Request","StatusLine")
d pResponse.HTTPHeaders.SetAt("text/html; charset=utf-8","Content-Type")
do pResponse.StreamSet(pResponseBody)
quit tSC
}
}