data.go 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. package service
  2. import (
  3. "XT_New/models"
  4. _ "github.com/astaxie/beego"
  5. _ "strconv"
  6. _ "strings"
  7. "time"
  8. )
  9. // GetPatientList 返回患者的列表
  10. func GetConfigList(orgID int64) (dataconfig interface{}, err error) {
  11. var configList []*models.Dataconfig
  12. err = readDb.Model(&models.Dataconfig{}).Where("(org_id in (0,?) and status = 1) or (status = 0 and delete_id_system > 0 and org_id = ?)", orgID, orgID).Order("orders asc, id asc").Find(&configList).Error
  13. if err != nil {
  14. return nil, err
  15. }
  16. // configResult := make([]*ConfigViewModel,0)
  17. childConfig := make(map[int64][]*models.Dataconfig)
  18. resultConfig := make(map[string][]*models.ConfigViewModel)
  19. deleteSystemChilds := make([]*models.Dataconfig, 0)
  20. editSystemChilds := make([]*models.Dataconfig, 0)
  21. for _, config := range configList {
  22. if config.Status == 1 && config.DeleteIdSystem > 0 {
  23. editSystemChilds = append(editSystemChilds, config)
  24. }
  25. if config.Status == 0 && config.DeleteIdSystem > 0 {
  26. deleteSystemChilds = append(deleteSystemChilds, config)
  27. }
  28. }
  29. continueFlag := false
  30. for _, config := range configList {
  31. continueFlag = false
  32. if config.ParentId == 0 {
  33. newConfig := &models.ConfigViewModel{
  34. ID: config.ID,
  35. ParentId: config.ParentId,
  36. Module: config.Module,
  37. OrgId: config.OrgId,
  38. Name: config.Name,
  39. FieldName: config.FieldName,
  40. Value: config.Value,
  41. CreateUserId: config.CreateUserId,
  42. Status: config.Status,
  43. Remark: config.Remark,
  44. Title: config.Title,
  45. Content: config.Content,
  46. }
  47. // configResult = append(configResult,newConfig)
  48. result := resultConfig[config.Module]
  49. if result == nil {
  50. result = make([]*models.ConfigViewModel, 0)
  51. }
  52. for _, vm := range editSystemChilds {
  53. if vm.DeleteIdSystem == config.ID {
  54. continueFlag = true
  55. break
  56. }
  57. }
  58. for _, _vm := range deleteSystemChilds {
  59. if _vm.DeleteIdSystem == config.ID {
  60. continueFlag = true
  61. break
  62. }
  63. }
  64. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  65. continue
  66. }
  67. if continueFlag {
  68. continue
  69. }
  70. result = append(result, newConfig)
  71. resultConfig[config.Module] = result
  72. } else {
  73. childs := childConfig[config.ParentId]
  74. if childs == nil {
  75. childs = make([]*models.Dataconfig, 0)
  76. }
  77. continueFlag := false
  78. for _, vm := range editSystemChilds {
  79. if vm.DeleteIdSystem == config.ID {
  80. continueFlag = true
  81. break
  82. }
  83. }
  84. for _, _vm := range deleteSystemChilds {
  85. if _vm.DeleteIdSystem == config.ID {
  86. continueFlag = true
  87. break
  88. }
  89. }
  90. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  91. continue
  92. }
  93. if continueFlag {
  94. continue
  95. }
  96. childs = append(childs, config)
  97. childConfig[config.ParentId] = childs
  98. }
  99. }
  100. for _, vm := range resultConfig {
  101. for _, _vm := range vm {
  102. _vm.Childs = childConfig[_vm.ID]
  103. }
  104. // vm.Childs = childConfig[vm.ID]
  105. }
  106. return resultConfig, err
  107. }
  108. func GetDictConfigList(orgID int64) (dataconfig interface{}, err error) {
  109. var configList []*models.DictionaryDataconfig
  110. err = readDb.Model(&models.DictionaryDataconfig{}).Where("(org_id in (0,?) and status = 1) or (status = 0 and delete_id_system > 0 and org_id = ?)", orgID, orgID).Order("orders asc, id asc").Find(&configList).Error
  111. if err != nil {
  112. return nil, err
  113. }
  114. // configResult := make([]*ConfigViewModel,0)
  115. childConfig := make(map[int64][]*models.DictionaryDataconfig)
  116. resultConfig := make(map[string][]*models.DictionaryConfigViewModel)
  117. deleteSystemChilds := make([]*models.DictionaryDataconfig, 0)
  118. editSystemChilds := make([]*models.DictionaryDataconfig, 0)
  119. for _, config := range configList {
  120. if config.Status == 1 && config.DeleteIdSystem > 0 {
  121. editSystemChilds = append(editSystemChilds, config)
  122. }
  123. if config.Status == 0 && config.DeleteIdSystem > 0 {
  124. deleteSystemChilds = append(deleteSystemChilds, config)
  125. }
  126. }
  127. continueFlag := false
  128. for _, config := range configList {
  129. continueFlag = false
  130. if config.ParentId == 0 {
  131. newConfig := &models.DictionaryConfigViewModel{
  132. ID: config.ID,
  133. ParentId: config.ParentId,
  134. Module: config.Module,
  135. OrgId: config.OrgId,
  136. Name: config.Name,
  137. FieldName: config.FieldName,
  138. Value: config.Value,
  139. CreateUserId: config.CreateUserId,
  140. Status: config.Status,
  141. Remark: config.Remark,
  142. Title: config.Title,
  143. Content: config.Content,
  144. }
  145. // configResult = append(configResult,newConfig)
  146. result := resultConfig[config.Module]
  147. if result == nil {
  148. result = make([]*models.DictionaryConfigViewModel, 0)
  149. }
  150. for _, vm := range editSystemChilds {
  151. if vm.DeleteIdSystem == config.ID {
  152. continueFlag = true
  153. break
  154. }
  155. }
  156. for _, _vm := range deleteSystemChilds {
  157. if _vm.DeleteIdSystem == config.ID {
  158. continueFlag = true
  159. break
  160. }
  161. }
  162. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  163. continue
  164. }
  165. if continueFlag {
  166. continue
  167. }
  168. result = append(result, newConfig)
  169. resultConfig[config.Module] = result
  170. } else {
  171. childs := childConfig[config.ParentId]
  172. if childs == nil {
  173. childs = make([]*models.DictionaryDataconfig, 0)
  174. }
  175. continueFlag := false
  176. for _, vm := range editSystemChilds {
  177. if vm.DeleteIdSystem == config.ID {
  178. continueFlag = true
  179. break
  180. }
  181. }
  182. for _, _vm := range deleteSystemChilds {
  183. if _vm.DeleteIdSystem == config.ID {
  184. continueFlag = true
  185. break
  186. }
  187. }
  188. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  189. continue
  190. }
  191. if continueFlag {
  192. continue
  193. }
  194. childs = append(childs, config)
  195. childConfig[config.ParentId] = childs
  196. }
  197. }
  198. for _, vm := range resultConfig {
  199. for _, _vm := range vm {
  200. _vm.Childs = childConfig[_vm.ID]
  201. }
  202. // vm.Childs = childConfig[vm.ID]
  203. }
  204. return resultConfig, err
  205. }
  206. func FindConfigByFieldname(module string, field_name string, org_id int64) (dataconfig models.Dataconfig, err error) {
  207. err = readDb.Model(&models.Dataconfig{}).Where("module=? and field_name=? and org_id in (0,?) and status = 1", module, field_name, org_id).First(&dataconfig).Error
  208. return
  209. }
  210. func FindConfigByTitle(module string, title string, org_id int64) (dataconfig models.Dataconfig, err error) {
  211. err = readDb.Model(&models.Dataconfig{}).Where("module=? and title=? and org_id in (0,?) and status = 1", module, title, org_id).First(&dataconfig).Error
  212. return
  213. }
  214. func FindConfigByName(module string, name string, parent_id int64, org_id int64) (dataconfig models.Dataconfig, err error) {
  215. err = readDb.Model(&models.Dataconfig{}).Where("module=? and name=? and parent_id=? and org_id in (0,?) and status = 1", module, name, parent_id, org_id).First(&dataconfig).Error
  216. return
  217. }
  218. func FindConfigByNameForUpdate(module string, name string, parent_id int64, org_id int64, id int64) (dataconfig models.Dataconfig, err error) {
  219. err = readDb.Model(&models.Dataconfig{}).Where("module=? and name=? and parent_id=? and org_id in (0,?) and id != ? and status = 1", module, name, parent_id, org_id, id).First(&dataconfig).Error
  220. return
  221. }
  222. func FindConfigByTitleForUpdate(module string, title string, org_id int64, id int64) (dataconfig models.Dataconfig, err error) {
  223. err = readDb.Model(&models.Dataconfig{}).Where("module=? and title=? and org_id in (0,?) and id != ? and status = 1", module, title, org_id, id).First(&dataconfig).Error
  224. return
  225. }
  226. func UpdateChildConfig(dataconfig *models.Dataconfig) (err error) {
  227. err = readDb.Model(&models.Dataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"name": dataconfig.Name, "update_time": dataconfig.UpdatedTime, "remark": dataconfig.Remark, "orders": dataconfig.Order, "field_type": dataconfig.FieldType}).Error
  228. return
  229. }
  230. func UpdateTemplate(dataconfig *models.Dataconfig) (err error) {
  231. err = readDb.Model(&models.Dataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"title": dataconfig.Title, "content": dataconfig.Content, "update_time": dataconfig.UpdatedTime, "remark": dataconfig.Remark}).Error
  232. return
  233. }
  234. func CreateConfig(dataconfig *models.Dataconfig) (err error) {
  235. // readDb.Model(&models.Dataconfig{}).Where("module = ? and parent_id = 0 and org_id in (0,?)",dataconfig.Module,dataconfig.OrgId).Count(&total)
  236. err = readDb.Create(&dataconfig).Error
  237. return
  238. }
  239. func GetChildValue(module string, parent_id int64, org_id int64) (value int) {
  240. readDb.Model(&models.Dataconfig{}).Where("module=? and parent_id=? and org_id in (0,?)", module, parent_id, org_id).Count(&value)
  241. return
  242. }
  243. func DeleteChildConfig(dataconfig *models.Dataconfig) (err error) {
  244. err = readDb.Model(&models.Dataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"status": dataconfig.Status, "update_time": dataconfig.UpdatedTime}).Error
  245. return
  246. }
  247. func FindFiledByOrgId(org_id int64) (filedConfig []*models.FiledConfig, err error) {
  248. err = readDb.Model(&models.FiledConfig{}).Where("org_id =? AND sys_module = 0", org_id).Find(&filedConfig).Error
  249. return
  250. }
  251. func FindQualityByOrgId(orgid int64) (xtquality []*models.XtQualityControlStandard, err error) {
  252. err = readDb.Model(&models.XtQualityControlStandard{}).Where("user_org_id =? and status =1 and is_status = 1", orgid).Find(&xtquality).Error
  253. return
  254. }
  255. func GetDefaultSystolicPressure(orgid int64) (xtquality []*models.XtQualityControlStandard, err error) {
  256. err = readDb.Model(&models.XtQualityControlStandard{}).Where("user_org_id = ? and status = 1 and is_status =0", orgid).Find(&xtquality).Error
  257. return
  258. }
  259. func FindeInspectionByOrgId(orgid int64) (xtquality []*models.XtCheckConfiguration, err error) {
  260. err = readDb.Model(&models.XtQualityControlStandard{}).Where("user_org_id = ? and status =1", orgid).Find(&xtquality).Error
  261. return
  262. }
  263. func BatchInsertFiledConfig(org_id int64) (err error) {
  264. err = XTWriteDB().Exec("INSERT INTO sgj_xt.xt_filed_config ( org_id, module, filed_name, filed_name_cn, is_show ) SELECT ?, module, filed_name, filed_name_cn, is_show FROM sgj_xt.xt_filed_config WHERE org_id = 0 AND is_show = 1", org_id).Error
  265. return
  266. }
  267. func BatchInsertQualityControl(org_id int64) (err error) {
  268. err = XTWriteDB().Exec("INSERT INTO xt_quality_control_standard(user_org_id,inspection_major,inspection_minor,min_range,large_range,sort,created_time,status,range_type,range_value,is_status) SELECT ?,inspection_major,inspection_minor,min_range,large_range,sort,created_time,status,range_type,range_value,is_status FROM xt_quality_control_standard where user_org_id = 0 and is_status = 1", org_id).Error
  269. return
  270. }
  271. func BathInsertQualityControlTwo(org_id int64) (err error) {
  272. err = XTWriteDB().Exec("INSERT INTO xt_quality_control_standard(user_org_id,inspection_major,inspection_minor,min_range,large_range,sort,created_time,status,range_type,range_value,is_status) SELECT ?,inspection_major,inspection_minor,min_range,large_range,sort,created_time,status,range_type,range_value,is_status FROM xt_quality_control_standard where user_org_id = 0 and is_status = 0", org_id).Error
  273. return
  274. }
  275. func BatchInspectionConfiguration(orgid int64) (err error) {
  276. err = XTWriteDB().Exec("INSERT INTO xt_check_configuration(user_org_id,inspection_major,inspection_frequency,sort,created_time,status) SELECT ?,inspection_major,inspection_frequency,sort,created_time,status FROM xt_check_configuration where user_org_id = 0", orgid).Error
  277. return
  278. }
  279. func ShowFiledConfig(org_id int64, isShow int, is_write int, id int64) (err error) {
  280. err = XTWriteDB().Model(&models.FiledConfig{}).Where("org_id = ? AND id = ?", org_id, id).Updates(map[string]interface{}{"create_time": time.Now().Unix(), "update_time": time.Now().Unix(), "is_show": isShow, "is_write": is_write}).Error
  281. return
  282. }
  283. func FindSysDialysisFiledByOrgId() (filedConfig []*models.FiledConfig, err error) {
  284. err = XTWriteDB().Model(&models.FiledConfig{}).Where("org_id =? AND id in (11250,11251,11252,11253,11254,11255,11256,11257,11258,11259,11260,11261,11262)", 0).Find(&filedConfig).Error
  285. return
  286. }
  287. func BatchInsertFiledSystemConfig(org_id int64) (err error) {
  288. err = XTWriteDB().Exec("INSERT INTO sgj_xt.xt_filed_config ( org_id, module, filed_name, filed_name_cn, is_show ) SELECT ?, module, filed_name, filed_name_cn, is_show FROM sgj_xt.xt_filed_config WHERE org_id = 9442", org_id).Error
  289. return
  290. }
  291. func BatchInsertDoctorSchedule(orgid int64) (err error) {
  292. err = XTWriteDB().Exec("INSERT INTO sgj_xt.xt_doctor_schedules(user_org_id,class_name,class_attributes,timeone_start,timeone_type,timeone_end,timetwo_start,timetwo_type,timetwo_end,work_time,remarks,status,ctime,minute) SELECT ?, class_name,class_attributes,timeone_start,timeone_type,timeone_end,timetwo_start,timetwo_type,timetwo_end,work_time,remarks,status,ctime,minute FROM xt_doctor_schedules WHERE user_org_id = 0", orgid).Error
  293. return
  294. }
  295. func CreateContinueSchedule(schedule *models.ContinueSchedule) error {
  296. err := writeDb.Model(&schedule).Create(&schedule).Error
  297. return err
  298. }
  299. func GetExecutionFrequencyByName(name string, org_id int64) (ef models.ExecutionFrequencyDic, err error) {
  300. err = readDb.Model(&models.ExecutionFrequencyDic{}).Where("org_id = ? AND name = ?", org_id, name).First(&ef).Error
  301. return
  302. }