Esempio n. 1
0
        public FluVaccineConsentModel GetFluConsent(long eventCustomerId)
        {
            var fluConsentSignature = _fluConsentSignatureRepository.GetByEventCustomerId(eventCustomerId);

            if (fluConsentSignature == null)
            {
                return new FluVaccineConsentModel {
                           EventCustomerId = eventCustomerId
                }
            }
            ;

            var fileIds = new Int64[2];

            fileIds[0] = fluConsentSignature.SignatureFileId;
            if (fluConsentSignature.ClinicalProviderSignatureFileId != null)
            {
                fileIds[1] = (long)fluConsentSignature.ClinicalProviderSignatureFileId;
            }

            var fileFeatch = _fileRepository.GetByIds(fileIds);

            if (fileFeatch == null)
            {
                return(new FluVaccineConsentModel
                {
                    EventCustomerId = eventCustomerId,
                    ClinicalProviderSignatureBytes = null,
                    ClinicalAnswers = null,
                    CustomerAnswers = null,
                    PatientSignatureBytes = null,
                });
            }

            var fluConsentQuestionAllQuestion = _fluConsentQuestionRepository.GetAllQuestions();

            var CustomerQuestion = GetFluConsentQuestion(fluConsentQuestionAllQuestion, (long)FluConsentQuestionsType.CustomerQuestion);

            var ClinicalQuestion = GetFluConsentQuestion(fluConsentQuestionAllQuestion, (long)FluConsentQuestionsType.ClinicalQuestion);

            var fluConsentAnswers = _fluConsentAnswerRepository.GetByEventCustomerId(eventCustomerId);

            var fluConsentCustomerAnswerModel = GetFluConsentAnswer(fluConsentAnswers, CustomerQuestion);
            var fluConsentClinicalAnswerModel = GetFluConsentAnswer(fluConsentAnswers, ClinicalQuestion);

            var fluConsentSignatureFileName = fileFeatch.Where(x => x.Id == fluConsentSignature.SignatureFileId).Select(x => x.Path).SingleOrDefault();

            var eventCustomer = _eventCustomerRepository.GetById(eventCustomerId);
            var mediaLocation = _mediaRepository.GetFluVaccineConsentSignatureLocation(eventCustomer.EventId, eventCustomer.CustomerId);

            var fluConsentSignatureFilePath = Path.Combine(mediaLocation.PhysicalPath, fluConsentSignatureFileName);

            string ClinicalProviderSignatureFileName = "";

            if (fluConsentSignature.ClinicalProviderSignatureFileId > default(long))
            {
                ClinicalProviderSignatureFileName = fileFeatch.Where(x => x.Id == (long)fluConsentSignature.ClinicalProviderSignatureFileId).Select(x => x.Path).SingleOrDefault();
            }

            var ClinicalProviderSignatureFilePath = Path.Combine(mediaLocation.PhysicalPath, ClinicalProviderSignatureFileName);

            var fluVaccineConsentModel = new FluVaccineConsentModel
            {
                EventCustomerId = eventCustomerId
            };

            if (File.Exists(fluConsentSignatureFilePath))
            {
                var fluConsentSignatureFileByte = File.ReadAllBytes(fluConsentSignatureFilePath);
                fluVaccineConsentModel.PatientSignatureBytes = Convert.ToBase64String(fluConsentSignatureFileByte);
            }
            if (File.Exists(ClinicalProviderSignatureFilePath))
            {
                var ClinicalProviderSignatureFileByte = File.ReadAllBytes(ClinicalProviderSignatureFilePath);
                fluVaccineConsentModel.ClinicalProviderSignatureBytes = Convert.ToBase64String(ClinicalProviderSignatureFileByte);
            }
            fluVaccineConsentModel.ClinicalAnswers = fluConsentClinicalAnswerModel;
            fluVaccineConsentModel.CustomerAnswers = fluConsentCustomerAnswerModel;

            return(fluVaccineConsentModel);
        }
Esempio n. 2
0
        public bool SaveAnswers(FluVaccineConsentModel model, long orgRoleUserId)
        {
            var evenntCustomer = _eventCustomerRepository.GetById(model.EventCustomerId);

            if (evenntCustomer == null)
            {
                return(false);
            }

            var signatureLocation = _mediaRepository.GetFluVaccineConsentSignatureLocation(evenntCustomer.EventId, evenntCustomer.CustomerId);

            var version = _fluConsentSignatureRepository.GetLatestVersion(model.EventCustomerId);

            var fluConsentSignature = new FluConsentSignature
            {
                EventCustomerId = model.EventCustomerId,
                Version         = version,
                IsActive        = true,
                CreatedBy       = orgRoleUserId,
                DateCreated     = DateTime.Now
            };

            var answers = new List <FluConsentAnswerModel>();

            if (!model.CustomerAnswers.IsNullOrEmpty())
            {
                answers.AddRange(model.CustomerAnswers);
            }

            if (!model.ClinicalAnswers.IsNullOrEmpty())
            {
                answers.AddRange(model.ClinicalAnswers);
            }

            if (!answers.IsNullOrEmpty())
            {
                var fluConsentAnswers = new List <FluConsentAnswer>();

                var answerVersion = _fluConsentAnswerRepository.GetLatestVersion(model.EventCustomerId);

                foreach (var answer in answers)
                {
                    var fluConsentAnswer = new FluConsentAnswer
                    {
                        EventCustomerId = model.EventCustomerId,
                        QuestionId      = answer.QuestionId,
                        Answer          = answer.Answer,
                        Version         = answerVersion + 1,
                        IsActive        = true,
                        DateCreated     = DateTime.Now,
                        CreatedBy       = orgRoleUserId
                    };

                    fluConsentAnswers.Add(fluConsentAnswer);
                }

                _fluConsentAnswerRepository.SaveAnswer(fluConsentAnswers);
            }

            if (!string.IsNullOrWhiteSpace(model.PatientSignatureBytes))
            {
                var fileName = "PatientSignature_" + Guid.NewGuid() + ".jpg";

                var patientImageFile = SaveSignatureImage(model.PatientSignatureBytes, orgRoleUserId, signatureLocation, fileName);

                fluConsentSignature.SignatureFileId   = patientImageFile.Id;
                fluConsentSignature.ConsentSignedDate = DateTime.Now;
            }

            //If Clinical Provider Signature provided before Patient Signature, we will not save the consent data.
            if (!string.IsNullOrWhiteSpace(model.ClinicalProviderSignatureBytes))
            {
                var fileName = "ClinicalProviderSignature_" + Guid.NewGuid() + ".jpg";

                var clinicalProviderImageFile = SaveSignatureImage(model.ClinicalProviderSignatureBytes, orgRoleUserId, signatureLocation, fileName);

                fluConsentSignature.ClinicalProviderSignatureFileId = clinicalProviderImageFile.Id;
            }

            _fluConsentSignatureRepository.Save(fluConsentSignature);

            var consentQuestion = model.CustomerAnswers.FirstOrDefault(x => x.QuestionId == ReceiveVaccinationQuestionId);

            if (consentQuestion != null && consentQuestion.Answer.ToLower() == Boolean.TrueString.ToLower())
            {
                evenntCustomer.IsFluVaccineConsentSigned = true;
                _eventCustomerRepository.Save(evenntCustomer);
            }
            else
            {
                evenntCustomer.IsFluVaccineConsentSigned = false;
                _eventCustomerRepository.Save(evenntCustomer);
            }

            return(true);
        }