Ejemplo n.º 1
0
 public void SetCampaignForTest(AsCampaign campaign)
 {
     if (m_CampaignInRamOnly != campaign)
     {
         m_CampaignInRamOnly = campaign; OnPropertyChanged("CampaignInRamOnly");
     }
 }
Ejemplo n.º 2
0
        private static bool NewDiseaseValidation(AsCampaign campaign, AsDisease item)
        {
            //check duplicates
            if (campaign.Diseases.Count(x => x.idfCampaignToDiagnosis != item.idfCampaignToDiagnosis && x.idfsDiagnosis == item.idfsDiagnosis && x.idfsSpeciesType == item.idfsSpeciesType && x.idfsSampleType == item.idfsSampleType && !x.IsMarkedToDelete) > 0)
            {
                throw new ValidationModelException("AsSession.Diseases.Duplicate_msgId", "idfsSpeciesType", "idfsSpeciesType", null, typeof(PredicateValidator), ValidationEventType.Error, item);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static bool ValidateCampaignToSessionDiseasesRules(AsSession session, AsCampaign campaign)
        {
            var campaignDiseasesCount = campaign.Diseases.Where(d => !d.IsMarkedToDelete).Count();

            if (campaignDiseasesCount == 0 && session.Diseases.Count(x => !x.IsMarkedToDelete) > 0)
            {
                return(false);
            }

            if (session.Diseases.Count(x => !x.IsMarkedToDelete) > 0)
            {
                //if session contains diagnosis which are not in the campaign, error
                if (session.Diseases.Where(x => !x.IsMarkedToDelete).Count(c => campaign.Diseases.Count(d => d.idfsDiagnosis == c.idfsDiagnosis) == 0) > 0)
                {
                    return(false);
                }


                //if diseases+species have at least one difference, error

                var commonDiseasesWithSpecies = session.Diseases.Where(x => !x.IsMarkedToDelete)
                                                .Join(campaign.Diseases,
                                                      x => new { x.idfsDiagnosis, x.idfsSpeciesType },
                                                      y => new { y.idfsDiagnosis, y.idfsSpeciesType },
                                                      (x, y) => x.idfsDiagnosis).Count();

                if (commonDiseasesWithSpecies < session.Diseases.Count(x => !x.IsMarkedToDelete))
                {
                    //if (commonDiseasesWithSpecies == campaign.Diseases.Count(d => d.idfsSpeciesType.HasValue && !d.IsMarkedToDelete) &&
                    //    commonDiseasesWithSpecies < campaignDiseasesCount)
                    //{

                    //if Campaign contains diseases without species, all ok
                    // this rule is wrong - see bug #13095

                    /*var commonDiseaseNoSpecies = session.Diseases.Where(x => !x.IsMarkedToDelete && x.idfsSpeciesType.HasValue)
                     *  .Join(campaign.Diseases.Where(d=>!d.IsMarkedToDelete && !d.idfsSpeciesType.HasValue),
                     *      s => s.idfsDiagnosis,
                     *      c => c.idfsDiagnosis,
                     *      (s,c) => s.idfsDiagnosis)
                     *  .Count();
                     *
                     * if (commonDiseaseNoSpecies != session.Diseases.Count(d => !d.IsMarkedToDelete) - commonDiseasesWithSpecies)
                     * {*/
                    return(false);
                    /*}*/
                    //}
                    //else
                    //{
                    //    return false;
                    //}
                }
            }
            return(true);
        }
Ejemplo n.º 4
0
 public static bool ValidateCheckToDeleteDiagnosis(AsSession session, AsCampaign campaign)
 {
     foreach (AsSessionDisease d in session.Diseases.Where(x => !x.IsMarkedToDelete &&
                                                           !campaign.Diseases.Any(y => !y.IsMarkedToDelete && y.idfsDiagnosis == x.idfsDiagnosis && y.idfsSpeciesType == x.idfsSpeciesType) &&
                                                           !campaign.Diseases.Any(y => !y.IsMarkedToDelete && y.idfsDiagnosis == x.idfsDiagnosis && !y.idfsSpeciesType.HasValue)
                                                           ))
     {
         if (!d.ValidateOnDelete())
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 5
0
        public static bool AssignCampaignToSession(AsCampaign campaign, long idfMonitoringSession)
        {
            using (DbManagerProxy manager = DbManagerFactory.Factory.Create(eidss.model.Core.EidssUserContext.Instance))
            {
                AsSession session = AsSession.Accessor.Instance(null).SelectByKey(manager, idfMonitoringSession);
                if (session != null && campaign.Sessions.Count(s => s.idfMonitoringSession == session.idfMonitoringSession && !s.IsMarkedToDelete) == 0)
                {
                    if (campaign.ValidateSessionAssignment(session))
                    {
                        //session.CampaignInRamOnly = campaign;
                        session.SetCampaignForTest(campaign);
                        session.idfCampaign = campaign.idfCampaign;
                        var temp = session.CampaignInRamOnly;

                        campaign.Sessions.Add(AsMonitoringSession.CreateFromASSession(manager, campaign, session));
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 6
0
        public static bool AssignCampaignToSession(AsCampaign campaign, AsSession session)
        {
            if (session == null)
            {
                return(false);
            }

            using (DbManagerProxy manager = DbManagerFactory.Factory.Create(eidss.model.Core.EidssUserContext.Instance))
            {
                if (campaign.ValidateSessionAssignment(session))
                {
                    //session.CampaignInRamOnly = campaign;
                    session.SetCampaignForTest(campaign);
                    session.idfCampaign = campaign.idfCampaign;
                    var temp = session.CampaignInRamOnly;

                    campaign.Sessions.Add(AsMonitoringSession.CreateFromASSession(manager, campaign, session));
                }
            }

            return(true);
        }
Ejemplo n.º 7
0
        public static bool ValidateCheckAnimalSampleList(AsSession session, AsCampaign campaign)
        {
            foreach (var item in session.ASAnimalsSamples.Where(x => !x.IsMarkedToDelete))
            {
                if (item.idfsSampleType.HasValue)
                {
                    if (!campaign.Diseases.Any(x => !x.IsMarkedToDelete && (x.idfsSpeciesType == item.idfsSpeciesType || !x.idfsSpeciesType.HasValue) && (x.idfsSampleType == item.idfsSampleType || !x.idfsSampleType.HasValue)))
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!campaign.Diseases.Any(x => !x.IsMarkedToDelete && (x.idfsSpeciesType == item.idfsSpeciesType || !x.idfsSpeciesType.HasValue)))
                    {
                        return(false);
                    }
                }
            }

            foreach (var item in session.SummaryItems.Where(x => !x.IsMarkedToDelete))
            {
                foreach (var s in item.Samples.Where(x => !x.IsMarkedToDelete && x.blnChecked.HasValue && x.blnChecked.Value))
                {
                    if (!campaign.Diseases.Any(x => !x.IsMarkedToDelete && (x.idfsSpeciesType == item.idfsSpeciesType || !x.idfsSpeciesType.HasValue) && (x.idfsSampleType == s.idfsSampleType || !x.idfsSampleType.HasValue)))
                    {
                        return(false);
                    }

                    if (!campaign.Diseases.Any(x => !x.IsMarkedToDelete && (x.idfsSpeciesType == item.idfsSpeciesType || !x.idfsSpeciesType.HasValue)))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 8
0
        public static void CopyDiseasesFromCampaignToSession(DbManagerProxy manager, AsSession session, AsCampaign campaign)
        {
            foreach (var sessionDisease in session.Diseases.Where(d => !d.IsMarkedToDelete))
            {
                sessionDisease.DeleteNoValidate(false);
            }

            if (campaign.Diseases.Count(x => !x.IsMarkedToDelete) > 0 && session.Diseases.Count(x => !x.IsMarkedToDelete) == 0)
            {
                AsSessionDisease item = null;

                foreach (var campaignDisease in campaign.Diseases.Where(d => !d.IsMarkedToDelete))
                {
                    item = (AsSessionDisease)AsSessionDisease.Accessor.Instance(null).CreateNew(manager, session);
                    item.idfMonitoringSession = session.idfMonitoringSession;
                    //item.idfsDiagnosis = campaignDisease.idfsDiagnosis;
                    //item.idfsSpeciesType = campaignDisease.idfsSpeciesType;
                    item.Diagnosis   = item.DiagnosisLookup.FirstOrDefault(c => c.idfsDiagnosis == campaignDisease.idfsDiagnosis);
                    item.SpeciesType = item.SpeciesTypeLookup.FirstOrDefault(c => c.idfsBaseReference == campaignDisease.idfsSpeciesType);
                    item.SampleType  = item.SampleTypeLookup.FirstOrDefault(c => c.idfsReference == campaignDisease.idfsSampleType);
                    session.Diseases.Add(item);
                }
            }
        }
Ejemplo n.º 9
0
        public static AsMonitoringSession CreateFromASSession(DbManagerProxy manager, AsCampaign campaign, AsSession original)
        {
            AsMonitoringSession mssession = AsMonitoringSession.Accessor.Instance(null).CreateNewT(manager, campaign);


            string[] populateSession = new string[] {
                "idfMonitoringSession",
                "idfCampaign",
                "datStartDate",
                "datEndDate",
                "strMonitoringSessionID",
            };

            foreach (var prop in populateSession)
            {
                if (original.GetValue(prop) != null)
                {
                    mssession.SetValue(prop, original.GetValue(prop).ToString());
                }
            }

            mssession.strRegion     = original.Region == null ? String.Empty : original.Region.ToString();
            mssession.strRayon      = original.Rayon == null ? String.Empty : original.Rayon.ToString();
            mssession.strSettlement = original.Settlement == null ? String.Empty : original.Settlement.ToString();
            mssession.strStatus     = original.MonitoringSessionStatus.ToString();
            //mssession.FullSession = original;

            return(mssession);
        }
Ejemplo n.º 10
0
        public static void RemoveSessionFromCampaign(AsCampaign campaign, long idfMonitoringSession)
        {
            AsMonitoringSession mssession = campaign.Sessions.Single(s => s.idfMonitoringSession == idfMonitoringSession);

            mssession.idfCampaign = null;
        }