Example #1
0
        public async Task SubmitAdditionalInfoToLicense(Guid appId, string text)
        {
            var application = DataService.GetEntity <PrlApplication>(x => x.Id == appId).FirstOrDefault();

            if (application == null)
            {
                throw new Exception();
            }
            var organization = DataService.GetEntity <OrganizationExt>(x => x.Id == application.OrgUnitId).FirstOrDefault();

            if (organization == null)
            {
                throw new Exception();
            }
            var orgInfo = DataService.GetEntity <OrganizationInfo>(x => x.Id == application.OrganizationInfoId)
                          .FirstOrDefault();

            if (orgInfo == null)
            {
                throw new Exception();
            }
            var limsLicense = (await _limsExchangeService.GetLicenses("Prl",
                                                                      string.IsNullOrEmpty(organization.EDRPOU) ?
                                                                      organization.INN : organization.EDRPOU)).FirstOrDefault();
            var newLic = new PrlLicense
            {
                OldLimsId   = limsLicense.Id,
                OrgUnitId   = application.OrgUnitId,
                ParentId    = application.Id,
                LicType     = "PRL",
                LicState    = "Active",
                IsRelevant  = true,
                LicenseDate = DateTime.Parse(limsLicense.RegistrationDate),
                OrderDate   = limsLicense.OrderDate,
                OrderNumber = limsLicense.OrderNumber
            };

            DataService.Add(newLic);

            application.AppState           = "Reviewed";
            application.BackOfficeAppState = "Reviewed";

            orgInfo.IsActualInfo           = true;
            orgInfo.IsPendingLicenseUpdate = false;

            var decision = new AppDecision {
                Id = Guid.NewGuid(), AppId = appId, DecisionType = "Accepted", DecisionDescription = text
            };

            application.AppDecisionId = decision.Id;
            DataService.Add(decision);

            await DataService.SaveChangesAsync();
        }
        public void SaveDecision(AppDecisionDTO model)
        {
            var decision = _dataService.GetEntity <AppDecision>(p => p.Id == model.Id).SingleOrDefault();
            var isUpdate = false;

            if (decision == null)
            {
                decision = new AppDecision();
            }
            else
            {
                _dataService.GetEntity <AppDecisionReason>(p => p.AppDecisionId == decision.Id).ToList()
                .ForEach(x => _dataService.Remove(x));
                isUpdate = true;
            }
            _objectMapper.Map(model, decision);

            foreach (var reason in model.ListOfDecisionReason)
            {
                decision.AppDecisionReasons.Add(new AppDecisionReason {
                    ReasonType = reason, AppDecisionId = decision.Id
                });
            }

            var trl = _dataService.GetEntity <TrlApplication>(p => p.Id == decision.AppId).SingleOrDefault();

            if (trl == null || string.IsNullOrEmpty(trl.ExpertiseResult) || trl.AppState == "Reviewed")
            {
                return;
            }
            trl.AppDecision = decision;

            _dataService.Add(decision, isUpdate);
            _limsExchangeService.ExportDecisionTRL(decision, isUpdate); // TODO: Сделать

            _dataService.SaveChanges();
        }
