his_project_api_controller.go 32KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. type HisProjectApiController struct {
  16. BaseAuthAPIController
  17. }
  18. func HisProjectRouters() {
  19. beego.Router("/api/his/saveproject", &HisProjectApiController{}, "Get:SaveProject")
  20. beego.Router("/api/his/getprojectlist", &HisProjectApiController{}, "Get:GetProjectList")
  21. beego.Router("/api/his/getprojectdetail", &HisProjectApiController{}, "Get:GetProjectDetail")
  22. beego.Router("/api/his/updatedproject", &HisProjectApiController{}, "Get:UpdatedProject")
  23. beego.Router("/api/his/deletehisproject", &HisProjectApiController{}, "Get:DeleteHisProject")
  24. beego.Router("/api/his/saveprojectteam", &HisProjectApiController{}, "Get:SaveProjectTeam")
  25. beego.Router("/api/his/getprojectteamlist", &HisProjectApiController{}, "Get:GetProjectTeamList")
  26. beego.Router("/api/his/getprojectteamdetail", &HisProjectApiController{}, "Get:GetProjectTeamDetail")
  27. beego.Router("/api/his/updateprojectteam", &HisProjectApiController{}, "Get:UpdatedProjectTeam")
  28. beego.Router("/api/his/deleteprojectteam", &HisProjectApiController{}, "Get:DeleteProjectTeam")
  29. beego.Router("/api/his/savedepartment", &HisProjectApiController{}, "Get:SaveDePartment")
  30. beego.Router("/api/his/getdepartmentlist", &HisProjectApiController{}, "Get:GetDepartMentList")
  31. beego.Router("/api/his/getdepartmentdetail", &HisProjectApiController{}, "Get:GetDepartMentDetail")
  32. beego.Router("/api/his/updagtedepartment", &HisProjectApiController{}, "Get:UpdatedDeparment")
  33. beego.Router("/api/his/deletedeparment", &HisProjectApiController{}, "Get:DeleteDepartment")
  34. beego.Router("/api/his/getallprojectlist", &HisProjectApiController{}, "Get:GetAllProjectList")
  35. beego.Router("/api/his/addprojectlist", &HisProjectApiController{}, "Get:AddProjectList")
  36. beego.Router("/api/his/deleteproject", &HisProjectApiController{}, "Get:DeleteProject")
  37. beego.Router("/api/his/gethisproject", &HisProjectApiController{}, "Get:GetHisProject")
  38. beego.Router("/api/his/getprojectteam", &HisProjectApiController{}, "Get:GetProjectTeam")
  39. beego.Router("/api/his/getalldoctorlist", &HisProjectApiController{}, "Get:GetAllDoctorList")
  40. beego.Router("/api/his/savehispatient", &HisProjectApiController{}, "Get:SaveHisPatient")
  41. //获取今日血透排班的患者
  42. beego.Router("/api/his/getbloodpatient", &HisProjectApiController{}, "Get:GetBloodPatientList")
  43. //获取患者的今日透析处方
  44. beego.Router("/api/his/gethisprescription", &HisProjectApiController{}, "Get:GetHisPrescription")
  45. //新增附加费用
  46. beego.Router("/api/his/additionalcharge", &HisProjectApiController{}, "Post:AdditionalCharge")
  47. //获取治疗单
  48. beego.Router("/api/his/gettreatlist", &HisProjectApiController{}, "Get:GetTreatmentList")
  49. beego.Router("/api/his/getpatientinformation", &HisProjectApiController{}, "Get:GetPatientInformation")
  50. beego.Router("/api/hist/getallprojecteam", &HisProjectApiController{}, "Get:GetAllProjectTeam")
  51. beego.Router("/api/his/getprojectlistbyid", &HisProjectApiController{}, "Get:GetProjectListById")
  52. beego.Router("/api/his/gethispatienthistory", &HisProjectApiController{}, "Get:GetHisPatientHistory")
  53. beego.Router("/api/patient/changepatient", &HisProjectApiController{}, "Get:ChangePatient")
  54. beego.Router("/api/patient/getpatientcasehistory", &HisProjectApiController{}, "Get:GetPatientcaseHistory")
  55. beego.Router("/api/doctorworkstation/gettemplatedetail", &HisProjectApiController{}, "Get:GetTemplateDetail")
  56. beego.Router("/api/doctorworkstation/updaterecordtemplate", &HisProjectApiController{}, "Get:UpdateRecordTemplate")
  57. beego.Router("/api/hispatient/gehispatient", &HisProjectApiController{}, "Get:GetHisPatient")
  58. }
  59. func (this *HisProjectApiController) SaveProject() {
  60. project_name := this.GetString("project_name")
  61. pinyin := this.GetString("pinyin")
  62. wubi := this.GetString("wubi")
  63. price := this.GetString("price")
  64. price_float, err := strconv.ParseFloat(price, 64)
  65. unit := this.GetString("unit")
  66. cost_classify, _ := this.GetInt64("cost_classify")
  67. executive_section, _ := this.GetInt64("executive_section")
  68. medical_coverage, _ := this.GetInt64("medical_coverage")
  69. statistical_classification, _ := this.GetInt64("statistical_classification")
  70. disease_directory, _ := this.GetInt64("disease_directory")
  71. is_record, _ := this.GetInt64("is_record")
  72. medical_code := this.GetString("medical_code")
  73. tube_color, _ := this.GetInt64("tube_color")
  74. medical_status, _ := this.GetInt64("medical_status")
  75. remark := this.GetString("remark")
  76. sign, _ := this.GetInt64("sign")
  77. default_number := this.GetString("default_number")
  78. is_charge, _ := this.GetInt64("is_charge")
  79. is_estimate, _ := this.GetInt64("is_estimate")
  80. is_workload, _ := this.GetInt64("is_workload")
  81. sort := this.GetString("sort")
  82. is_advice, _ := this.GetInt64("is_advice")
  83. is_default, _ := this.GetInt64("is_default")
  84. single_dose := this.GetString("single_dose")
  85. delivery_way := this.GetString("delivery_way")
  86. execution_frequency := this.GetString("execution_frequency")
  87. number_days := this.GetString("number_days")
  88. total := this.GetString("total")
  89. adminUserInfo := this.GetAdminUserInfo()
  90. orgId := adminUserInfo.CurrentOrgId
  91. hisProject := models.XtHisProject{
  92. ProjectName: project_name,
  93. Pinyin: pinyin,
  94. Wubi: wubi,
  95. Price: price_float,
  96. Unit: unit,
  97. CostClassify: cost_classify,
  98. ExecutiveSection: executive_section,
  99. MedicalCoverage: medical_coverage,
  100. StatisticalClassification: statistical_classification,
  101. DiseaseDirectory: disease_directory,
  102. IsRecord: is_record,
  103. MedicalCode: medical_code,
  104. TubeColor: tube_color,
  105. MedicalStatus: medical_status,
  106. Remark: remark,
  107. Sign: sign,
  108. DefaultNumber: default_number,
  109. IsCharge: is_charge,
  110. IsEstimate: is_estimate,
  111. IsWorkload: is_workload,
  112. Sort: sort,
  113. DoctorAdvice: is_advice,
  114. IsDefault: is_default,
  115. UserOrgId: orgId,
  116. Status: 1,
  117. CreatedTime: time.Now().Unix(),
  118. SingleDose: single_dose,
  119. DeliveryWay: delivery_way,
  120. ExecutionFrequency: execution_frequency,
  121. NumberDays: number_days,
  122. Total: total,
  123. }
  124. //查询项目名称是否存在
  125. _, errcode := service.GetHisProjectIsExist(project_name, orgId)
  126. if errcode == gorm.ErrRecordNotFound {
  127. err = service.CreateHisProject(&hisProject)
  128. if err != nil {
  129. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  130. return
  131. }
  132. this.ServeSuccessJSON(map[string]interface{}{
  133. "hisProject": hisProject,
  134. })
  135. return
  136. } else if errcode == nil {
  137. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  138. return
  139. }
  140. }
  141. func (this *HisProjectApiController) GetProjectList() {
  142. adminUserInfo := this.GetAdminUserInfo()
  143. orgId := adminUserInfo.CurrentOrgId
  144. limit, _ := this.GetInt64("limit")
  145. page, _ := this.GetInt64("page")
  146. is_charge, _ := this.GetInt64("is_charge")
  147. is_start, _ := this.GetInt64("is_start")
  148. keyword := this.GetString("keyword")
  149. projecList, total, err := service.GetHisProjectList(orgId, limit, page, is_charge, is_start, keyword)
  150. if err != nil {
  151. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  152. return
  153. }
  154. this.ServeSuccessJSON(map[string]interface{}{
  155. "projecList": projecList,
  156. "total": total,
  157. })
  158. return
  159. }
  160. func (this *HisProjectApiController) GetProjectDetail() {
  161. id, _ := this.GetInt64("id")
  162. projectDetail, err := service.GetProjectDetail(id)
  163. if err != nil {
  164. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  165. return
  166. }
  167. this.ServeSuccessJSON(map[string]interface{}{
  168. "projecDetail": projectDetail,
  169. })
  170. return
  171. }
  172. func (this *HisProjectApiController) UpdatedProject() {
  173. id, _ := this.GetInt64("id")
  174. project_name := this.GetString("project_name")
  175. pinyin := this.GetString("pinyin")
  176. wubi := this.GetString("wubi")
  177. price := this.GetString("price")
  178. price_float, _ := strconv.ParseFloat(price, 64)
  179. unit := this.GetString("unit")
  180. cost_classify, _ := this.GetInt64("cost_classify")
  181. executive_section, _ := this.GetInt64("executive_section")
  182. medical_coverage, _ := this.GetInt64("medical_coverage")
  183. statistical_classification, _ := this.GetInt64("statistical_classification")
  184. disease_directory, _ := this.GetInt64("disease_directory")
  185. is_record, _ := this.GetInt64("is_record")
  186. medical_code := this.GetString("medical_code")
  187. tube_color, _ := this.GetInt64("tube_color")
  188. medical_status, _ := this.GetInt64("medical_status")
  189. remark := this.GetString("remark")
  190. sign, _ := this.GetInt64("sign")
  191. default_number := this.GetString("default_number")
  192. is_charge, _ := this.GetInt64("is_charge")
  193. is_estimate, _ := this.GetInt64("is_estimate")
  194. is_workload, _ := this.GetInt64("is_workload")
  195. sort := this.GetString("sort")
  196. is_advice, _ := this.GetInt64("is_advice")
  197. is_default, _ := this.GetInt64("is_default")
  198. single_dose := this.GetString("single_dose")
  199. delivery_way := this.GetString("delivery_way")
  200. execution_frequency := this.GetString("execution_frequency")
  201. number_days := this.GetString("number_days")
  202. total := this.GetString("total")
  203. hisProject := models.XtHisProject{
  204. ProjectName: project_name,
  205. Pinyin: pinyin,
  206. Wubi: wubi,
  207. Price: price_float,
  208. Unit: unit,
  209. CostClassify: cost_classify,
  210. ExecutiveSection: executive_section,
  211. MedicalCoverage: medical_coverage,
  212. StatisticalClassification: statistical_classification,
  213. DiseaseDirectory: disease_directory,
  214. IsRecord: is_record,
  215. MedicalCode: medical_code,
  216. TubeColor: tube_color,
  217. MedicalStatus: medical_status,
  218. Remark: remark,
  219. Sign: sign,
  220. DefaultNumber: default_number,
  221. IsCharge: is_charge,
  222. IsEstimate: is_estimate,
  223. IsWorkload: is_workload,
  224. Sort: sort,
  225. DoctorAdvice: is_advice,
  226. IsDefault: is_default,
  227. UpdatedTime: time.Now().Unix(),
  228. SingleDose: single_dose,
  229. DeliveryWay: delivery_way,
  230. ExecutionFrequency: execution_frequency,
  231. NumberDays: number_days,
  232. Total: total,
  233. }
  234. err := service.UpdatedProject(id, &hisProject)
  235. if err != nil {
  236. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  237. return
  238. }
  239. this.ServeSuccessJSON(map[string]interface{}{
  240. "hisProject": hisProject,
  241. })
  242. return
  243. }
  244. func (this *HisProjectApiController) DeleteHisProject() {
  245. id, _ := this.GetInt64("id")
  246. err := service.DeleteHisProject(id)
  247. if err != nil {
  248. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  249. return
  250. }
  251. returnData := make(map[string]interface{}, 0)
  252. returnData["msg"] = "ok"
  253. this.ServeSuccessJSON(returnData)
  254. return
  255. }
  256. func (this *HisProjectApiController) SaveProjectTeam() {
  257. project_team := this.GetString("project_team")
  258. price := this.GetString("price")
  259. price_float, _ := strconv.ParseFloat(price, 64)
  260. pinyin := this.GetString("pinyin")
  261. wubi := this.GetString("wubi")
  262. tube_color, _ := this.GetInt64("tube_color")
  263. team_type, _ := this.GetInt64("team_type")
  264. remark := this.GetString("remark")
  265. ids := this.GetString("ids")
  266. adminUserInfo := this.GetAdminUserInfo()
  267. orgId := adminUserInfo.CurrentOrgId
  268. projectTeam := models.XtHisProjectTeam{
  269. ProjectTeam: project_team,
  270. Price: price_float,
  271. Pinyin: pinyin,
  272. Wubi: wubi,
  273. TubeColor: tube_color,
  274. TeamType: team_type,
  275. Remark: remark,
  276. UserOrgId: orgId,
  277. Status: 1,
  278. CreatedTime: time.Now().Unix(),
  279. ProjectId: ids,
  280. }
  281. fmt.Println(projectTeam)
  282. _, errcodes := service.GetHisProjectByNameOne(project_team, orgId)
  283. if errcodes == gorm.ErrRecordNotFound {
  284. err := service.CreatedProjectTeam(&projectTeam)
  285. if err != nil {
  286. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  287. return
  288. }
  289. this.ServeSuccessJSON(map[string]interface{}{
  290. "projectTeam": projectTeam,
  291. })
  292. return
  293. } else if errcodes == nil {
  294. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  295. return
  296. }
  297. }
  298. func (this *HisProjectApiController) GetProjectTeamList() {
  299. limit, _ := this.GetInt64("limit")
  300. page, _ := this.GetInt64("page")
  301. keyword := this.GetString("keyword")
  302. adminUserInfo := this.GetAdminUserInfo()
  303. orgId := adminUserInfo.CurrentOrgId
  304. projectTeamList, total, err := service.GetProjectTeamList(limit, page, orgId, keyword)
  305. if err != nil {
  306. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  307. return
  308. }
  309. this.ServeSuccessJSON(map[string]interface{}{
  310. "projectTeamList": projectTeamList,
  311. "total": total,
  312. })
  313. return
  314. }
  315. func (this *HisProjectApiController) GetProjectTeamDetail() {
  316. id, _ := this.GetInt64("id")
  317. projectTeamDetail, err := service.GetProjectTeamDetail(id)
  318. if err != nil {
  319. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  320. return
  321. }
  322. this.ServeSuccessJSON(map[string]interface{}{
  323. "projectTeamDetail": projectTeamDetail,
  324. })
  325. return
  326. }
  327. func (this *HisProjectApiController) UpdatedProjectTeam() {
  328. id, _ := this.GetInt64("id")
  329. project_team := this.GetString("project_team")
  330. price := this.GetString("price")
  331. price_float, _ := strconv.ParseFloat(price, 64)
  332. pinyin := this.GetString("pinyin")
  333. wubi := this.GetString("wubi")
  334. tube_color, _ := this.GetInt64("tube_color")
  335. team_type, _ := this.GetInt64("team_type")
  336. remark := this.GetString("remark")
  337. ids := this.GetString("ids")
  338. projectTeam := models.XtHisProjectTeam{
  339. ProjectTeam: project_team,
  340. Price: price_float,
  341. Pinyin: pinyin,
  342. Wubi: wubi,
  343. TubeColor: tube_color,
  344. TeamType: team_type,
  345. Remark: remark,
  346. ProjectId: ids,
  347. }
  348. err := service.UpdatedProjectTeam(id, &projectTeam)
  349. if err != nil {
  350. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  351. return
  352. }
  353. this.ServeSuccessJSON(map[string]interface{}{
  354. "projectTeam": projectTeam,
  355. })
  356. return
  357. }
  358. func (this *HisProjectApiController) DeleteProjectTeam() {
  359. id, _ := this.GetInt64("id")
  360. err := service.DeleteProjectTeam(id)
  361. if err != nil {
  362. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  363. return
  364. }
  365. returnData := make(map[string]interface{}, 0)
  366. returnData["msg"] = "ok"
  367. this.ServeSuccessJSON(returnData)
  368. return
  369. }
  370. func (this *HisProjectApiController) SaveDePartment() {
  371. name := this.GetString("name")
  372. number := this.GetString("number")
  373. adminUserInfo := this.GetAdminUserInfo()
  374. orgId := adminUserInfo.CurrentOrgId
  375. department := models.XtHisDepartment{
  376. Name: name,
  377. Number: number,
  378. UserOrgId: orgId,
  379. CreatedTime: time.Now().Unix(),
  380. Status: 1,
  381. }
  382. err := service.CreateDePartment(&department)
  383. if err != nil {
  384. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  385. return
  386. }
  387. this.ServeSuccessJSON(map[string]interface{}{
  388. "department": department,
  389. })
  390. return
  391. }
  392. func (this *HisProjectApiController) GetDepartMentList() {
  393. limit, _ := this.GetInt64("limit")
  394. page, _ := this.GetInt64("page")
  395. adminUserInfo := this.GetAdminUserInfo()
  396. orgId := adminUserInfo.CurrentOrgId
  397. departMentList, total, err := service.GetDepartMentList(limit, page, orgId)
  398. if err != nil {
  399. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  400. return
  401. }
  402. this.ServeSuccessJSON(map[string]interface{}{
  403. "departMentList": departMentList,
  404. "total": total,
  405. })
  406. return
  407. }
  408. func (this *HisProjectApiController) GetDepartMentDetail() {
  409. id, _ := this.GetInt64("id")
  410. departDetail, err := service.GetDepartMentDetail(id)
  411. if err != nil {
  412. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  413. return
  414. }
  415. this.ServeSuccessJSON(map[string]interface{}{
  416. "departDetail": departDetail,
  417. })
  418. return
  419. }
  420. func (this *HisProjectApiController) UpdatedDeparment() {
  421. id, _ := this.GetInt64("id")
  422. name := this.GetString("name")
  423. number := this.GetString("number")
  424. department := models.XtHisDepartment{
  425. Name: name,
  426. Number: number,
  427. }
  428. err := service.UpdatedDepartment(id, &department)
  429. if err != nil {
  430. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  431. return
  432. }
  433. this.ServeSuccessJSON(map[string]interface{}{
  434. "department": department,
  435. })
  436. return
  437. }
  438. func (this *HisProjectApiController) DeleteDepartment() {
  439. id, _ := this.GetInt64("id")
  440. err := service.DeleteDepartment(id)
  441. if err != nil {
  442. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  443. return
  444. }
  445. returnData := make(map[string]interface{}, 0)
  446. returnData["msg"] = "ok"
  447. this.ServeSuccessJSON(returnData)
  448. return
  449. }
  450. func (this *HisProjectApiController) GetBloodPatientList() {
  451. adminUserInfo := this.GetAdminUserInfo()
  452. orgId := adminUserInfo.CurrentOrgId
  453. timeStr := time.Now().Format("2006-01-02")
  454. timeLayout := "2006-01-02 15:04:05"
  455. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  456. timenow := timeStringToTime.Unix()
  457. //统计血透排班的患者
  458. scheduleList, err := service.GetBloodPatientList(orgId, timenow)
  459. //统计当日挂号的患者
  460. hisPatient, _ := service.GetHisPatient(orgId, timenow)
  461. //统计今天开处方的患者
  462. prescription, _ := service.GetHisPrescriptionOther(orgId, timenow)
  463. if err != nil {
  464. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  465. return
  466. }
  467. this.ServeSuccessJSON(map[string]interface{}{
  468. "scheduleList": scheduleList,
  469. "hisPatient": hisPatient,
  470. "prescription": prescription,
  471. })
  472. return
  473. }
  474. func (this *HisProjectApiController) GetHisPrescription() {
  475. id, _ := this.GetInt64("id")
  476. timeStr := time.Now().Format("2006-01-02")
  477. timeLayout := "2006-01-02 15:04:05"
  478. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  479. timenow := timeStringToTime.Unix()
  480. prescriptionList, err := service.GetHisPrescriptionByPatientId(id, timenow)
  481. if err != nil {
  482. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  483. return
  484. }
  485. this.ServeSuccessJSON(map[string]interface{}{
  486. "prescriptionList": prescriptionList,
  487. })
  488. return
  489. }
  490. func (this *HisProjectApiController) AdditionalCharge() {
  491. dataBody := make(map[string]interface{}, 0)
  492. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  493. fmt.Println(err)
  494. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  495. patient_id := int64(dataBody["patient_id"].(float64))
  496. medicineData, _ := dataBody["medicineData"].([]interface{})
  497. adminUserInfo := this.GetAdminUserInfo()
  498. orgId := adminUserInfo.CurrentOrgId
  499. admin_user_id := adminUserInfo.AdminUser.Id
  500. timeStr := time.Now().Format("2006-01-02")
  501. timeLayout := "2006-01-02 15:04:05"
  502. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  503. timenow := timeStringToTime.Unix()
  504. for _, item := range medicineData {
  505. items := item.(map[string]interface{})
  506. //drug_id := int64(items["id"].(float64))
  507. money := items["money"].(string)
  508. moneys, _ := strconv.ParseInt(money, 10, 64)
  509. monStr := strconv.FormatInt(moneys, 10)
  510. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  511. additionalCharge := models.HisAdditionalCharge{
  512. HisPatientId: his_patient_id,
  513. UserOrgId: orgId,
  514. PatientId: patient_id,
  515. RecordDate: timenow,
  516. Price: monneyStr,
  517. Status: 1,
  518. AdminUserId: admin_user_id,
  519. CreatedTime: time.Now().Unix(),
  520. }
  521. err := service.CreateAdditionalCharge(&additionalCharge)
  522. if err != nil {
  523. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  524. return
  525. }
  526. this.ServeSuccessJSON(map[string]interface{}{
  527. "additionalCharge": additionalCharge,
  528. })
  529. return
  530. }
  531. }
  532. func (this *HisProjectApiController) GetTreatmentList() {
  533. patient_id, _ := this.GetInt64("patient_id")
  534. timeStr := time.Now().Format("2006-01-02")
  535. timeLayout := "2006-01-02 15:04:05"
  536. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  537. timenow := timeStringToTime.Unix()
  538. treatmentList, err := service.GetTreatmentList(patient_id, timenow)
  539. if err != nil {
  540. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  541. return
  542. }
  543. this.ServeSuccessJSON(map[string]interface{}{
  544. "treatmentList": treatmentList,
  545. })
  546. return
  547. }
  548. func (this *HisProjectApiController) GetAllProjectList() {
  549. adminUserInfo := this.GetAdminUserInfo()
  550. orgId := adminUserInfo.CurrentOrgId
  551. projectList, err := service.GetAllProjectList(orgId)
  552. //获取列表数据
  553. hisprojectlist, err := service.GetHisProjectListByOrgId(orgId)
  554. if err != nil {
  555. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  556. return
  557. }
  558. this.ServeSuccessJSON(map[string]interface{}{
  559. "projectList": projectList,
  560. "hisprojectlist": hisprojectlist,
  561. })
  562. return
  563. }
  564. func (this *HisProjectApiController) AddProjectList() {
  565. id, _ := this.GetInt64("id")
  566. number, _ := this.GetInt64("number")
  567. adminUserInfo := this.GetAdminUserInfo()
  568. orgId := adminUserInfo.CurrentOrgId
  569. projectList := models.XtHisProjectList{
  570. ProjectId: id,
  571. Number: number,
  572. UserOrgId: orgId,
  573. Status: 1,
  574. CreatedTime: time.Now().Unix(),
  575. }
  576. err := service.CreateProjectList(&projectList)
  577. if err != nil {
  578. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  579. return
  580. }
  581. this.ServeSuccessJSON(map[string]interface{}{
  582. "projectList": projectList,
  583. })
  584. return
  585. }
  586. func (this *HisProjectApiController) GetPatientInformation() {
  587. id, _ := this.GetInt64("id")
  588. information, err := service.GetHisPatientInformation(id)
  589. if err != nil {
  590. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  591. return
  592. }
  593. this.ServeSuccessJSON(map[string]interface{}{
  594. "information": information,
  595. })
  596. return
  597. }
  598. func (this *HisProjectApiController) DeleteProject() {
  599. id, _ := this.GetInt64("id")
  600. err := service.DeleteProjectList(id)
  601. if err != nil {
  602. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  603. return
  604. }
  605. returnData := make(map[string]interface{}, 0)
  606. returnData["msg"] = "ok"
  607. this.ServeSuccessJSON(returnData)
  608. return
  609. }
  610. func (this *HisProjectApiController) GetHisProject() {
  611. adminUserInfo := this.GetAdminUserInfo()
  612. orgId := adminUserInfo.CurrentOrgId
  613. project, err := service.GetHisProject(orgId)
  614. if err != nil {
  615. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  616. return
  617. }
  618. this.ServeSuccessJSON(map[string]interface{}{
  619. "project": project,
  620. })
  621. }
  622. func (this *HisProjectApiController) GetProjectTeam() {
  623. strids := this.GetString("strids")
  624. idStrs := strings.Split(strids, ",")
  625. adminUserInfo := this.GetAdminUserInfo()
  626. orgId := adminUserInfo.CurrentOrgId
  627. team, err := service.GetProjectTeam(idStrs, orgId)
  628. if err != nil {
  629. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  630. return
  631. }
  632. this.ServeSuccessJSON(map[string]interface{}{
  633. "team": team,
  634. })
  635. }
  636. func (this *HisProjectApiController) GetAllDoctorList() {
  637. adminUserInfo := this.GetAdminUserInfo()
  638. orgId := adminUserInfo.CurrentOrgId
  639. appId := adminUserInfo.CurrentAppId
  640. //获取所有的医生
  641. doctor, err := service.GetAllDoctor(orgId, appId)
  642. //获取所有的科室
  643. department, err := service.GetAllDepartMent(orgId)
  644. if err != nil {
  645. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  646. return
  647. }
  648. this.ServeSuccessJSON(map[string]interface{}{
  649. "doctor": doctor,
  650. "department": department,
  651. })
  652. }
  653. func (this *HisProjectApiController) SaveHisPatient() {
  654. timeLayout := "2006-01-02"
  655. loc, _ := time.LoadLocation("Local")
  656. age, _ := this.GetInt64("age")
  657. birthday := this.GetString("birthDay")
  658. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  659. birthUnix := birthdays.Unix()
  660. certificates, _ := this.GetInt64("certificates")
  661. cost_checked, _ := this.GetInt64("costChecked")
  662. cost, _ := this.GetInt64("cost")
  663. costs := strconv.FormatInt(cost, 10)
  664. cost_float, _ := strconv.ParseFloat(costs, 64)
  665. department, _ := this.GetInt64("department")
  666. doctor, _ := this.GetInt64("doctor")
  667. medicalcare, _ := this.GetInt64("medicalCare")
  668. idcard := this.GetString("idCard")
  669. medicalExpenses, _ := this.GetInt64("medicalExpenses")
  670. medicalExpense := strconv.FormatInt(medicalExpenses, 10)
  671. medicalExpense_float, _ := strconv.ParseFloat(medicalExpense, 64)
  672. medicalinsurancecard := this.GetString("medicalInsuranceCard")
  673. name := this.GetString("name")
  674. register, _ := this.GetInt64("register")
  675. registrationfee, _ := this.GetInt64("registrationFee")
  676. registrationfees := strconv.FormatInt(registrationfee, 10)
  677. registrationfees_float, _ := strconv.ParseFloat(registrationfees, 64)
  678. settlementValue, _ := this.GetInt64("settlementValue")
  679. sex, _ := this.GetInt64("sex")
  680. total, _ := this.GetInt64("total")
  681. totals := strconv.FormatInt(total, 10)
  682. totals_float, _ := strconv.ParseFloat(totals, 64)
  683. adminUserInfo := this.GetAdminUserInfo()
  684. orgId := adminUserInfo.CurrentOrgId
  685. recordDateStr := time.Now().Format("2006-01-02")
  686. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  687. nowtime := recordDate.Unix()
  688. bloodPatient, errcode := service.GetBloodPatientByIdCard(idcard, orgId)
  689. if errcode == gorm.ErrRecordNotFound {
  690. patient := models.XtHisPatient{
  691. Age: age,
  692. Birthday: birthUnix,
  693. IdType: certificates,
  694. CostOfProduction: cost_float,
  695. Departments: department,
  696. Doctor: doctor,
  697. AdminUserId: adminUserInfo.AdminUser.Id,
  698. MedicalTreatmentType: medicalcare,
  699. IdCardNo: idcard,
  700. IsNeedCostOfProduction: cost_checked,
  701. TreatmentCost: medicalExpense_float,
  702. MedicalInsuranceNumber: medicalinsurancecard,
  703. Name: name,
  704. RegisterType: register,
  705. RegisterCost: registrationfees_float,
  706. BalanceAccountsType: settlementValue,
  707. Gender: sex,
  708. Total: totals_float,
  709. UserOrgId: orgId,
  710. Status: 1,
  711. RecordDate: nowtime,
  712. IsReturn: 1,
  713. }
  714. err := service.CreateHisPatient(&patient)
  715. if err != nil {
  716. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  717. return
  718. }
  719. this.ServeSuccessJSON(map[string]interface{}{
  720. "patient": patient,
  721. })
  722. } else if errcode == nil {
  723. patient := models.XtHisPatient{
  724. Age: age,
  725. Birthday: birthUnix,
  726. IdType: certificates,
  727. CostOfProduction: cost_float,
  728. Departments: department,
  729. AdminUserId: doctor,
  730. MedicalTreatmentType: medicalcare,
  731. IdCardNo: idcard,
  732. IsNeedCostOfProduction: cost_checked,
  733. TreatmentCost: medicalExpense_float,
  734. MedicalInsuranceNumber: medicalinsurancecard,
  735. Name: name,
  736. RegisterType: register,
  737. RegisterCost: registrationfees_float,
  738. BalanceAccountsType: settlementValue,
  739. Gender: sex,
  740. Total: totals_float,
  741. UserOrgId: orgId,
  742. PatientId: bloodPatient.ID,
  743. }
  744. err := service.CreateHisPatient(&patient)
  745. if err != nil {
  746. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  747. return
  748. }
  749. this.ServeSuccessJSON(map[string]interface{}{
  750. "patient": patient,
  751. })
  752. }
  753. }
  754. func (this *HisProjectApiController) GetAllProjectTeam() {
  755. adminUserInfo := this.GetAdminUserInfo()
  756. orgId := adminUserInfo.CurrentOrgId
  757. team, err := service.GetAllProjectTeam(orgId)
  758. if err != nil {
  759. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  760. return
  761. }
  762. this.ServeSuccessJSON(map[string]interface{}{
  763. "team": team,
  764. })
  765. }
  766. func (this *HisProjectApiController) GetProjectListById() {
  767. adminUserInfo := this.GetAdminUserInfo()
  768. orgId := adminUserInfo.CurrentOrgId
  769. project_id := this.GetString("project_id")
  770. idStrs := strings.Split(project_id, ",")
  771. project, err := service.GetProjectListById(orgId, idStrs)
  772. if err != nil {
  773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  774. return
  775. }
  776. this.ServeSuccessJSON(map[string]interface{}{
  777. "project": project,
  778. })
  779. }
  780. func (this *HisProjectApiController) GetHisPatientHistory() {
  781. timeLayout := "2006-01-02"
  782. loc, _ := time.LoadLocation("Local")
  783. keyword := this.GetString("keyword")
  784. start_time := this.GetString("start_time")
  785. end_time := this.GetString("end_time")
  786. register_type, _ := this.GetInt64("register_type")
  787. limit, _ := this.GetInt64("limit")
  788. page, _ := this.GetInt64("page")
  789. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  790. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  791. adminUserInfo := this.GetAdminUserInfo()
  792. orgId := adminUserInfo.CurrentOrgId
  793. history, total, err := service.GetHisPatientHistory(keyword, startTime.Unix(), endTime.Unix(), register_type, limit, page, orgId)
  794. department, err := service.GetAllDepartMent(orgId)
  795. appId := adminUserInfo.CurrentAppId
  796. doctor, err := service.GetAllDoctor(orgId, appId)
  797. if err != nil {
  798. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  799. return
  800. }
  801. this.ServeSuccessJSON(map[string]interface{}{
  802. "history": history,
  803. "total": total,
  804. "department": department,
  805. "doctor": doctor,
  806. })
  807. }
  808. func (this *HisProjectApiController) ChangePatient() {
  809. id, _ := this.GetInt64("id")
  810. //查询该患者今日是否已经就诊
  811. recordDateStr := time.Now().Format("2006-01-02")
  812. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  813. nowtime := recordDate.Unix()
  814. adminUserInfo := this.GetAdminUserInfo()
  815. orgId := adminUserInfo.CurrentOrgId
  816. _, errcode := service.GetHisPrescriptionTwo(id, orgId, nowtime)
  817. if errcode == gorm.ErrRecordNotFound {
  818. err := service.ChangePatient(id)
  819. if err != nil {
  820. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  821. return
  822. }
  823. returnData := make(map[string]interface{}, 0)
  824. returnData["msg"] = "ok"
  825. this.ServeSuccessJSON(returnData)
  826. return
  827. } else if errcode == nil {
  828. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  829. return
  830. }
  831. }
  832. func (this *HisProjectApiController) GetPatientcaseHistory() {
  833. patient_id, _ := this.GetInt64("patient_id")
  834. patient, _ := service.GetBloodPatientInfoById(patient_id)
  835. history, err := service.GetPatientCaseHistory(patient_id)
  836. hispatient, _ := service.GetHisPatientById(patient_id)
  837. if err != nil {
  838. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  839. return
  840. }
  841. this.ServeSuccessJSON(map[string]interface{}{
  842. "patient": patient,
  843. "history": history,
  844. "hispatient": hispatient,
  845. })
  846. }
  847. func (this *HisProjectApiController) GetTemplateDetail() {
  848. id, _ := this.GetInt64("id")
  849. templateDetail, err := service.GetTemplateDetail(id)
  850. if err != nil {
  851. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  852. return
  853. }
  854. this.ServeSuccessJSON(map[string]interface{}{
  855. "templateDetail": templateDetail,
  856. })
  857. }
  858. func (this *HisProjectApiController) UpdateRecordTemplate() {
  859. id, _ := this.GetInt64("id")
  860. template_name := this.GetString("template_name")
  861. template_remark := this.GetString("template_remark")
  862. diagnostic := this.GetString("diagnostic")
  863. chief_conplaint := this.GetString("chief_conplaint")
  864. history_of_present_illness := this.GetString("history_of_present_illness")
  865. past_history := this.GetString("past_history")
  866. personal_history := this.GetString("personal_history")
  867. family_history := this.GetString("family_history")
  868. adminUserInfo := this.GetAdminUserInfo()
  869. creater := adminUserInfo.AdminUser.Id
  870. historyTemplate := models.HisCaseHistoryTemplate{
  871. HistoryOfPresentIllness: history_of_present_illness,
  872. PastHistory: past_history,
  873. ChiefConplaint: chief_conplaint,
  874. PersonalHistory: personal_history,
  875. FamilyHistory: family_history,
  876. Diagnostic: diagnostic,
  877. Status: 1,
  878. Mtime: time.Now().Unix(),
  879. RecordDate: time.Now().Unix(),
  880. TemplateName: template_name,
  881. TemplateRemark: template_remark,
  882. Modifier: creater,
  883. }
  884. err := service.UpdateCaseHistoryTemplate(&historyTemplate, id)
  885. if err != nil {
  886. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  887. return
  888. }
  889. this.ServeSuccessJSON(map[string]interface{}{
  890. "templateDetail": historyTemplate,
  891. })
  892. }
  893. func (this *HisProjectApiController) GetHisPatient() {
  894. adminUserInfo := this.GetAdminUserInfo()
  895. orgId := adminUserInfo.CurrentOrgId
  896. keyword := this.GetString("keyword")
  897. patient, err := service.GetHistPatient(orgId, keyword)
  898. if err != nil {
  899. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  900. return
  901. }
  902. this.ServeSuccessJSON(map[string]interface{}{
  903. "patient": patient,
  904. })
  905. }