public RIResponse Get(string token, string remedy)
        {
            RIResponse result = new RIResponse();

            try
            {
                using (ISession session = ApplicationCore.Instance.SessionFactory.OpenSession())
                {
                    if (LoginManager.Check(session, token))
                    {
                        using (session.BeginTransaction())
                        {
                            result.values = session.QueryOver <RemedyGenericInfo>().Where(ri => ri.RAbbrev == remedy).Select(ri => ri.RTextInfo).List <string>().ToArray <string>();
                            session.Transaction.Rollback();
                        }
                    }
                    else
                    {
                        LoginManager.NoValidToken(token);
                    }
                }
            }
            catch (Exception ex)
            {
                result.error = new SerializedError(ex);
            }
            return(result);
        }
Esempio n. 2
0
        public QResponse Back(string token)
        {
            QResponse result = new QResponse();

            try
            {
                using (ISession session = ApplicationCore.Instance.SessionFactory.OpenSession())
                {
                    if (LoginManager.Check(session, token))
                    {
                        using (session.BeginTransaction())
                        {
                            int       last      = session.QueryOver <Session>().Select(Projections.ProjectionList().Add(Projections.Max <Session>(x => x.SProgr))).List <int>().First();
                            Session[] toDeletes = session.QueryOver <Session>().Where(s => s.SProgr == last).List <Session>().ToArray();
                            foreach (Session toDelete in toDeletes)
                            {
                                session.Delete(toDelete);
                            }
                            session.Transaction.Commit();
                        }
                    }
                    else
                    {
                        LoginManager.NoValidToken(token);
                    }
                }
            }
            catch (Exception ex)
            {
                result.error = new SerializedError(ex);
            }
            return(result);
        }
Esempio n. 3
0
        //GET /api/pathologies?token=<string>&lang=<int>
        public PResponse getPathologies(string token, int lang)
        {
            PResponse result = new PResponse();

            try
            {
                using (ISession session = ApplicationCore.Instance.SessionFactory.OpenSession())
                {
                    if (LoginManager.Check(session, token))
                    {
                        using (session.BeginTransaction())
                        {
                            ICriteria         criteria = session.CreateCriteria <Pathology>();
                            IList <Pathology> pats     = criteria.List <Pathology>();
                            result.values = getPathologies(session, pats, lang);
                            session.Transaction.Rollback();
                        }
                    }
                    else
                    {
                        LoginManager.NoValidToken(token);
                    }
                }
            }
            catch (Exception ex)
            {
                result.error = new SerializedError(ex);
            }
            return(result);
        }
Esempio n. 4
0
        //GET /api/analysis?token=<string>
        public AResponse Get(string token)
        {
            AResponse result = new AResponse();

            try
            {
                using (ISession session = ApplicationCore.Instance.SessionFactory.OpenSession())
                {
                    if (LoginManager.Check(session, token))
                    {
                        using (session.BeginTransaction())
                        {
                            int[] idRisposte = session.QueryOver <Session>().Where(s => s.SToken == token).List().Select(s => s.SAnswerId).ToArray();
                            int[] idSintomi  = session.QueryOver <Answer>().List().Where(a => idRisposte.Contains(a.AId)).Select(a => a.SymptomId).ToArray();
                            result.idSintomi = idSintomi;
                            var rimedi = session.QueryOver <HomAddition>().AndRestrictionOn(h => h.RaRubricid).IsIn(idSintomi).List().ToArray();
                            result.value = rimedi.GroupBy(r => r.Remedy.RAbbrev).Select(g => new Analysis()
                            {
                                rimedio = g.Key, punteggio = g.Count() + g.Sum(h => h.RaDegree)
                            }).OrderByDescending(r => r.punteggio).ToArray();
                            session.Transaction.Commit();
                        }
                    }
                    else
                    {
                        LoginManager.NoValidToken(token);
                    }
                }
            }
            catch (Exception ex)
            {
                result.error = new SerializedError(ex);
            }
            return(result);
        }
Esempio n. 5
0
        public PResponse Filtered(string token, int lang, string filter)
        {
            PResponse result = new PResponse();

            try
            {
                using (ISession session = ApplicationCore.Instance.SessionFactory.OpenSession())
                {
                    if (LoginManager.Check(session, token))
                    {
                        using (session.BeginTransaction())
                        {
                            string[] filters = filter.Split(' ');
                            var      query   = session.QueryOver <Translation>();
                            foreach (string filt in filters)
                            {
                                if (lang == 1)
                                {
                                    query = query.AndRestrictionOn(t => t.Original).IsInsensitiveLike(filt, MatchMode.Anywhere);
                                }
                                else
                                {
                                    query = query.AndRestrictionOn(t => t.Translationval).IsInsensitiveLike(filt, MatchMode.Anywhere);
                                }
                            }
                            var               resu  = query.List();
                            string[]          trans = query.Select(t => t.Original).List <string>().ToArray();
                            IList <Pathology> pats  = session.QueryOver <Pathology>().AndRestrictionOn(p => p.PScientificName).IsIn(trans).List();
                            result.values = getPathologies(session, pats, lang);
                            session.Transaction.Rollback();
                        }
                    }
                    else
                    {
                        LoginManager.NoValidToken(token);
                    }
                }
            }
            catch (Exception ex)
            {
                result.error = new SerializedError(ex);
            }
            return(result);
        }
