public AcceptedResult LinkFor( [FromHeader(Name = CORRELATION_ID)] string correlationId, [FromBody] LinkReferenceRequest request) { backgroundJob.Enqueue(() => LinkPatient(request, correlationId)); return(Accepted()); }
public async Task LinkPatient(LinkReferenceRequest request) { var cmUserId = request.Patient.Id; var cmSuffix = cmUserId.Substring( cmUserId.LastIndexOf("@", StringComparison.Ordinal) + 1); var patient = new LinkEnquiry( cmSuffix, cmUserId, request.Patient.ReferenceNumber, request.Patient.CareContexts); try { var doesRequestExists = await discoveryRequestRepository.RequestExistsFor( request.TransactionId, request.Patient?.Id, request.Patient?.ReferenceNumber); ErrorRepresentation errorRepresentation = null; if (!doesRequestExists) { errorRepresentation = new ErrorRepresentation( new Error(ErrorCode.DiscoveryRequestNotFound, ErrorMessage.DiscoveryRequestNotFound)); } var patientReferenceRequest = new PatientLinkEnquiry(request.TransactionId, request.RequestId, patient); var patientLinkEnquiryRepresentation = new PatientLinkEnquiryRepresentation(); var(linkReferenceResponse, error) = errorRepresentation != null ? (patientLinkEnquiryRepresentation, errorRepresentation) : await linkPatient.LinkPatients(patientReferenceRequest); var linkedPatientRepresentation = new LinkEnquiryRepresentation(); if (linkReferenceResponse != null) { linkedPatientRepresentation = linkReferenceResponse.Link; } var response = new GatewayLinkResponse( linkedPatientRepresentation, error?.Error, new Resp(request.RequestId), request.TransactionId, DateTime.Now.ToUniversalTime(), Guid.NewGuid()); await gatewayClient.SendDataToGateway(PATH_ON_LINK_INIT, response, cmSuffix); } catch (Exception exception) { Log.Error(exception, exception.StackTrace); } }
public AcceptedResult LinkFor([FromBody, BindRequired] LinkReferenceRequest request) { backgroundJob.Enqueue(() => LinkPatient(request)); return(Accepted()); }