data.go 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. package service
  2. import (
  3. _ "strconv"
  4. _ "strings"
  5. "time"
  6. "XT_New/models"
  7. _ "github.com/astaxie/beego"
  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. Sort: config.Sort,
  47. }
  48. // configResult = append(configResult,newConfig)
  49. result := resultConfig[config.Module]
  50. if result == nil {
  51. result = make([]*models.ConfigViewModel, 0)
  52. }
  53. for _, vm := range editSystemChilds {
  54. if vm.DeleteIdSystem == config.ID {
  55. continueFlag = true
  56. break
  57. }
  58. }
  59. for _, _vm := range deleteSystemChilds {
  60. if _vm.DeleteIdSystem == config.ID {
  61. continueFlag = true
  62. break
  63. }
  64. }
  65. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  66. continue
  67. }
  68. if continueFlag {
  69. continue
  70. }
  71. result = append(result, newConfig)
  72. resultConfig[config.Module] = result
  73. } else {
  74. childs := childConfig[config.ParentId]
  75. if childs == nil {
  76. childs = make([]*models.Dataconfig, 0)
  77. }
  78. continueFlag := false
  79. for _, vm := range editSystemChilds {
  80. if vm.DeleteIdSystem == config.ID {
  81. continueFlag = true
  82. break
  83. }
  84. }
  85. for _, _vm := range deleteSystemChilds {
  86. if _vm.DeleteIdSystem == config.ID {
  87. continueFlag = true
  88. break
  89. }
  90. }
  91. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  92. continue
  93. }
  94. if continueFlag {
  95. continue
  96. }
  97. childs = append(childs, config)
  98. childConfig[config.ParentId] = childs
  99. }
  100. }
  101. for _, vm := range resultConfig {
  102. for _, _vm := range vm {
  103. _vm.Childs = childConfig[_vm.ID]
  104. }
  105. // vm.Childs = childConfig[vm.ID]
  106. }
  107. return resultConfig, err
  108. }
  109. func GetDictConfigList(orgID int64) (dataconfig interface{}, err error) {
  110. var configList []*models.DictionaryDataconfig
  111. 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
  112. if err != nil {
  113. return nil, err
  114. }
  115. // configResult := make([]*ConfigViewModel,0)
  116. childConfig := make(map[int64][]*models.DictionaryDataconfig)
  117. resultConfig := make(map[string][]*models.DictionaryConfigViewModel)
  118. deleteSystemChilds := make([]*models.DictionaryDataconfig, 0)
  119. editSystemChilds := make([]*models.DictionaryDataconfig, 0)
  120. for _, config := range configList {
  121. if config.Status == 1 && config.DeleteIdSystem > 0 {
  122. editSystemChilds = append(editSystemChilds, config)
  123. }
  124. if config.Status == 0 && config.DeleteIdSystem > 0 {
  125. deleteSystemChilds = append(deleteSystemChilds, config)
  126. }
  127. }
  128. continueFlag := false
  129. for _, config := range configList {
  130. continueFlag = false
  131. if config.ParentId == 0 {
  132. newConfig := &models.DictionaryConfigViewModel{
  133. ID: config.ID,
  134. ParentId: config.ParentId,
  135. Module: config.Module,
  136. OrgId: config.OrgId,
  137. Name: config.Name,
  138. FieldName: config.FieldName,
  139. Value: config.Value,
  140. CreateUserId: config.CreateUserId,
  141. Status: config.Status,
  142. Remark: config.Remark,
  143. Title: config.Title,
  144. Content: config.Content,
  145. }
  146. // configResult = append(configResult,newConfig)
  147. result := resultConfig[config.Module]
  148. if result == nil {
  149. result = make([]*models.DictionaryConfigViewModel, 0)
  150. }
  151. for _, vm := range editSystemChilds {
  152. if vm.DeleteIdSystem == config.ID {
  153. continueFlag = true
  154. break
  155. }
  156. }
  157. for _, _vm := range deleteSystemChilds {
  158. if _vm.DeleteIdSystem == config.ID {
  159. continueFlag = true
  160. break
  161. }
  162. }
  163. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  164. continue
  165. }
  166. if continueFlag {
  167. continue
  168. }
  169. result = append(result, newConfig)
  170. resultConfig[config.Module] = result
  171. } else {
  172. childs := childConfig[config.ParentId]
  173. if childs == nil {
  174. childs = make([]*models.DictionaryDataconfig, 0)
  175. }
  176. continueFlag := false
  177. for _, vm := range editSystemChilds {
  178. if vm.DeleteIdSystem == config.ID {
  179. continueFlag = true
  180. break
  181. }
  182. }
  183. for _, _vm := range deleteSystemChilds {
  184. if _vm.DeleteIdSystem == config.ID {
  185. continueFlag = true
  186. break
  187. }
  188. }
  189. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  190. continue
  191. }
  192. if continueFlag {
  193. continue
  194. }
  195. childs = append(childs, config)
  196. childConfig[config.ParentId] = childs
  197. }
  198. }
  199. for _, vm := range resultConfig {
  200. for _, _vm := range vm {
  201. _vm.Childs = childConfig[_vm.ID]
  202. }
  203. // vm.Childs = childConfig[vm.ID]
  204. }
  205. return resultConfig, err
  206. }
  207. func FindConfigByFieldname(module string, field_name string, org_id int64) (dataconfig models.Dataconfig, err error) {
  208. 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
  209. return
  210. }
  211. func FindConfigByTitle(module string, title string, org_id int64) (dataconfig models.Dataconfig, err error) {
  212. err = readDb.Model(&models.Dataconfig{}).Where("module=? and title=? and org_id in (0,?) and status = 1", module, title, org_id).First(&dataconfig).Error
  213. return
  214. }
  215. func FindConfigByName(module string, name string, parent_id int64, org_id int64) (dataconfig models.Dataconfig, err error) {
  216. 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
  217. return
  218. }
  219. func FindConfigByNameForUpdate(module string, name string, parent_id int64, org_id int64, id int64) (dataconfig models.Dataconfig, err error) {
  220. 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
  221. return
  222. }
  223. func FindConfigByTitleForUpdate(module string, title string, org_id int64, id int64) (dataconfig models.Dataconfig, err error) {
  224. 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
  225. return
  226. }
  227. func UpdateChildConfig(dataconfig *models.Dataconfig) (err error) {
  228. 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
  229. return
  230. }
  231. func UpdateTemplate(dataconfig *models.Dataconfig) (err error) {
  232. 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
  233. return
  234. }
  235. func CreateConfig(dataconfig *models.Dataconfig) (err error) {
  236. // readDb.Model(&models.Dataconfig{}).Where("module = ? and parent_id = 0 and org_id in (0,?)",dataconfig.Module,dataconfig.OrgId).Count(&total)
  237. err = readDb.Create(&dataconfig).Error
  238. return
  239. }
  240. func GetChildValue(module string, parent_id int64, org_id int64) (value int) {
  241. readDb.Model(&models.Dataconfig{}).Where("module=? and parent_id=? and org_id in (0,?)", module, parent_id, org_id).Count(&value)
  242. return
  243. }
  244. func DeleteChildConfig(dataconfig *models.Dataconfig) (err error) {
  245. err = readDb.Model(&models.Dataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"status": dataconfig.Status, "update_time": dataconfig.UpdatedTime}).Error
  246. return
  247. }
  248. func FindFiledByOrgId(org_id int64) (filedConfig []*models.FiledConfig, err error) {
  249. err = readDb.Model(&models.FiledConfig{}).Where("org_id =? AND sys_module = 0", org_id).Find(&filedConfig).Error
  250. return
  251. }
  252. func FindQualityByOrgId(orgid int64) (xtquality []*models.XtQualityControlStandard, err error) {
  253. err = readDb.Model(&models.XtQualityControlStandard{}).Where("user_org_id =? and status =1 and is_status = 1", orgid).Find(&xtquality).Error
  254. return
  255. }
  256. func GetDefaultSystolicPressure(orgid int64) (xtquality []*models.XtQualityControlStandard, err error) {
  257. err = readDb.Model(&models.XtQualityControlStandard{}).Where("user_org_id = ? and status = 1 and is_status =0", orgid).Find(&xtquality).Error
  258. return
  259. }
  260. func FindeInspectionByOrgId(orgid int64) (xtquality []*models.XtCheckConfiguration, err error) {
  261. err = readDb.Model(&models.XtQualityControlStandard{}).Where("user_org_id = ? and status =1", orgid).Find(&xtquality).Error
  262. return
  263. }
  264. func BatchInsertFiledConfig(org_id int64) (err error) {
  265. 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
  266. return
  267. }
  268. func BatchInsertQualityControl(org_id int64) (err error) {
  269. 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
  270. return
  271. }
  272. func BathInsertQualityControlTwo(org_id int64) (err error) {
  273. 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
  274. return
  275. }
  276. func BatchInspectionConfiguration(orgid int64) (err error) {
  277. 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
  278. return
  279. }
  280. func ShowFiledConfig(org_id int64, isShow int, is_write int, id int64) (err error) {
  281. 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
  282. return
  283. }
  284. func FindSysDialysisFiledByOrgId() (filedConfig []*models.FiledConfig, err error) {
  285. 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
  286. return
  287. }
  288. func BatchInsertFiledSystemConfig(org_id int64) (err error) {
  289. 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
  290. return
  291. }
  292. func BatchInsertDoctorSchedule(orgid int64) (err error) {
  293. 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
  294. return
  295. }
  296. func CreateContinueSchedule(schedule *models.ContinueSchedule) error {
  297. err := writeDb.Model(&schedule).Create(&schedule).Error
  298. return err
  299. }
  300. func GetExecutionFrequencyByName(name string, org_id int64) (ef models.ExecutionFrequencyDic, err error) {
  301. err = readDb.Model(&models.ExecutionFrequencyDic{}).Where("org_id = ? AND name = ?", org_id, name).First(&ef).Error
  302. return
  303. }