Example #1
0
        public async Task <bool> ChangeBranchDeleteCheck(Guid branchId)
        {
            var branch = _commonDataService.GetEntity <Branch>(x => x.Id == branchId).FirstOrDefault();

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

            //TODO check if correct
            //branch.LicenseDeleteCheck = !branch.LicenseDeleteCheck ?? true;

            if (branch.LicenseDeleteCheck == null)
            {
                branch.LicenseDeleteCheck = true;
            }
            else
            {
                branch.LicenseDeleteCheck = !branch.LicenseDeleteCheck;
            }

            try
            {
                await _commonDataService.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Example #2
0
        public async Task <JsonResult> DeleteContractor(Guid id)
        {
            try
            {
                var contractor = _dataService.GetEntity <PrlContractor>(x => x.Id == id).SingleOrDefault();
                contractor.RecordState = RecordState.D;
                var contrBranches = _dataService.GetEntity <PrlBranchContractor>(x => x.ContractorId == contractor.Id)
                                    .ToList();
                contrBranches.ForEach(x => x.RecordState = RecordState.D);
                await _dataService.SaveChangesAsync();

                return(await Task.FromResult(Json(new { success = true })));
            }
            catch (Exception e)
            {
                return(await Task.FromResult(Json(new { success = false, ErrorMessage = "Помилка видалення. " + (e.InnerException ?? e).Message })));
            }
        }
Example #3
0
        public async Task <bool> ChangeCheck(Guid sendId)
        {
            var drug = DataService.GetEntity <ResultInputControl>(x => x.Id == sendId).FirstOrDefault();

            if (drug == null)
            {
                return(false);
            }
            try
            {
                drug.SendCheck = !drug.SendCheck;
                await DataService.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
Example #4
0
        public async Task <AppAssigneeDetailDTO> EditLicense(AppAssigneeDetailDTO model)
        {
            var assigneeBranches = DataService.GetEntity <AppAssigneeBranch>(x => x.AssigneeId == model.Id).ToList();
            var branches         = DataService.GetEntity <Branch>(x => assigneeBranches.Select(y => y.BranchId).Contains(x.Id)).ToList();
            var branchesToDelete = branches.Where(x => x.IsFromLicense != true).ToList();

            assigneeBranches.Where(x => branchesToDelete.Select(y => y.Id).Contains(x.BranchId)).ToList().ForEach(x => DataService.Remove(x));
            model.ListOfBranches?.ForEach(branchId => DataService.Add(new AppAssigneeBranch
            {
                AssigneeId = model.Id,
                BranchId   = branchId
            }));

            await DataService.SaveChangesAsync();

            return(model);
        }
Example #5
0
        public async Task <IActionResult> SubmitApplication(Guid id)
        {
            if (id == Guid.Empty)
            {
                return(await Task.Run(() => NotFound()));
            }
            var app = _commonDataService.GetEntity <ImlApplication>(x => x.Id == id)?.FirstOrDefault();

            if (app == null)
            {
                return(await Task.Run(() => NotFound()));
            }
            app.AppState = "Submitted";
            await _commonDataService.SaveChangesAsync();

            return(RedirectToAction("Index", "Home", new { Area = "" }));
        }
Example #6
0
        public async Task <IActionResult> CreateOnOpen(Guid appId, string documentType, string sort, string appType, Guid?msgId)
        {
            if (appId == Guid.Empty)
            {
                return(NotFound());
            }
            var dto = new EDocumentDetailsDTO()
            {
                EDocumentType = documentType
            };
            var id = _dataService.Add <EDocument>(dto);
            await _dataService.SaveChangesAsync();

            return(msgId == null
                ? RedirectToAction("Edit", new { id, appId, sort, appType })
                : RedirectToAction("EditMsg", new { id, msgId }));
        }
        public async Task <Guid> ProcessApplicationToApplication(Guid appId, Guid?licenseId = null, string sort = "", bool isBackOffice = false)
        {
            var licenseApplication = _commonDataService.GetEntity <ImlApplication>(x => x.Id == appId)
                                     .FirstOrDefault();

            if (licenseApplication == null)
            {
                Log.Error("licenseApplication == null");
                throw new NullReferenceException("Виникла помилка");
            }

            var newApplication = new ImlApplication();

            _objectMapper.Map(licenseApplication, newApplication);
            newApplication.Id = Guid.NewGuid();

            //ссылка на дочернюю заяву, из которой создана лицензия
            if (licenseId == null || licenseId == Guid.Empty)
            {
                newApplication.ParentId = licenseApplication.ParentId;
            }
            else
            {
                newApplication.ParentId = licenseId;
            }

            if (!string.IsNullOrEmpty(sort))
            {
                newApplication.AppSort = sort;
            }
            else
            {
                newApplication.AppSort = licenseApplication.AppSort;
            }

            if (isBackOffice)
            {
                newApplication.IsCreatedOnPortal  = false;
                newApplication.AppState           = null;
                newApplication.BackOfficeAppState = "Project";
            }
            else
            {
                newApplication.AppState           = "Project";
                newApplication.BackOfficeAppState = null;
                newApplication.IsCreatedOnPortal  = true;
            }

            newApplication.AppType                    = "IML";
            newApplication.ModifiedOn                 = DateTime.Now;
            newApplication.IsCheckMpd                 = false;
            newApplication.IsPaperLicense             = false;
            newApplication.IsCourierDelivery          = false;
            newApplication.IsPostDelivery             = false;
            newApplication.IsAgreeLicenseTerms        = false;
            newApplication.IsAgreeProcessingData      = false;
            newApplication.IsCourierResults           = false;
            newApplication.IsPostResults              = false;
            newApplication.IsElectricFormResults      = false;
            newApplication.IsProtectionFromAggressors = false;
            newApplication.Comment                    = "";

            newApplication.ErrorProcessingLicense = null;
            newApplication.PerformerOfExpertise   = null;
            newApplication.ExpertiseDate          = null;
            newApplication.ExpertiseResult        = null;
            newApplication.AppPreLicenseCheckId   = null;
            newApplication.AppLicenseMessageId    = null;
            newApplication.AppDecisionId          = null;
            newApplication.PerformerId            = null;
            newApplication.RegDate     = null;
            newApplication.RegNumber   = null;
            newApplication.Description = null;
            newApplication.OldLimsId   = 0;

            var organizationInfo = _commonDataService.GetEntity <OrganizationInfo>(x => x.Id == licenseApplication.OrganizationInfoId)
                                   .FirstOrDefault();

            if (organizationInfo == null)
            {
                Log.Error("organizationInfo == null");
                throw new NullReferenceException("Виникла помилка");
            }

            var newOrganizationInfo = new OrganizationInfo();

            _objectMapper.Map(organizationInfo, newOrganizationInfo);
            newOrganizationInfo.Id = Guid.NewGuid();
            if (licenseId != null)
            {
                newOrganizationInfo.IsActualInfo = false;
            }
            else
            {
                newOrganizationInfo.IsActualInfo = true;
                _commonDataService.GetEntity <OrganizationInfo>(
                    x => x.OrganizationId == licenseApplication.OrgUnitId).ToList().ForEach(x => x.IsActualInfo = false);
            }

            newApplication.OrganizationInfoId = newOrganizationInfo.Id;
            _commonDataService.Add(newOrganizationInfo);

            var licenseBranches = new List <Branch>();
            var licenseBranch   = new List <ApplicationBranch>();

            var applicationBranchesIds = _commonDataService
                                         .GetEntity <ApplicationBranch>(x => x.LimsDocumentId == licenseApplication.Id)
                                         .Select(x => x.BranchId)
                                         .Distinct()
                                         .ToList();
            var applicationBranches = _commonDataService.GetEntity <Branch>(br => applicationBranchesIds.Contains(br.Id))
                                      .ToList();

            foreach (var branch in applicationBranches)
            {
                var licBr = _objectMapper.Map <Branch>(branch);
                licBr.Id = Guid.NewGuid();
                //ссылка на дочерний обьект мпд
                licBr.ParentId      = branch.Id;
                licBr.IsFromLicense = true;
                licenseBranches.Add(licBr);

                licenseBranch.Add(new ApplicationBranch
                {
                    BranchId       = licBr.Id,
                    LimsDocumentId = newApplication.Id
                });
            }

            var applicationAssigneeBranches =
                _commonDataService.GetEntity <AppAssigneeBranch>(x => applicationBranchesIds.Contains(x.BranchId));
            var applicationAssigneeIds = applicationAssigneeBranches.Select(x => x.AssigneeId).Distinct().ToList();
            var applicationAssignee    =
                _commonDataService.GetEntity <AppAssignee>(x => applicationAssigneeIds.Contains(x.Id));
            var licenseAssigneeBranches = new List <AppAssigneeBranch>();
            var licenseAssignees        = new List <AppAssignee>();

            foreach (var assignee in applicationAssignee)
            {
                var licAssignee = _objectMapper.Map <AppAssignee>(assignee);
                licAssignee.Id            = Guid.NewGuid();
                licAssignee.IsFromLicense = true;
                licenseAssignees.Add(licAssignee);

                var assBranches = applicationAssigneeBranches.Where(x => x.AssigneeId == assignee.Id);
                foreach (var appAssigneeBranch in assBranches)
                {
                    licenseAssigneeBranches.Add(new AppAssigneeBranch
                    {
                        AssigneeId = licAssignee.Id,
                        BranchId   = licenseBranches.FirstOrDefault(br => br.ParentId == appAssigneeBranch.BranchId).Id
                    });
                }
            }


            var applicationEdocumentBranches =
                _commonDataService.GetEntity <BranchEDocument>(x => applicationBranchesIds.Contains(x.BranchId));
            var applicationEdocumentIds = applicationEdocumentBranches.Select(x => x.EDocumentId).Distinct().ToList();
            var applicationEdocuments   = _commonDataService
                                          .GetEntity <EDocument>(x => applicationEdocumentIds.Contains(x.Id)).ToList();
            var licenseEdocumentBranches = new List <BranchEDocument>();
            var licenseEdocuments        = new List <EDocument>();
            var licenseFiles             = new List <FileStore>();

            foreach (var applicationEDocument in applicationEdocuments)
            {
                var licEDocument = _objectMapper.Map <EDocument>(applicationEDocument);
                licEDocument.Id            = Guid.NewGuid();
                licEDocument.IsFromLicense = true;
                licenseEdocuments.Add(licEDocument);

                var edocBranches = applicationEdocumentBranches.Where(x => x.EDocumentId == applicationEDocument.Id);
                foreach (var branchEdocument in edocBranches)
                {
                    licenseEdocumentBranches.Add(new BranchEDocument()
                    {
                        EDocumentId = licEDocument.Id,
                        BranchId    = licenseBranches.FirstOrDefault(br => br.ParentId == branchEdocument.BranchId).Id
                    });
                }
                var fileStore = _commonDataService
                                .GetEntity <FileStore>(x => x.EntityName == "EDocument" && x.EntityId == applicationEDocument.Id).ToList();
                fileStore.ForEach(x =>
                {
                    x.EntityId = licEDocument.Id;
                    x.Id       = Guid.NewGuid();
                    licenseFiles.Add(x);
                });
            }

            var imlMedicine  = (await _commonDataService.GetDtoAsync <ImlMedicineDetailDTO>(x => x.ApplicationId == appId)).ToList();
            var imlMedicines = new List <ImlMedicine>();

            foreach (var med in imlMedicine)
            {
                var imlMed = _objectMapper.Map <ImlMedicine>(med);
                imlMed.Id            = Guid.NewGuid();
                imlMed.ApplicationId = newApplication.Id;
                imlMed.IsFromLicense = true;
                imlMedicines.Add(imlMed);
            }

            _commonDataService.Add(newApplication, false);
            licenseBranches.ForEach(branch => _commonDataService.Add(branch, false));
            licenseBranch.ForEach(appBranch => _commonDataService.Add(appBranch, false));
            licenseAssignees.ForEach(assignee => _commonDataService.Add(assignee, false));
            licenseAssigneeBranches.ForEach(assigneeBr => _commonDataService.Add(assigneeBr, false));
            licenseEdocuments.ForEach(eDoc => _commonDataService.Add(eDoc, false));
            licenseEdocumentBranches.ForEach(eDocBra => _commonDataService.Add(eDocBra, false));
            licenseFiles.ForEach(x => _commonDataService.Add(x, false));
            await _commonDataService.SaveChangesAsync();

            await _imlMedicineService.SaveMedicines(imlMedicines);

            return(newApplication.Id);
        }
Example #8
0
        public async Task <Guid> Save(BranchDetailsDTO model)
        {
            var check = model.Id == Guid.Empty;

            if (check)
            {
                model.IsFromLicense = false;
            }

            var branchId = _dataService.Add <Branch>(model);
            await _dataService.SaveChangesAsync();

            if (check)
            {
                var applicationBranch = new ApplicationBranch
                {
                    LimsDocumentId = model.ApplicationId,
                    BranchId       = branchId
                };
                _dataService.Add(applicationBranch);
                await _dataService.SaveChangesAsync();

                if (model.AppType == "TRL")
                {
                    //Вид діяльності обраний в МПД
                    var trlActivityTypeEnum = _dataService.GetEntity <EnumRecord>(x => x.Code == model.TrlActivityType)?.FirstOrDefault();
                    _dataService.Add(new EntityEnumRecords()
                    {
                        EntityId       = branchId,
                        EntityType     = "BranchApplication",
                        EnumRecordType = trlActivityTypeEnum?.EnumType,
                        EnumRecordCode = trlActivityTypeEnum?.Code
                    });

                    if (model.PharmacyId != null)
                    {
                        _dataService.Add(new PharmacyItemPharmacy()
                        {
                            PharmacyId     = model.PharmacyId.Value,
                            PharmacyItemId = branchId
                        });
                    }

                    await _dataService.SaveChangesAsync();
                }
            }
            else
            {
                if (model.AppType == "TRL")
                {
                    var pharmacyItem = _dataService.GetEntity <PharmacyItemPharmacy>(x => x.PharmacyItemId == branchId)?.FirstOrDefault();
                    if (pharmacyItem != null)
                    {
                        _dataService.Remove(pharmacyItem);
                    }

                    if (model.PharmacyId != null)
                    {
                        _dataService.Add(new PharmacyItemPharmacy()
                        {
                            PharmacyId     = model.PharmacyId.Value,
                            PharmacyItemId = branchId
                        });
                    }

                    var entityEnumRecords =
                        _dataService.GetEntity <EntityEnumRecords>(x => x.EntityId == branchId).ToList();

                    if (entityEnumRecords.Count > 0)
                    {
                        entityEnumRecords.ForEach(x => _dataService.Remove(x));
                    }

                    //Види діяльності обрані в МПД
                    var trlActivityTypeEnum = _dataService.GetEntity <EnumRecord>(x => x.Code == model.TrlActivityType)?.FirstOrDefault();
                    _dataService.Add(new EntityEnumRecords()
                    {
                        EntityId       = branchId,
                        EntityType     = "BranchApplication",
                        EnumRecordType = trlActivityTypeEnum?.EnumType,
                        EnumRecordCode = trlActivityTypeEnum?.Code
                    });

                    await _dataService.SaveChangesAsync();
                }
            }
            return(branchId);
        }
Example #9
0
        public async Task <List <string> > UploadMedicine(Guid?appId, IFormFile file)
        {
            var countOfErrors = 0;
            var cellErrors    = new List <string>();
            var medicines     = new List <ImlMedicine>();

            using (var excelPackage = new ExcelPackage(file.OpenReadStream()))
            {
                var workbook    = excelPackage.Workbook;
                var worksheet   = workbook.Worksheets.First();
                var row         = 9;
                var checkString = "";
                var limsRps     = await DataService.GetDtoAsync <LimsRPMinDTO>(x => x.EndDate > DateTime.Now && x.OffOrderDate == null, extraParameters : new object[] { "" });

                do
                {
                    var    imlMedicine  = new ImlMedicine();
                    var    checkOnError = false;
                    string cellNum      = "";
                    for (var col = 1; col < 14; col++)
                    {
                        var cell     = worksheet.Cells[row, col].First();
                        var valueObj = cell.Value;
                        if (valueObj != null)
                        {
                            var value = valueObj.ToString();
                            switch (col)
                            {
                            case 1:
                                cellNum = value;
                                break;

                            case 2:
                                imlMedicine.MedicineName = value;
                                checkString = value;
                                break;

                            case 3:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.FormName = value;
                                break;

                            case 4:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.DoseInUnit = value;
                                break;

                            case 5:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.NumberOfUnits = value;
                                break;

                            case 6:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.MedicineNameEng = value;
                                break;

                            case 7:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                var rplz = limsRps.FirstOrDefault(x => x.RegNum == value);
                                if (rplz == null)
                                {
                                    cellErrors.Add(cellNum);
                                    checkOnError = true;
                                    break;
                                }
                                else
                                {
                                    imlMedicine.LimsRpId = rplz.Id;
                                }

                                imlMedicine.RegisterNumber = value;
                                break;

                            case 8:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.AtcCode = value;
                                break;

                            case 9:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.ProducerName = value;
                                break;

                            case 10:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.ProducerCountry = value;
                                break;

                            case 11:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.SupplierName = value;
                                break;

                            case 12:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.SupplierCountry = value;
                                break;

                            case 13:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.SupplierAddress = value;
                                break;

                            case 14:
                                if (string.IsNullOrEmpty(value))
                                {
                                    checkOnError = true;
                                }
                                imlMedicine.Notes = value;
                                break;
                            }
                        }
                        else
                        {
                            if (col == 2)
                            {
                                checkString  = string.Empty;
                                checkOnError = true;
                                break;
                            }
                        }

                        //if (checkOnError)
                        //    break;
                    }

                    imlMedicine.ApplicationId = appId.Value;
                    imlMedicine.CreatedByJson = _userInfo.PersonId;

                    if (!checkOnError)
                    {
                        medicines.Add(imlMedicine);
                    }
                    //else
                    //    countOfErrors++;

                    row++;
                } while (!string.IsNullOrEmpty(checkString));

                await SaveMedicines(medicines);
            }
            var fileStore = new FileStoreDTO
            {
                FileType     = FileType.Unknown,
                OrigFileName = file.Name + ".xlsx",
                FileSize     = file.Length,
                Ock          = false,
                EntityId     = appId.Value,
                EntityName   = nameof(ImlApplication),
                ContentType  = ".xlsx",
                Description  = "Medicines"
            };
            var dto = FileStoreHelper.SaveFile(_configuration, file, fileStore);

            DataService.Add <FileStore>(dto);
            await DataService.SaveChangesAsync();

            return(cellErrors);
        }
Example #10
0
        public async Task <bool> ChangeCheckBox(string checkBoxId, Guid appId)
        {
            var application = _commonDataService.GetEntity <T>(x => x.Id == appId && x.RecordState != RecordState.D).SingleOrDefault();

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

            switch (checkBoxId)
            {
            case "IsCheckMPD":
                application.IsCheckMpd = !application.IsCheckMpd;
                break;

            case "IsPaperLicense":
                application.IsPaperLicense = !application.IsPaperLicense;
                break;

            case "IsCourierDelivery":
                application.IsCourierDelivery = !application.IsCourierDelivery;
                break;

            case "IsPostDelivery":
                application.IsPostDelivery = !application.IsPostDelivery;
                break;

            case "IsCourierResults":
                application.IsCourierResults = !application.IsCourierResults;
                break;

            case "IsPostResults":
                application.IsPostResults = !application.IsPostResults;
                break;

            case "IsElectricFormResults":
                application.IsElectricFormResults = !application.IsElectricFormResults;
                break;

            case "IsAgreeLicenseTerms":
                application.IsAgreeLicenseTerms = !application.IsAgreeLicenseTerms;
                break;

            case "IsAgreeProcesingData":
                application.IsAgreeProcessingData = !application.IsAgreeProcessingData;
                break;

            case "IsProtectionFromAggressors":
                application.IsProtectionFromAggressors = !application.IsProtectionFromAggressors;
                break;
            }

            try
            {
                await _commonDataService.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Example #11
0
        public async Task <IActionResult> ListPayment(Guid appId, string appType)
        {
            var eDocumentAppList = (await _dataService.GetDtoAsync <EDocumentPaymentListDTO>(
                                        p => p.EdocumentType == "PaymentDocument",
                                        extraParameters: new object[] { $"\'{appId}\'" })).ToList();

            string entityName = appType == "PRL" ? "PrlApplication" : appType == "IML" ? "ImlApplication" : "TrlApplication";

            ViewBag.AppType = appType;
            var dto = new EDocumentDetailsDTO();

            if (eDocumentAppList.Count == 0)
            {
                dto = new EDocumentDetailsDTO()
                {
                    Id              = Guid.NewGuid(),
                    EDocumentType   = "PaymentDocument",
                    EDocumentStatus = "RequiresPayment",
                    EntityName      = entityName,
                    EntityId        = appId,
                    DateFrom        = DateTime.Now
                };
                _dataService.Add <EDocument>(dto);
                await _dataService.SaveChangesAsync();

                return(PartialView("ListPayment", dto));
            }

            var notVerified = eDocumentAppList.Where(p => p.EdocumentStatus == "PaymentNotVerified")
                              .OrderByDescending(p => p.CreatedOn).FirstOrDefault();
            var docRequires = eDocumentAppList.SingleOrDefault(p => p.EdocumentStatus == "RequiresPayment");

            if (docRequires != null)
            {
                dto = (await _dataService.GetDtoAsync <EDocumentDetailsDTO>(p => p.Id == docRequires.Id,
                                                                            extraParameters: new object[] { $"\'{docRequires.EntityId}\'" })).SingleOrDefault();
                dto.Comment = notVerified?.Comment;

                return(PartialView("ListPayment", dto));
            }

            docRequires = eDocumentAppList.SingleOrDefault(p => p.EdocumentStatus == "WaitingForConfirmation" || p.EdocumentStatus == "PaymentConfirmed");
            if (docRequires != null)
            {
                return(PartialView("ListPayment", new EDocumentDetailsDTO
                {
                    Id = docRequires.Id,
                    EDocumentStatus = docRequires.EdocumentStatus,
                    EntityId = docRequires.EntityId
                }));
            }

            //if PaymentNotVerified
            dto = new EDocumentDetailsDTO()
            {
                Id              = Guid.NewGuid(),
                EDocumentType   = "PaymentDocument",
                EDocumentStatus = "RequiresPayment",
                EntityName      = entityName,
                EntityId        = appId,
                DateFrom        = DateTime.Now
            };
            _dataService.Add <EDocument>(dto);
            await _dataService.SaveChangesAsync();

            dto.Comment = notVerified?.Comment;
            return(PartialView("ListPayment", dto));
        }