Example #3
0
 public async Task <IActionResult> AdditionalInfoToLicenseSubmit(Guid id, string type, string text)
 {
     if (string.IsNullOrEmpty(text))
     {
         return(NotFound());
     }
     if (type == "Submit")
     {
         try
         {
             await _imlApplicationService.SubmitAdditionalInfoToLicense(id, text);
         }
         catch (Exception e)
         {
             Log.Error(e.Message);
             return(Json(new { success = false, alert = "Виникла помилка серверу, спробуйте пізніше!" }));
         }
     }
     else if (type == "Reject")
     {
         var app = _imlApplicationService.DataService.GetEntity <ImlApplication>(x => x.Id == id).FirstOrDefault();
         app.BackOfficeAppState = "Reviewed";
         app.AppState           = "Reviewed";
         var decision = new AppDecision {
             Id = Guid.NewGuid(), AppId = id, DecisionType = "Denied", DecisionDescription = text
         };
         app.AppDecisionId = decision.Id;
         _imlApplicationService.DataService.Add(decision);
         await _imlApplicationService.DataService.SaveChangesAsync();
     }
     else
     {
         return(Json(new { success = false, alert = "Неправильно введені дані, спробуйте ще раз" }));
     }
     return(Json(new { success = true }));
 }
        public void CreateLicenseFromApplication(AppDecision decision, AppProtocol protocol)
        {
            var application = _dataService.GetEntity <TrlApplication>(trlApplication => trlApplication.Id == decision.AppId)
                              .FirstOrDefault();
            long id = 0;

            if (application == null)
            {
                Log.Error("[TRL]CreateLicenseFromApplication - Заяву не знайдено");
                return;
            }

            var oldLicense = _dataService
                             .GetEntity <TrlLicense>(x => x.OrgUnitId == application.OrgUnitId && x.LicState == "Active" && x.IsRelevant)
                             .FirstOrDefault();

            try
            {
                if (decision == null)
                {
                    Log.Error("[TRL]CreateLicenseFromApplication - Рішення не знайдено");
                    application.ErrorProcessingLicense = "Рішення не знайдено";
                    throw new Exception();
                }

                decision.IsClosed = true;
                _dataService.SaveChanges();

                if (protocol == null)
                {
                    Log.Error("[TRL]CreateLicenseFromApplication - Протокол не знайдено");
                    application.ErrorProcessingLicense = "Протокол не знайдено";
                    throw new Exception();
                }

                if (application.AppSort == "GetLicenseApplication" || application.AppSort == "IncreaseToTRLApplication")
                {
                    if (oldLicense != null)
                    {
                        Log.Error("[TRL]CreateLicenseFromApplication - У даного СГД вже є активна ліцензія");
                        application.ErrorProcessingLicense = "У даного СГД вже є активна ліцензія";
                        throw new Exception();
                    }
                }
                else
                {
                    if (oldLicense == null)
                    {
                        Log.Error("[TRL]CreateLicenseFromApplication - У даного СГД немає активної ліцензії");
                        application.ErrorProcessingLicense = "У даного СГД немає активної ліцензії";
                        throw new Exception();
                    }
                    oldLicense.IsRelevant = false;
                    id = oldLicense.OldLimsId;
                }
            }
            catch (Exception)
            {
                _dataService.SaveChanges();
                return;
            }

            long limsId = -1;

            if (application.AppSort == "GetLicenseApplication" ||
                application.AppSort == "IncreaseToTRLApplication" ||
                application.AppSort == "CancelLicenseApplication" ||
                application.AppSort == "DecreaseTRLApplication"
                //|| application.AppSort == "ChangeAutPersonApplication"
                || application.AppSort == "AddBranchApplication" ||
                application.AppSort == "RemBranchApplication"
                //|| application.AppSort == "ChangeDrugList"
                //|| application.AppSort == "ReplacementDrugList"
                )

            {
                try
                {
                    limsId = _limsExchangeService.InsertLicenseTRL(decision.AppId).Result;
                }
                catch (Exception e)
                {
                    Log.Error(e.Message);
                    return;
                }
            }
            else
            {
                //lims insert for other sorts of application
                limsId = id;//id of new limsDoc
            }

            var newLicense = new TrlLicense
            {
                OldLimsId   = limsId,
                OrgUnitId   = application.OrgUnitId,
                Id          = Guid.NewGuid(),
                ParentId    = application.Id,
                LicType     = "TRL",
                LicState    = "Active",
                IsRelevant  = true,
                LicenseDate = decision.DateOfStart,
                OrderNumber = protocol.OrderNumber,
                OrderDate   = protocol.OrderDate.Value
            };

            switch (application.AppSort)
            {
            case "RemBranchApplication":
            {
                var appBranches = _dataService.GetEntity <ApplicationBranch>(x => x.LimsDocumentId == application.Id).Select(x => x.BranchId).ToList();
                var branches    = _dataService.GetEntity <Branch>(x => appBranches.Contains(x.Id) && x.LicenseDeleteCheck == true).ToList();
                branches.ForEach(x => x.RecordState    = RecordState.D);
                branches.ForEach(x => x.BranchActivity = "Closed");
                break;
            }

            case "CancelLicenseApplication":
            case "DecreaseTRLApplication":
                newLicense.LicState = "Canceled";
                break;

            case "AddBranchInfoApplication":
            {
                var appBranches = _dataService.GetEntity <ApplicationBranch>(x => x.LimsDocumentId == application.Id)
                                  .Select(x => x.BranchId).ToList();
                var branches = _dataService
                               .GetEntity <Branch>(x => appBranches.Contains(x.Id)).ToList();
                foreach (var branch in branches)
                {
                    List <Dictionary <string, string> > operationListForm;
                    try
                    {
                        operationListForm =
                            JsonConvert.DeserializeObject <List <Dictionary <string, string> > >(
                                branch.OperationListForm);
                    }
                    catch (Exception)
                    {
                        operationListForm = new List <Dictionary <string, string> >();
                    }
                    List <Dictionary <string, string> > operationListFormChanging;
                    try
                    {
                        operationListFormChanging =
                            JsonConvert.DeserializeObject <List <Dictionary <string, string> > >(
                                branch.OperationListFormChanging);
                    }
                    catch (Exception)
                    {
                        operationListFormChanging = new List <Dictionary <string, string> >();
                    }

                    foreach (var itemChanging in operationListFormChanging)
                    {
                        var exists            = false;
                        var itemValueChanging = itemChanging.FirstOrDefault().Value;
                        foreach (var item in operationListForm)
                        {
                            var itemValue = item.FirstOrDefault().Value;
                            if (itemValueChanging == itemValue)
                            {
                                exists = true;
                                break;
                            }
                        }

                        if (exists == false)
                        {
                            operationListForm.Add(itemChanging);
                        }
                    }
                    branch.OperationListForm         = JsonConvert.SerializeObject(operationListForm.OrderBy(x => x.FirstOrDefault().Value));
                    branch.OperationListFormChanging = null;
                }
                break;
            }
            }

            _dataService.Add(newLicense);

            application.AppState           = "Reviewed";
            application.BackOfficeAppState = "Reviewed";

            _dataService.SaveChanges();
        }