public async Task <ActionResult> HealthInformationRequestFor( [FromBody] HealthInformationRequest healthInformationRequest, [FromHeader(Name = "X-GatewayID")] string consentManagerId) { var(healthInformationResponse, error) = await dataFlow .HealthInformationRequestFor(healthInformationRequest, consentManagerId); return(error != null?ServerResponseFor(error) : Ok(healthInformationResponse)); }
public async Task <Tuple <HealthInformationTransactionResponse, ErrorRepresentation> > HealthInformationRequestFor( HealthInformationRequest request, string gatewayId, string correlationId) { var consent = await consentRepository.GetFor(request.Consent.Id); if (consent == null) { return(ConsentArtefactNotFound()); } var dataRequest = new DataRequest(consent.ConsentArtefact.CareContexts, request.DateRange, request.DataPushUrl, consent.ConsentArtefact.HiTypes, request.TransactionId, request.KeyMaterial, gatewayId, consent.ConsentArtefactId, consent.ConsentArtefact.ConsentManager.Id, correlationId); var result = await dataFlowRepository.SaveRequest(request.TransactionId, request).ConfigureAwait(false); var(response, errorRepresentation) = result.Map(r => { var errorResponse = new ErrorRepresentation(new Error(ErrorCode.ServerInternalError, ErrorMessage.InternalServerError)); return(new Tuple <HealthInformationTransactionResponse, ErrorRepresentation>(null, errorResponse)); }).ValueOr(new Tuple <HealthInformationTransactionResponse, ErrorRepresentation>(new HealthInformationTransactionResponse(request.TransactionId), null)); if (errorRepresentation != null) { logger.Log(LogLevel.Error, LogEvents.DataFlow, "Failed to save data request: {@ErrorRepresentation}", errorRepresentation); return(new Tuple <HealthInformationTransactionResponse, ErrorRepresentation>(null, errorRepresentation)); } if (IsExpired(request.KeyMaterial.DhPublicKey.Expiry)) { var errorResponse = new ErrorRepresentation(new Error(ErrorCode.ExpiredKeyPair, ErrorMessage.ExpiredKeyPair)); logger.Log(LogLevel.Error, LogEvents.DataFlow, "Encryption key expired: {@ErrorRepresentation}", errorResponse); return(new Tuple <HealthInformationTransactionResponse, ErrorRepresentation>(null, errorResponse)); } PublishDataRequest(dataRequest); return(new Tuple <HealthInformationTransactionResponse, ErrorRepresentation>(response, null)); }
public async Task <Option <Exception> > SaveRequest( string transactionId, HealthInformationRequest request) { var dataFlowRequest = new DataFlowRequest(transactionId, request); try { dataFlowContext.DataFlowRequest.Add(dataFlowRequest); await dataFlowContext.SaveChangesAsync(); return(Option.None <Exception>()); } catch (Exception exception) { Log.Fatal(exception, "Error Occured"); return(Option.Some(exception)); } }