Esempio n. 6
0
        public RLResponce Localized(string token, int lang, int local)
        {
            RLResponce result = new RLResponce();

            try
            {
                using (ISession session = ApplicationCore.Instance.SessionFactory.OpenSession())
                {
                    if (LoginManager.Check(session, token))
                    {
                        using (session.BeginTransaction())
                        {
                            LocalizedPatology         model = null;
                            IList <LocalizedPatology> pats  = session.QueryOver <Pathology>().Right.JoinQueryOver <Localisation>(p => p.Localisations).Where(l => l.LId == local).SelectList(list => list
                                                                                                                                                                                             .Select(p => p.PCommonName).WithAlias(() => model.PCommonName)
                                                                                                                                                                                             .Select(p => p.PId).WithAlias(() => model.PId)
                                                                                                                                                                                             .Select(p => p.PKeySymptoms).WithAlias(() => model.PKeySymptoms)
                                                                                                                                                                                             .Select(p => p.PIcd10Code).WithAlias(() => model.PIcd10Code)
                                                                                                                                                                                             .Select(p => p.QIdFirstQuestion).WithAlias(() => model.QIdFirstQuestion)
                                                                                                                                                                                             .Select(p => p.PWarning).WithAlias(() => model.PWarning)
                                                                                                                                                                                             .Select(p => p.PScientificName).WithAlias(() => model.PScientificName)
                                                                                                                                                                                             ).TransformUsing(Transformers.AliasToBean <LocalizedPatology>()).Future <LocalizedPatology>().ToList();
                            for (int i = 0; i < pats.Count; i++)
                            {
                                pats[i] = TranslateManager.Translate <LocalizedPatology>(session, lang, pats[i]);
                            }
                            result.values = pats.ToArray <LocalizedPatology>();
                            session.Transaction.Rollback();
                        }
                    }
                    else
                    {
                        LoginManager.NoValidToken(token);
                    }
                }
            }
            catch (Exception ex)
            {
                result.error = new SerializedError(ex);
            }
            return(result);
        }
Esempio n. 7
0
        public QResponse First(string token, int p_id, int lang)
        {
            QResponse result = new QResponse();

            try
            {
                using (ISession session = ApplicationCore.Instance.SessionFactory.OpenSession())
                {
                    if (LoginManager.Check(session, token))
                    {
                        using (session.BeginTransaction())
                        {
                            ICriteria criteria = session.CreateCriteria <Pathology>();
                            Pathology pat      = session.Get <Pathology>(p_id);
                            //session.Update(pat);
                            result.value = session.Get <Question>(pat.QIdFirstQuestion);
                            result.value = TranslateManager.Translate <Question>(session, lang, result.value);
                            for (int i = 0; i < result.value.Answers.Count; i++)
                            {
                                result.value.Answers[i] = TranslateManager.Translate <Answer>(session, lang, result.value.Answers[i]);
                            }
                            session.Transaction.Commit();
                        }
                    }
                    else
                    {
                        LoginManager.NoValidToken(token);
                    }
                }
            }
            catch (Exception ex)
            {
                result.error = new SerializedError(ex);
            }
            return(result);
        }
Esempio n. 8
0
        public QResponse Next(string token, int q_id, [FromUri] int[] a_id, int lang)
        {
            QResponse result = new QResponse();

            try
            {
                using (ISession session = ApplicationCore.Instance.SessionFactory.OpenSession())
                {
                    if (LoginManager.Check(session, token))
                    {
                        using (session.BeginTransaction())
                        {
                            //carico la risposta
                            Answer[] answers = session.QueryOver <Answer>().AndRestrictionOn(a => a.AId).IsIn(a_id).List().ToArray();
                            if (answers != null && answers.Length > 0)
                            {
                                int max      = session.QueryOver <Session>().Select(Projections.ProjectionList().Add(Projections.Max <Session>(x => x.SId))).List <int>().First() + 1;
                                int newprogr = session.QueryOver <Session>().Where(s => s.SId == max - 1).Select(s => s.SProgr).List <int>().FirstOrDefault() + 1;
                                //int max = LastSession.SId + 1;
                                //int newprogr = LastSession.SProgr + 1;
                                foreach (Answer answer in answers)
                                {
                                    //Salvo la risposta nella sessione
                                    Session newSessionItem = new Session()
                                    {
                                        SToken    = token,
                                        SAnswerId = answer.AId,
                                        SId       = max++,
                                        SProgr    = newprogr
                                    };
                                    session.Save(newSessionItem);
                                }
                            }
                            else
                            {
                                //Se l'utente non ha dato risposte recupero tutte le risposte legate alla vecchia domanda per calcolare
                                answers = session.QueryOver <Answer>().Where(a => a.QuestionId == q_id).List().ToArray();
                            }
                            //Recupero la prossima domanda da restituire
                            result.value = session.Get <Question>(answers[0].NextQuestionId);
                            result.value = TranslateManager.Translate <Question>(session, lang, result.value);
                            for (int i = 0; i < result.value.Answers.Count; i++)
                            {
                                result.value.Answers[i] = TranslateManager.Translate <Answer>(session, lang, result.value.Answers[i]);
                            }

                            session.Transaction.Commit();
                        }
                    }
                    else
                    {
                        LoginManager.NoValidToken(token);
                    }
                }
            }
            catch (Exception ex)
            {
                result.error = new SerializedError(ex);
            }
            return(result);
        }