Example #1
0
 public AcceptedResult ConsentNotification(
     [FromHeader(Name = CORRELATION_ID)] string correlationId,
     [FromBody] ConsentArtefactRepresentation consentArtefact)
 {
     backgroundJob.Enqueue(() => StoreConsent(consentArtefact, correlationId));
     return(Accepted());
 }
        public async Task StoreConsent(ConsentArtefactRepresentation consentArtefact)
        {
            var notification = consentArtefact.Notification;

            if (notification.Status == ConsentStatus.GRANTED)
            {
                var consent = new Consent(notification.ConsentDetail.ConsentId,
                                          notification.ConsentDetail,
                                          notification.Signature,
                                          notification.Status,
                                          notification.ConsentId);
                await consentRepository.AddAsync(consent);
            }
            else
            {
                await consentRepository.UpdateAsync(notification.ConsentId, notification.Status);

                if (notification.Status == ConsentStatus.REVOKED)
                {
                    var consent = await consentRepository.GetFor(notification.ConsentId);

                    var cmSuffix        = consent.ConsentArtefact.ConsentManager.Id;
                    var gatewayResponse = new GatewayRevokedConsentRepresentation(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        new ConsentUpdateResponse(ConsentUpdateStatus.OK.ToString(),
                                                  notification.ConsentId),
                        null,
                        new Resp(consentArtefact.RequestId));
                    await gatewayClient.SendDataToGateway(PATH_CONSENT_ON_NOTIFY, gatewayResponse, cmSuffix);
                }
            }
        }
        public async Task StoreConsent(ConsentArtefactRepresentation consentArtefact, String correlationId)
        {
            var notification = consentArtefact.Notification;

            if (notification.Status == ConsentStatus.GRANTED)
            {
                var consent = new Consent(notification.ConsentDetail.ConsentId,
                                          notification.ConsentDetail,
                                          notification.Signature,
                                          notification.Status,
                                          notification.ConsentId);
                await consentRepository.AddAsync(consent);

                var patientId = consent.ConsentArtefact.Patient.Id;
                var cmSuffix  = patientId.Substring(
                    patientId.LastIndexOf("@", StringComparison.Ordinal) + 1);
                var gatewayResponse = new GatewayConsentRepresentation(
                    Guid.NewGuid(),
                    DateTime.Now.ToUniversalTime(),
                    new ConsentUpdateResponse(ConsentUpdateStatus.OK.ToString(), notification.ConsentId),
                    null,
                    new Resp(consentArtefact.RequestId));
                await gatewayClient.SendDataToGateway(PATH_CONSENT_ON_NOTIFY, gatewayResponse, cmSuffix, correlationId);
            }
            else
            {
                await consentRepository.UpdateAsync(notification.ConsentId, notification.Status);

                if (notification.Status == ConsentStatus.REVOKED)
                {
                    var consent = await consentRepository.GetFor(notification.ConsentId);

                    var patientId = consent.ConsentArtefact.Patient.Id;
                    var cmSuffix  = patientId.Substring(
                        patientId.LastIndexOf("@", StringComparison.Ordinal) + 1);
                    var gatewayResponse = new GatewayConsentRepresentation(
                        Guid.NewGuid(),
                        DateTime.Now.ToUniversalTime(),
                        new ConsentUpdateResponse(ConsentUpdateStatus.OK.ToString(), notification.ConsentId),
                        null,
                        new Resp(consentArtefact.RequestId));
                    await gatewayClient.SendDataToGateway(PATH_CONSENT_ON_NOTIFY, gatewayResponse, cmSuffix, correlationId);
                }
            }
        }
 public AcceptedResult ConsentNotification([FromBody] ConsentArtefactRepresentation consentArtefact)
 {
     backgroundJob.Enqueue(() => StoreConsent(consentArtefact));
     return(Accepted());
 }