Ejemplo n.º 1
0
 public void Add(CohortEnumLink link)
 {
     using (var dbContext = new MedialynxDbCohortEnumLinkContext()) {
         dbContext.CohortEnumLink.Add(link);
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        public bool Remove(string cohortId)
        {
            Guid id = Utils.ToGuid(cohortId);

            using (var dbContext = new MedialynxDbCohortContext()) {
                if (id != Guid.Empty)
                {
                    string sid    = id.ToString("B");
                    Cohort cohort = dbContext.Cohorts.FirstOrDefault(c => c != null && c.Id == sid);
                    if (cohort != null)
                    {
                        dbContext.Cohorts.Remove(cohort);
                        dbContext.SaveChanges();

                        using (var dbContextLinks = new MedialynxDbCohortEnumLinkContext()) {
                            List <CohortEnumLink> links = dbContextLinks.CohortEnumLink.Where(link => link != null && link.CohortId == sid).ToList();
                            dbContextLinks.RemoveRange(links);
                            dbContextLinks.SaveChanges();
                        }
                    }
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 3
0
 public void RemoveRange(List <string> linkIds)
 {
     using (var dbContext = new MedialynxDbCohortEnumLinkContext()) {
         List <CohortEnumLink> linksToRemove = new List <CohortEnumLink>();
         foreach (string id in linkIds)
         {
             linksToRemove.Add(dbContext.CohortEnumLink.FirstOrDefault(link => link != null && link.Id == id));
         }
         dbContext.CohortEnumLink.RemoveRange(linksToRemove);
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 4
0
        public void Remove(string linkId)
        {
            List <CohortEnumLink> links = this.Get(linkId);

            if (links.Count > 0)
            {
                using (var dbContext = new MedialynxDbCohortEnumLinkContext()) {
                    dbContext.CohortEnumLink.Remove(links[0]);
                    dbContext.SaveChanges();
                }
            }
        }
Ejemplo n.º 5
0
 public void Update(CohortEnumLink link)
 {
     using (var dbContext = new MedialynxDbCohortEnumLinkContext()) {
         CohortEnumLink existsLink = dbContext.CohortEnumLink.FirstOrDefault(l => l != null && l.Id == link.Id);
         if (existsLink != null)
         {
             if (Utils.CopyPropertyValues <CohortEnumLink>(link, existsLink))
             {
                 dbContext.CohortEnumLink.Update(existsLink);
                 dbContext.SaveChanges();
             }
         }
     }
 }
Ejemplo n.º 6
0
        public List <CohortEnumLink> Get(string linkId = "{00000000-0000-0000-0000-000000000000}")
        {
            Guid id = Utils.ToGuid(linkId);
            List <CohortEnumLink> links = new List <CohortEnumLink>();

            using (var dbContext = new MedialynxDbCohortEnumLinkContext()) {
                if (id != Guid.Empty)
                {
                    string         sid  = id.ToString("B");
                    CohortEnumLink link = dbContext.CohortEnumLink.FirstOrDefault(link => link != null && link.Id == sid);
                    links.Add(link);
                }
                else
                {
                    // Add all links
                    links.AddRange(dbContext.CohortEnumLink);
                }
            }
            return(links);
        }
Ejemplo n.º 7
0
        public List <CohortEnumLinkRepresentation> GetLinksByCohort(string cohortId = "{00000000-0000-0000-0000-000000000000}")
        {
            Guid id = Utils.ToGuid(cohortId);

            using (var dbContext = new MedialynxDbCohortEnumLinkContext()) {
                if (id != Guid.Empty)
                {
                    string sid = id.ToString("B");
                    List <CohortEnumLink> links = dbContext.CohortEnumLink.Where(link => link != null && link.CohortId == sid).ToList();
                    List <CohortEnumLinkRepresentation> representation = new List <CohortEnumLinkRepresentation>();
                    foreach (CohortEnumLink enumLink in links)
                    {
                        CohortEnumLinkRepresentation p = new CohortEnumLinkRepresentation(enumLink);
                        p.EnumItem = this.GetEnumValue(enumLink.CohortEnumId, enumLink.EnumItemId);
                        representation.Add(p);
                    }
                    return(representation);
                }
            }
            return(null);
        }
Ejemplo n.º 8
0
        public void UpdateLinks(string cohortId, List <CohortEnumLinkAPI> LinksForUpdate)
        {
            if (LinksForUpdate == null)
            {
                return; // nothing to update
            }

            // collect id's for update
            List <string> updatesIds = new List <string>();

            foreach (CohortEnumLinkAPI linkAPI in LinksForUpdate)
            {
                Guid id = Utils.ToGuid(linkAPI.Id, false);
                if (id != Guid.Empty)   // empty = create
                {
                    updatesIds.Add(linkAPI.Id);
                }
            }

            // exists guids
            List <string> existsIds = new List <string>();

            using (var dbContext = new MedialynxDbCohortEnumLinkContext()) {
                List <CohortEnumLink> existsLinks = dbContext.CohortEnumLink.Where(link => link.CohortId == cohortId).ToList();
                foreach (CohortEnumLink link in existsLinks)
                {
                    existsIds.Add(link.Id);
                }
            }

            // check that exists id present in new links collection.
            List <string> toDeleteIds = new List <string>();

            foreach (string item in existsIds)
            {
                if (!updatesIds.Contains(item))
                {
                    toDeleteIds.Add(item);
                }
            }
            // remove not exists limks
            this.RemoveRange(toDeleteIds);

            foreach (CohortEnumLinkAPI linkAPI in LinksForUpdate)
            {
                // enum item defined within link item. Must be created and used instead linkAPI.EnumItemId
                if (linkAPI.enumItem != null)
                {
                    this.CreateEnumItem(linkAPI);
                }

                List <CohortEnumLink> existLinks = this.Get(linkAPI.Id);
                CohortEnumLink        existLink  = existLinks.Count > 0 ? existLinks[0] : null;
                if (existLink == null)
                {
                    this.CreateNewLink(cohortId, linkAPI);
                }
                else   // update exists link required
                {
                    CohortEnumLink link = new CohortEnumLink();
                    link.Id           = Guid.NewGuid().ToString("B");
                    link.CohortId     = cohortId;
                    link.CohortEnumId = linkAPI.CohortEnumId;
                    link.EnumItemId   = linkAPI.EnumItemId;
                    link.Include      = linkAPI.Include;
                    link.Percentage   = linkAPI.Percentage;
                    link.LastUpdate   = link.CreationDate;
                    this.Update(link);
                }
            }
        }
Ejemplo n.º 9
0
        public void Generate(string cohortId)
        {
            List <CohortEnumLink> links = new List <CohortEnumLink>();

            using (var dbCohortContext = new MedialynxDbCohortEnumsContext()) {
                foreach (CohortEnums enumItem in dbCohortContext.CohortEnums)
                {
                    switch (enumItem.Id)
                    {
                    case CohortEnumsDictionary.DiseaseStates:
                        using (var dbDiseaseStatesContext = new MedialynxDbDiseaseStatesContext()) {
                            links.AddRange(ExistingOptionsAsLink <DiseaseStates>(new List <DiseaseStates>(dbDiseaseStatesContext.DiseaseStates), cohortId, enumItem.Id));
                        }
                        break;

                    case CohortEnumsDictionary.GeneticMatches:
                        using (var dbGeneticMatchesContext = new MedialynxDbGeneticMatchesContext()) {
                            links.AddRange(ExistingOptionsAsLink <GeneticMatches>(new List <GeneticMatches>(dbGeneticMatchesContext.GeneticMatches), cohortId, enumItem.Id));
                        }
                        break;

                    case CohortEnumsDictionary.Biomarkers:
                        using (var dbBiomarkersContext = new MedialynxDbBiomarkersContext()) {
                            links.AddRange(ExistingOptionsAsLink <Biomarkers>(new List <Biomarkers>(dbBiomarkersContext.Biomarkers), cohortId, enumItem.Id));
                        }
                        break;

                    case CohortEnumsDictionary.Demographics:
                        using (var dbDemographicsContext = new MedialynxDbDemographicsContext()) {
                            links.AddRange(ExistingOptionsAsLink <Demographics>(new List <Demographics>(dbDemographicsContext.Demographics), cohortId, enumItem.Id));
                        }
                        break;

                    case CohortEnumsDictionary.Ethnicitys:
                        using (var dbEthnicitysContext = new MedialynxDbEthnicitysContext()) {
                            links.AddRange(ExistingOptionsAsLink <Ethnicitys>(new List <Ethnicitys>(dbEthnicitysContext.Ethnicitys), cohortId, enumItem.Id));
                        }
                        break;

                    case CohortEnumsDictionary.StageOfDiseases:
                        using (var dbStageOfDiseasesContext = new MedialynxDbStageOfDiseasesContext()) {
                            links.AddRange(ExistingOptionsAsLink <StageOfDiseases>(new List <StageOfDiseases>(dbStageOfDiseasesContext.StageOfDiseases), cohortId, enumItem.Id));
                        }
                        break;

                    case CohortEnumsDictionary.Prognosis:
                        using (var dbPrognosisContext = new MedialynxDbPrognosisContext()) {
                            links.AddRange(ExistingOptionsAsLink <Prognosis>(new List <Prognosis>(dbPrognosisContext.Prognosis), cohortId, enumItem.Id));
                        }
                        break;

                    case CohortEnumsDictionary.PreviousTreatments:
                        using (var dbPreviousTreatmentsContext = new MedialynxDbPreviousTreatmentsContext()) {
                            links.AddRange(ExistingOptionsAsLink <PreviousTreatments>(new List <PreviousTreatments>(dbPreviousTreatmentsContext.PreviousTreatments), cohortId, enumItem.Id));
                        }
                        break;
                    }
                }

                using (var dbContext = new MedialynxDbCohortEnumLinkContext()) {
                    dbContext.CohortEnumLink.AddRange(links);
                    dbContext.SaveChanges();
                }
            }
        }