using System.Collections.Generic;
using System.Linq;
using ASHermed.SinoInterface.Api.ContractModel.App;
using ASHermed.SinoInterface.Api.IRepository.App;
using ASHermed.SinoInterface.Repository.MySql;

namespace ASHermed.SinoInterface.Api.MySqlRepository.App
{
    public class ManyPatRepository : BaseRepositoryToASHermed_SinoInterface<Pub_User_Info>, IManyPatRepository
    {
        public List<Pub_User_Info> GetUsersByPatId(int patId)
        {
            const string sql = @"SELECT
                                 	u.* 
                                 FROM
                                 	pub_map_user_pat AS map
                                 	LEFT JOIN pub_user_info AS u ON map.USER_ID = u.ID 
                                 WHERE
                                 	map.IS_DELETED = FALSE 
                                 	AND u.IS_DELETED = FALSE 
                                 	AND map.PAT_ID = @patId";

            var parms = new Dictionary<string, object>
            {
                { "@patId", patId }
            };

            var result = Query<Pub_User_Info>(sql, parms);
            return result.ToList();
        }

        /// <summary>
        /// 查询用户绑定的患者
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public List<Pub_Pat_Info> GetPatientsByUserId(int userId)
        {
            const string sql = @"SELECT
                                 	pat.* 
                                 FROM
                                 	pub_map_user_pat AS map
                                 	LEFT JOIN pub_pat_info AS pat ON map.USER_ID = pat.ID 
                                 WHERE
                                 	map.IS_DELETED = FALSE 
                                 	AND pat.IS_DELETED = FALSE 
                                 	AND map.USER_ID = @userId";

            var parms = new Dictionary<string, object>
            {
                { "@userId", userId }
            };

            var result = Query<Pub_Pat_Info>(sql, parms);
            return result.ToList();
        }
    }
}