public async Task LinkPatientCareContextFor(LinkPatientRequest request)
        {
            try
            {
                var(patientLinkResponse, cmId, error) = await linkPatient
                                                        .VerifyAndLinkCareContext(new LinkConfirmationRequest(request.Confirmation.Token,
                                                                                                              request.Confirmation.LinkRefNumber));

                var linkedPatientRepresentation = new LinkConfirmationRepresentation();
                if (patientLinkResponse != null || cmId != "")
                {
                    linkedPatientRepresentation = patientLinkResponse.Patient;
                }

                var response = new GatewayLinkConfirmResponse(
                    Guid.NewGuid(),
                    DateTime.Now.ToUniversalTime(),
                    linkedPatientRepresentation,
                    error?.Error,
                    new Resp(request.RequestId)
                    );
                await gatewayClient.SendDataToGateway(PATH_ON_LINK_CONFIRM, response, cmId);
            }
            catch (Exception exception)
            {
                Log.Error(exception, exception.StackTrace);
            }
        }
 public AcceptedResult LinkPatientFor(
     [FromHeader(Name = CORRELATION_ID)] string correlationId,
     [FromBody] LinkPatientRequest request)
 {
     backgroundJob.Enqueue(() => LinkPatientCareContextFor(request, correlationId));
     return(Accepted());
 }
 public AcceptedResult LinkPatientFor([FromBody, BindRequired] LinkPatientRequest request)
 {
     backgroundJob.Enqueue(() => LinkPatientCareContextFor(request));
     return(Accepted());
 }