manage_center_service.go 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. package service
  2. import (
  3. "Xcx_New/models"
  4. "github.com/jinzhu/gorm"
  5. "time"
  6. )
  7. func GetDictionaryConfigList(orgID int64) (dataconfig interface{}, err error) {
  8. var configList []*models.DictionaryDataconfig
  9. 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
  10. if err != nil {
  11. return nil, err
  12. }
  13. // configResult := make([]*ConfigViewModel,0)
  14. childConfig := make(map[int64][]*models.DictionaryDataconfig)
  15. resultConfig := make(map[string][]*models.DictionaryConfigViewModel)
  16. deleteSystemChilds := make([]*models.DictionaryDataconfig, 0)
  17. editSystemChilds := make([]*models.DictionaryDataconfig, 0)
  18. for _, config := range configList {
  19. if config.Status == 1 && config.DeleteIdSystem > 0 {
  20. editSystemChilds = append(editSystemChilds, config)
  21. }
  22. if config.Status == 0 && config.DeleteIdSystem > 0 {
  23. deleteSystemChilds = append(deleteSystemChilds, config)
  24. }
  25. }
  26. continueFlag := false
  27. for _, config := range configList {
  28. continueFlag = false
  29. if config.ParentId == 0 {
  30. newConfig := &models.DictionaryConfigViewModel{
  31. ID: config.ID,
  32. ParentId: config.ParentId,
  33. Module: config.Module,
  34. OrgId: config.OrgId,
  35. Name: config.Name,
  36. FieldName: config.FieldName,
  37. Value: config.Value,
  38. CreateUserId: config.CreateUserId,
  39. Status: config.Status,
  40. Remark: config.Remark,
  41. Title: config.Title,
  42. Content: config.Content,
  43. }
  44. // configResult = append(configResult,newConfig)
  45. result := resultConfig[config.Module]
  46. if result == nil {
  47. result = make([]*models.DictionaryConfigViewModel, 0)
  48. }
  49. for _, vm := range editSystemChilds {
  50. if vm.DeleteIdSystem == config.ID {
  51. continueFlag = true
  52. break
  53. }
  54. }
  55. for _, _vm := range deleteSystemChilds {
  56. if _vm.DeleteIdSystem == config.ID {
  57. continueFlag = true
  58. break
  59. }
  60. }
  61. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  62. continue
  63. }
  64. if continueFlag {
  65. continue
  66. }
  67. result = append(result, newConfig)
  68. resultConfig[config.Module] = result
  69. } else {
  70. childs := childConfig[config.ParentId]
  71. if childs == nil {
  72. childs = make([]*models.DictionaryDataconfig, 0)
  73. }
  74. continueFlag := false
  75. for _, vm := range editSystemChilds {
  76. if vm.DeleteIdSystem == config.ID {
  77. continueFlag = true
  78. break
  79. }
  80. }
  81. for _, _vm := range deleteSystemChilds {
  82. if _vm.DeleteIdSystem == config.ID {
  83. continueFlag = true
  84. break
  85. }
  86. }
  87. if config.OrgId != 0 && config.Status == 0 && config.DeleteIdSystem > 0 {
  88. continue
  89. }
  90. if continueFlag {
  91. continue
  92. }
  93. childs = append(childs, config)
  94. childConfig[config.ParentId] = childs
  95. }
  96. }
  97. for _, vm := range resultConfig {
  98. for _, _vm := range vm {
  99. _vm.Childs = childConfig[_vm.ID]
  100. }
  101. // vm.Childs = childConfig[vm.ID]
  102. }
  103. return resultConfig, err
  104. }
  105. func CreateDictionaryConfig(dataconfig *models.DictionaryDataconfig) (err error) {
  106. // readDb.Model(&models.Dataconfig{}).Where("module = ? and parent_id = 0 and org_id in (0,?)",dataconfig.Module,dataconfig.OrgId).Count(&total)
  107. err = readDb.Create(&dataconfig).Error
  108. return
  109. }
  110. func GetDictionaryChildValue(module string, parent_id int64, org_id int64) (value int) {
  111. readDb.Model(&models.DictionaryDataconfig{}).Where("module=? and parent_id=? and org_id in (0,?)", module, parent_id, org_id).Count(&value)
  112. return
  113. }
  114. func FindDictionaryConfigByTitle(module string, title string, org_id int64) (dataconfig models.DictionaryDataconfig, err error) {
  115. err = readDb.Model(&models.DictionaryDataconfig{}).Where("module=? and title=? and org_id in (0,?) and status = 1", module, title, org_id).First(&dataconfig).Error
  116. return
  117. }
  118. func UpdateDictionaryTemplate(dataconfig *models.DictionaryDataconfig) (err error) {
  119. err = readDb.Model(&models.DictionaryDataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"title": dataconfig.Title, "content": dataconfig.Content, "update_time": dataconfig.UpdatedTime, "remark": dataconfig.Remark}).Error
  120. return
  121. }
  122. func UpdateDictionaryChildConfig(dataconfig *models.DictionaryDataconfig) (err error) {
  123. err = readDb.Model(&models.DictionaryDataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"name": dataconfig.Name, "update_time": dataconfig.UpdatedTime, "remark": dataconfig.Remark, "orders": dataconfig.Order, "code": dataconfig.Code}).Error
  124. return
  125. }
  126. func DeleteDictionaryChildConfig(dataconfig *models.DictionaryDataconfig) (err error) {
  127. err = readDb.Model(&models.DictionaryDataconfig{}).Where("id =?", dataconfig.ID).Update(map[string]interface{}{"status": dataconfig.Status, "update_time": dataconfig.UpdatedTime}).Error
  128. return
  129. }
  130. func CreateBaseDrugLib(lib *models.BaseDrugLib) (err error) {
  131. err = writeDb.Create(&lib).Error
  132. return
  133. }
  134. func UpdateBaseDrugLib(lib *models.BaseDrugLib) (err error) {
  135. err = writeDb.Save(lib).Error
  136. return
  137. }
  138. func FindBaseDrugLibRecordCount(lib *models.BaseDrugLib) (count int64) {
  139. readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND drug_name = ? AND drug_category = ? AND drug_spec=? AND drug_type=? AND status = 1", lib.OrgId, lib.DrugName, lib.DrugCategory, lib.DrugSpec, lib.DrugType).Count(&count)
  140. return
  141. }
  142. func FindBaseDrugLibRecordCountOne(lib *models.BaseDrugLib) (count int64) {
  143. readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? and drug_name = ? and dose = ? and dose_unit = ? and min_number = ? and min_unit = ? and max_unit = ? and manufacturer = ? and status = 1", lib.OrgId, lib.DrugName, lib.Dose, lib.DoseUnit, lib.MinNumber, lib.MinUnit, lib.MaxUnit, lib.Manufacturer).Count(&count)
  144. return
  145. }
  146. func FindAllDrugLibRecordTotal(org_id int64) (count int64) {
  147. readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Count(&count)
  148. return
  149. }
  150. func FindBaseDrugLibRecord(org_id int64, id int64) (lib models.BaseDrugLib, err error) {
  151. err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND id = ? AND status = 1", org_id, id).First(&lib).Error
  152. return
  153. }
  154. func GetBaseDrugLibList(org_id int64, keyword string, page int64, limit int64, is_use int64, is_charge int64, is_inject int64, manufacturer int64, isRecord int64) (list []*models.BaseDrugLib, total int64, err error) {
  155. db := readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id)
  156. if len(keyword) != 0 {
  157. keyword = "%" + keyword + "%"
  158. db = db.Where("drug_name Like ?", keyword)
  159. }
  160. if is_use != 0 {
  161. if is_use == 1 {
  162. db = db.Where("find_in_set('停用',drug_status) = 0")
  163. } else {
  164. db = db.Where("find_in_set('停用',drug_status) > 0")
  165. }
  166. }
  167. if is_charge != 0 {
  168. //db = db.Where("drug_name Like ?", keyword)
  169. if is_charge == 1 {
  170. db = db.Where("find_in_set('收费',drug_status) > 0")
  171. } else {
  172. db = db.Where("find_in_set('收费',drug_status) = 0")
  173. }
  174. }
  175. if is_inject != 0 {
  176. //db = db.Where("drug_name Like ?", keyword)
  177. if is_inject == 1 {
  178. db = db.Where("find_in_set('注射类',drug_status) > 0")
  179. } else {
  180. db = db.Where("find_in_set('注射类',drug_status) = 0")
  181. }
  182. }
  183. if manufacturer > 0 {
  184. db = db.Where("manufacturer = ?", manufacturer)
  185. }
  186. if isRecord > 0 {
  187. db = db.Where("is_mark = ?", isRecord)
  188. }
  189. offset := (page - 1) * limit
  190. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  191. return
  192. }
  193. func CreateMedicineInsurancePercentage(mip *models.MedicineInsurancePercentage) (err error) {
  194. err = writeDb.Create(mip).Error
  195. return
  196. }
  197. func CreateUnitSafeguard(dus *models.DrugUnitSafeguard) (err error) {
  198. err = writeDb.Create(dus).Error
  199. return
  200. }
  201. func AddSigleMZSick(dealer *models.OutpatientServiceSick) (error, *models.OutpatientServiceSick) {
  202. err := writeDb.Create(&dealer).Error
  203. return err, dealer
  204. }
  205. func ModifyMZSick(mesick *models.OutpatientServiceSick) error {
  206. err := writeDb.Save(&mesick).Error
  207. return err
  208. }
  209. func FindAllMZSickList(orgId int64, page int64, limit int64) (list []*models.OutpatientServiceSick, total int64, err error) {
  210. offset := (page - 1) * limit
  211. db := readDb.Model(&models.OutpatientServiceSick{})
  212. db = db.Where("user_org_id = ? AND status = 1", orgId)
  213. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  214. return
  215. }
  216. func DeleteMZSickById(id int64) error {
  217. err := writeDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  218. return err
  219. }
  220. func FindMZSickById(id int64) (*models.OutpatientServiceSick, error) {
  221. dealer := &models.OutpatientServiceSick{}
  222. err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&dealer).Error
  223. return dealer, err
  224. }
  225. func GetDrugWareoutInfo(id int64) (*models.XtDrugWarehouseInfo, error) {
  226. info := models.XtDrugWarehouseInfo{}
  227. err = XTReadDB().Model(&info).Where("drug_id = ? and status = 1", id).Find(&info).Error
  228. if err == gorm.ErrRecordNotFound {
  229. return nil, err
  230. }
  231. if err != nil {
  232. return nil, err
  233. }
  234. return &info, nil
  235. }
  236. func GetDrugWareOutById(id int64) (*models.XtDrugWarehouseOutInfo, error) {
  237. info := models.XtDrugWarehouseOutInfo{}
  238. err := XTReadDB().Model(&info).Where("drug_id = ? and status = 1", id).Find(&info).Error
  239. if err == gorm.ErrRecordNotFound {
  240. return nil, err
  241. }
  242. if err != nil {
  243. return nil, err
  244. }
  245. return &info, nil
  246. }
  247. func DeleteBaseDrugById(id int64) error {
  248. drug := models.XtBaseDrug{}
  249. err := XTWriteDB().Model(&drug).Where("id = ? and status = 1", id).Updates(map[string]interface{}{"status": 0}).Error
  250. return err
  251. }
  252. func AddSigleAddition(dealer *models.XtHisAddtionConfig) (error, *models.XtHisAddtionConfig) {
  253. err := writeDb.Create(&dealer).Error
  254. return err, dealer
  255. }
  256. func ModifyAddition(mesick *models.XtHisAddtionConfig) error {
  257. err := writeDb.Save(&mesick).Error
  258. return err
  259. }
  260. func FindAllAdditionList(orgId int64, page int64, limit int64) (list []*models.XtHisAddtionConfig, total int64, err error) {
  261. offset := (page - 1) * limit
  262. db := readDb.Model(&models.XtHisAddtionConfig{})
  263. db = db.Where("user_org_id = ? AND status = 1", orgId)
  264. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  265. return
  266. }
  267. func DeleteAdditionById(id int64) error {
  268. err := writeDb.Model(&models.XtHisAddtionConfig{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  269. return err
  270. }
  271. func FindAdditionById(id int64) (*models.XtHisAddtionConfig, error) {
  272. dealer := &models.XtHisAddtionConfig{}
  273. err := readDb.Model(&models.XtHisAddtionConfig{}).Where("id = ? AND status = 1", id).First(&dealer).Error
  274. return dealer, err
  275. }
  276. func AddSigleDiagnose(dealer *models.HisXtDiagnoseConfig) (error, *models.HisXtDiagnoseConfig) {
  277. err := writeDb.Create(&dealer).Error
  278. return err, dealer
  279. }
  280. func ModifyDiagnose(mesick *models.HisXtDiagnoseConfig) error {
  281. err := writeDb.Save(&mesick).Error
  282. return err
  283. }
  284. func FindAllDiagnoseList(orgId int64, page int64, limit int64) (list []*models.HisXtDiagnoseConfig, total int64, err error) {
  285. offset := (page - 1) * limit
  286. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  287. db = db.Where("user_org_id = ? AND status = 1", orgId)
  288. err = db.Count(&total).Offset(offset).Limit(limit).Order("ctime desc").Find(&list).Error
  289. return
  290. }
  291. func DeleteDiagnoseById(id int64) error {
  292. err := writeDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? AND status = 1", id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  293. return err
  294. }
  295. func FindDiagnoseById(id int64) (*models.HisXtDiagnoseConfig, error) {
  296. dealer := &models.HisXtDiagnoseConfig{}
  297. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? AND status = 1", id).First(&dealer).Error
  298. return dealer, err
  299. }
  300. func GetDoseCode(dose_id int64, user_org_id int64) (error, string) {
  301. var data models.DictDataconfig
  302. err := readDb.Model(&models.DictDataconfig{}).Where(" (user_org_id = ? Or user_org_id = 0) AND parent_id = 4 AND module = 'system' AND status = 1 AND value = ?", user_org_id, dose_id).First(&data).Error
  303. return err, data.Code
  304. }
  305. func GetAllDrugList(orgid int64) (drug []*models.BaseDrugLib, err error) {
  306. err = XTReadDB().Model(&drug).Where("org_id = ? and status = 1", orgid).Find(&drug).Error
  307. return drug, err
  308. }