电子药箱通讯服务端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PatientInfoBLL.ext.cs 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using RDH.Data.Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace RDH.Data.BLL
  8. {
  9. public partial class PatientInfoBLL : IPatientInfoBLL
  10. {
  11. #region For Join
  12. private const string PATIENT_INFO_TABLE_NAME = "PATIENT_INFO";
  13. private const string PATIENT_INFO_MODEL_NAME = "PatientInfo";
  14. private const string PATIENT_INFO_KEY = "KEY";
  15. private const string PATIENT_INFO_REF_KEY = "SECTION_KEY";
  16. private const bool PATIENT_INFO_IS_SNAPSHOT = false;
  17. protected Dictionary<string, string> SectionColumnPropMaps = new Dictionary<string, string>();
  18. private const string SECTION_TABLE_NAME = "SECTION";
  19. private const string SECTION_MODEL_NAME = "Section";
  20. private const string SECTION_KEY = "KEY";
  21. private const bool SECTION_IS_SNAPSHOT = false;
  22. protected void InitSectionMaps()
  23. {
  24. SectionColumnPropMaps.Clear();
  25. SectionColumnPropMaps.Add("KEY", "Key");
  26. SectionColumnPropMaps.Add("CREATE_BY", "CreateBy");
  27. SectionColumnPropMaps.Add("CREATE_TIME", "CreateTime");
  28. SectionColumnPropMaps.Add("IS_ACTIVE", "IsActive");
  29. SectionColumnPropMaps.Add("IS_DELETE", "IsDelete");
  30. SectionColumnPropMaps.Add("SECTION_ID", "SectionId");
  31. SectionColumnPropMaps.Add("SECTION_NAME", "SectionName");
  32. SectionColumnPropMaps.Add("SECTION_LEADER", "SectionLeader");
  33. SectionColumnPropMaps.Add("SECTION_STATES", "SectionStates");
  34. SectionColumnPropMaps.Add("SECTION_DESCRIPTION", "SectionDescription");//COLUMN_MAPS
  35. }
  36. #endregion
  37. /// <summary>
  38. /// Time:2013-11-06 19:00:56
  39. /// Aouthor:
  40. /// Description:
  41. /// </summary>
  42. /// <returns>
  43. /// return All Item Info
  44. /// </returns>
  45. public IEnumerable<PatientInfo> ListPatientInfo()
  46. {
  47. InitSectionMaps();
  48. var ListPatientInfo = SqlMapper.Query<PatientInfo, Section, PatientInfo>
  49. (ConnectionFactory.Current.GetSessionConnection(), GenerateJoinSql(),
  50. (pt, sect) =>
  51. {
  52. pt.Section = sect;
  53. return pt;
  54. }, splitOn: "split1");
  55. return ListPatientInfo;
  56. }
  57. public IEnumerable<PatientInfo> ListPatientInfoByPage(string strWhere, string orderby, int startIndex, int endIndex)
  58. {
  59. InitSectionMaps();
  60. StringBuilder SectionValues = new StringBuilder();
  61. foreach (var c in SectionColumnPropMaps)
  62. {
  63. SectionValues.AppendFormat("sect.\"{0}\" \"{1}\",", c.Key, c.Value);
  64. }
  65. SectionValues.Remove(SectionValues.Length - 1, 1);
  66. StringBuilder strSql = new StringBuilder();
  67. strSql.Append("SELECT TP.KEY as Key,TP.SNAPSHOT_KEY as SnapshotKey,TP.START_TIME as StartTime,TP.END_TIME as EndTime ,");
  68. strSql.Append("TP.CREATE_BY as CreateBy,TP.CREATE_TIME as CreateTime,TP.PATIENT_ID as PatientId,TP.SOURCE as sOURCE,");
  69. strSql.Append("TP.ENCOUNTER_ID as EncounterId,TP.IN_TIME AS InTime,TP.OUT_TIME as OutTime, TP.SECTION_KEY as SectionKey,TP.NAME as Name,");
  70. strSql.AppendFormat("TP.BIRTHDAY as Birthday,TP.GENDER as Gender,TP.IDENTITY as Identity,TP.MEDICIAL_CARD as MedicialCard,TP.ADDRESS as Address,TP.TELEPHONE as Telephone,'' as split1, {0} FROM ( ", SectionValues);
  71. strSql.Append(" SELECT ROW_NUMBER() OVER (");
  72. if (!string.IsNullOrEmpty(orderby.Trim()))
  73. {
  74. strSql.Append("order by T." + orderby);
  75. }
  76. else
  77. {
  78. strSql.Append("order by T.SNAPSHOT_KEY desc");
  79. }
  80. strSql.Append(")AS num, T.* from PATIENT_INFO T ");
  81. if (!string.IsNullOrEmpty(strWhere.Trim()))
  82. {
  83. strSql.Append(" AND " + strWhere);
  84. }
  85. strSql.Append(" ) TP left join section sect on tp.SECTION_KEY = SECT.KEY ");
  86. strSql.AppendFormat(" WHERE TP.num between {0} and {1}", startIndex, endIndex);
  87. var List = SqlMapper.Query<PatientInfo, Section, PatientInfo>(ConnectionFactory.Current.GetSessionConnection(),
  88. strSql.ToString(), (pi, sect) =>
  89. {
  90. pi.Section = sect;
  91. return pi;
  92. }, splitOn: "split1");
  93. return List;
  94. }
  95. /// <summary>
  96. /// 根据指定的时间范围获取带有未发医嘱的患者
  97. /// </summary>
  98. public List<PatientInfo> ListPatientInfoWithFormulary(DateTime? formularyTimeStart, DateTime? formularyTimeEnd)
  99. {
  100. Object oParam;
  101. StringBuilder sqlSelect = new StringBuilder();
  102. sqlSelect.AppendFormat("SELECT {0} FROM {1} WHERE key IN "
  103. + "(SELECT f.patient_key FROM sate_formulary f WHERE (f.precessed IS NULL OR f.precessed=:isPrecessed)",
  104. BuildGetSql(),
  105. this.TABLE_NAME);
  106. if (formularyTimeStart != null)
  107. {
  108. sqlSelect.Append(" AND f.formulary_date BETWEEN :timeStart AND :timeEnd");
  109. oParam = new
  110. {
  111. isPrecessed = false,
  112. timeStart = formularyTimeStart.Value,
  113. timeEnd = formularyTimeEnd.GetValueOrDefault()
  114. };
  115. }
  116. else
  117. {
  118. oParam = new
  119. {
  120. isPrecessed = false
  121. };
  122. }
  123. sqlSelect.Append(")");
  124. var rlt = SqlMapper.Query<PatientInfo>(ConnectionFactory.Current.GetSessionConnection(),
  125. sqlSelect.ToString());
  126. return rlt == null ? null : rlt.ToList();
  127. }
  128. private string GenerateJoinSql()
  129. {
  130. StringBuilder PatientInfoValues = new StringBuilder();
  131. foreach (var c in ColumnPropMaps)
  132. {
  133. PatientInfoValues.AppendFormat("pt.\"{0}\" \"{1}\",", c.Key, c.Value);
  134. }
  135. PatientInfoValues.Remove(PatientInfoValues.Length - 1, 1);
  136. StringBuilder SectionValues = new StringBuilder();
  137. foreach (var c in SectionColumnPropMaps)
  138. {
  139. SectionValues.AppendFormat("sect.\"{0}\" \"{1}\",", c.Key, c.Value);
  140. }
  141. SectionValues.Remove(SectionValues.Length - 1, 1);
  142. StringBuilder from = new StringBuilder();
  143. from.Append(TABLE_NAME);
  144. from.Append(" PT ");
  145. from.Append(" LEFT JOIN ");
  146. from.Append(SECTION_TABLE_NAME);
  147. from.Append(" sect ");
  148. from.AppendFormat(" ON PT.{0} = sect.{1} ",PATIENT_INFO_REF_KEY, SECTION_KEY);
  149. return string.Format("SELECT {0},'' as split1,{1} FROM {2}", PatientInfoValues, SectionValues, from);
  150. }
  151. public PatientInfo GetByPatientEncounterId(string encounterId)
  152. {
  153. var sql = BuildBaseSql();
  154. return SqlMapper.Query<PatientInfo>(ConnectionFactory.Current.GetSessionConnection(), sql + " WHERE (ENCOUNTER_ID = :EncounterId or PATIENT_ID =:EncounterId )", new { EncounterId = encounterId }).FirstOrDefault();
  155. }
  156. public IEnumerable<PatientInfo> SearchPatients(String filterText)
  157. {
  158. return SqlMapper.Query<PatientInfo>(ConnectionFactory.Current.GetSessionConnection(),
  159. String.IsNullOrEmpty(filterText)
  160. ? BuildBaseSql()
  161. : String.Format("{0} WHERE NAME LIKE '%'||:filterText||'%' OR ENCOUNTER_ID LIKE '%'||:filterText||'%'",
  162. BuildBaseSql()),
  163. new { filterText = filterText });
  164. }
  165. }
  166. }