his_project_api_controller.go 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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. }
  54. func (this *HisProjectApiController) SaveProject() {
  55. project_name := this.GetString("project_name")
  56. pinyin := this.GetString("pinyin")
  57. wubi := this.GetString("wubi")
  58. price := this.GetString("price")
  59. price_float, err := strconv.ParseFloat(price, 64)
  60. unit := this.GetString("unit")
  61. cost_classify, _ := this.GetInt64("cost_classify")
  62. executive_section, _ := this.GetInt64("executive_section")
  63. medical_coverage, _ := this.GetInt64("medical_coverage")
  64. statistical_classification, _ := this.GetInt64("statistical_classification")
  65. disease_directory, _ := this.GetInt64("disease_directory")
  66. is_record, _ := this.GetInt64("is_record")
  67. medical_code := this.GetString("medical_code")
  68. tube_color, _ := this.GetInt64("tube_color")
  69. medical_status, _ := this.GetInt64("medical_status")
  70. remark := this.GetString("remark")
  71. sign, _ := this.GetInt64("sign")
  72. default_number := this.GetString("default_number")
  73. is_charge, _ := this.GetInt64("is_charge")
  74. is_estimate, _ := this.GetInt64("is_estimate")
  75. is_workload, _ := this.GetInt64("is_workload")
  76. sort := this.GetString("sort")
  77. is_advice, _ := this.GetInt64("is_advice")
  78. is_default, _ := this.GetInt64("is_default")
  79. single_dose := this.GetString("single_dose")
  80. delivery_way := this.GetString("delivery_way")
  81. execution_frequency := this.GetString("execution_frequency")
  82. number_days := this.GetString("number_days")
  83. total := this.GetString("total")
  84. adminUserInfo := this.GetAdminUserInfo()
  85. orgId := adminUserInfo.CurrentOrgId
  86. hisProject := models.XtHisProject{
  87. ProjectName: project_name,
  88. Pinyin: pinyin,
  89. Wubi: wubi,
  90. Price: price_float,
  91. Unit: unit,
  92. CostClassify: cost_classify,
  93. ExecutiveSection: executive_section,
  94. MedicalCoverage: medical_coverage,
  95. StatisticalClassification: statistical_classification,
  96. DiseaseDirectory: disease_directory,
  97. IsRecord: is_record,
  98. MedicalCode: medical_code,
  99. TubeColor: tube_color,
  100. MedicalStatus: medical_status,
  101. Remark: remark,
  102. Sign: sign,
  103. DefaultNumber: default_number,
  104. IsCharge: is_charge,
  105. IsEstimate: is_estimate,
  106. IsWorkload: is_workload,
  107. Sort: sort,
  108. DoctorAdvice: is_advice,
  109. IsDefault: is_default,
  110. UserOrgId: orgId,
  111. Status: 1,
  112. CreatedTime: time.Now().Unix(),
  113. SingleDose: single_dose,
  114. DeliveryWay: delivery_way,
  115. ExecutionFrequency: execution_frequency,
  116. NumberDays: number_days,
  117. Total: total,
  118. }
  119. //查询项目名称是否存在
  120. _, errcode := service.GetHisProjectIsExist(project_name, orgId)
  121. fmt.Println("9999999999999", errcode)
  122. if errcode == gorm.ErrRecordNotFound {
  123. fmt.Println("222")
  124. err = service.CreateHisProject(&hisProject)
  125. if err != nil {
  126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  127. return
  128. }
  129. this.ServeSuccessJSON(map[string]interface{}{
  130. "hisProject": hisProject,
  131. })
  132. return
  133. } else if errcode == nil {
  134. fmt.Println("3333")
  135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  136. return
  137. }
  138. }
  139. func (this *HisProjectApiController) GetProjectList() {
  140. adminUserInfo := this.GetAdminUserInfo()
  141. orgId := adminUserInfo.CurrentOrgId
  142. limit, _ := this.GetInt64("limit")
  143. page, _ := this.GetInt64("page")
  144. is_charge, _ := this.GetInt64("is_charge")
  145. is_start, _ := this.GetInt64("is_start")
  146. keyword := this.GetString("keyword")
  147. projecList, total, err := service.GetHisProjectList(orgId, limit, page, is_charge, is_start, keyword)
  148. fmt.Println("err", err)
  149. if err != nil {
  150. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  151. return
  152. }
  153. this.ServeSuccessJSON(map[string]interface{}{
  154. "projecList": projecList,
  155. "total": total,
  156. })
  157. return
  158. }
  159. func (this *HisProjectApiController) GetProjectDetail() {
  160. id, _ := this.GetInt64("id")
  161. projectDetail, err := service.GetProjectDetail(id)
  162. if err != nil {
  163. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  164. return
  165. }
  166. this.ServeSuccessJSON(map[string]interface{}{
  167. "projecDetail": projectDetail,
  168. })
  169. return
  170. }
  171. func (this *HisProjectApiController) UpdatedProject() {
  172. id, _ := this.GetInt64("id")
  173. project_name := this.GetString("project_name")
  174. pinyin := this.GetString("pinyin")
  175. wubi := this.GetString("wubi")
  176. price := this.GetString("price")
  177. price_float, _ := strconv.ParseFloat(price, 64)
  178. unit := this.GetString("unit")
  179. cost_classify, _ := this.GetInt64("cost_classify")
  180. executive_section, _ := this.GetInt64("executive_section")
  181. medical_coverage, _ := this.GetInt64("medical_coverage")
  182. statistical_classification, _ := this.GetInt64("statistical_classification")
  183. disease_directory, _ := this.GetInt64("disease_directory")
  184. is_record, _ := this.GetInt64("is_record")
  185. medical_code := this.GetString("medical_code")
  186. tube_color, _ := this.GetInt64("tube_color")
  187. medical_status, _ := this.GetInt64("medical_status")
  188. remark := this.GetString("remark")
  189. sign, _ := this.GetInt64("sign")
  190. default_number := this.GetString("default_number")
  191. is_charge, _ := this.GetInt64("is_charge")
  192. is_estimate, _ := this.GetInt64("is_estimate")
  193. is_workload, _ := this.GetInt64("is_workload")
  194. sort := this.GetString("sort")
  195. is_advice, _ := this.GetInt64("is_advice")
  196. is_default, _ := this.GetInt64("is_default")
  197. single_dose := this.GetString("single_dose")
  198. delivery_way := this.GetString("delivery_way")
  199. execution_frequency := this.GetString("execution_frequency")
  200. number_days := this.GetString("number_days")
  201. total := this.GetString("total")
  202. hisProject := models.XtHisProject{
  203. ProjectName: project_name,
  204. Pinyin: pinyin,
  205. Wubi: wubi,
  206. Price: price_float,
  207. Unit: unit,
  208. CostClassify: cost_classify,
  209. ExecutiveSection: executive_section,
  210. MedicalCoverage: medical_coverage,
  211. StatisticalClassification: statistical_classification,
  212. DiseaseDirectory: disease_directory,
  213. IsRecord: is_record,
  214. MedicalCode: medical_code,
  215. TubeColor: tube_color,
  216. MedicalStatus: medical_status,
  217. Remark: remark,
  218. Sign: sign,
  219. DefaultNumber: default_number,
  220. IsCharge: is_charge,
  221. IsEstimate: is_estimate,
  222. IsWorkload: is_workload,
  223. Sort: sort,
  224. DoctorAdvice: is_advice,
  225. IsDefault: is_default,
  226. UpdatedTime: time.Now().Unix(),
  227. SingleDose: single_dose,
  228. DeliveryWay: delivery_way,
  229. ExecutionFrequency: execution_frequency,
  230. NumberDays: number_days,
  231. Total: total,
  232. }
  233. err := service.UpdatedProject(id, &hisProject)
  234. if err != nil {
  235. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  236. return
  237. }
  238. this.ServeSuccessJSON(map[string]interface{}{
  239. "hisProject": hisProject,
  240. })
  241. return
  242. }
  243. func (this *HisProjectApiController) DeleteHisProject() {
  244. id, _ := this.GetInt64("id")
  245. err := service.DeleteHisProject(id)
  246. if err != nil {
  247. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  248. return
  249. }
  250. returnData := make(map[string]interface{}, 0)
  251. returnData["msg"] = "ok"
  252. this.ServeSuccessJSON(returnData)
  253. return
  254. }
  255. func (this *HisProjectApiController) SaveProjectTeam() {
  256. project_team := this.GetString("project_team")
  257. price := this.GetString("price")
  258. price_float, _ := strconv.ParseFloat(price, 64)
  259. pinyin := this.GetString("pinyin")
  260. wubi := this.GetString("wubi")
  261. tube_color, _ := this.GetInt64("tube_color")
  262. team_type, _ := this.GetInt64("team_type")
  263. remark := this.GetString("remark")
  264. ids := this.GetString("ids")
  265. adminUserInfo := this.GetAdminUserInfo()
  266. orgId := adminUserInfo.CurrentOrgId
  267. projectTeam := models.XtHisProjectTeam{
  268. ProjectTeam: project_team,
  269. Price: price_float,
  270. Pinyin: pinyin,
  271. Wubi: wubi,
  272. TubeColor: tube_color,
  273. TeamType: team_type,
  274. Remark: remark,
  275. UserOrgId: orgId,
  276. Status: 1,
  277. CreatedTime: time.Now().Unix(),
  278. ProjectId: ids,
  279. }
  280. fmt.Println(projectTeam)
  281. _, errcodes := service.GetHisProjectByNameOne(project_team, orgId)
  282. if errcodes == gorm.ErrRecordNotFound {
  283. err := service.CreatedProjectTeam(&projectTeam)
  284. if err != nil {
  285. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  286. return
  287. }
  288. this.ServeSuccessJSON(map[string]interface{}{
  289. "projectTeam": projectTeam,
  290. })
  291. return
  292. } else if errcodes == nil {
  293. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  294. return
  295. }
  296. }
  297. func (this *HisProjectApiController) GetProjectTeamList() {
  298. limit, _ := this.GetInt64("limit")
  299. page, _ := this.GetInt64("page")
  300. keyword := this.GetString("keyword")
  301. adminUserInfo := this.GetAdminUserInfo()
  302. orgId := adminUserInfo.CurrentOrgId
  303. projectTeamList, total, err := service.GetProjectTeamList(limit, page, orgId, keyword)
  304. if err != nil {
  305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  306. return
  307. }
  308. this.ServeSuccessJSON(map[string]interface{}{
  309. "projectTeamList": projectTeamList,
  310. "total": total,
  311. })
  312. return
  313. }
  314. func (this *HisProjectApiController) GetProjectTeamDetail() {
  315. id, _ := this.GetInt64("id")
  316. projectTeamDetail, err := service.GetProjectTeamDetail(id)
  317. if err != nil {
  318. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  319. return
  320. }
  321. this.ServeSuccessJSON(map[string]interface{}{
  322. "projectTeamDetail": projectTeamDetail,
  323. })
  324. return
  325. }
  326. func (this *HisProjectApiController) UpdatedProjectTeam() {
  327. id, _ := this.GetInt64("id")
  328. project_team := this.GetString("project_team")
  329. price := this.GetString("price")
  330. price_float, _ := strconv.ParseFloat(price, 64)
  331. pinyin := this.GetString("pinyin")
  332. wubi := this.GetString("wubi")
  333. tube_color, _ := this.GetInt64("tube_color")
  334. team_type, _ := this.GetInt64("team_type")
  335. remark := this.GetString("remark")
  336. ids := this.GetString("ids")
  337. projectTeam := models.XtHisProjectTeam{
  338. ProjectTeam: project_team,
  339. Price: price_float,
  340. Pinyin: pinyin,
  341. Wubi: wubi,
  342. TubeColor: tube_color,
  343. TeamType: team_type,
  344. Remark: remark,
  345. ProjectId: ids,
  346. }
  347. err := service.UpdatedProjectTeam(id, &projectTeam)
  348. if err != nil {
  349. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  350. return
  351. }
  352. this.ServeSuccessJSON(map[string]interface{}{
  353. "projectTeam": projectTeam,
  354. })
  355. return
  356. }
  357. func (this *HisProjectApiController) DeleteProjectTeam() {
  358. id, _ := this.GetInt64("id")
  359. err := service.DeleteProjectTeam(id)
  360. if err != nil {
  361. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  362. return
  363. }
  364. returnData := make(map[string]interface{}, 0)
  365. returnData["msg"] = "ok"
  366. this.ServeSuccessJSON(returnData)
  367. return
  368. }
  369. func (this *HisProjectApiController) SaveDePartment() {
  370. name := this.GetString("name")
  371. number := this.GetString("number")
  372. adminUserInfo := this.GetAdminUserInfo()
  373. orgId := adminUserInfo.CurrentOrgId
  374. department := models.XtHisDepartment{
  375. Name: name,
  376. Number: number,
  377. UserOrgId: orgId,
  378. CreatedTime: time.Now().Unix(),
  379. Status: 1,
  380. }
  381. err := service.CreateDePartment(&department)
  382. if err != nil {
  383. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  384. return
  385. }
  386. this.ServeSuccessJSON(map[string]interface{}{
  387. "department": department,
  388. })
  389. return
  390. }
  391. func (this *HisProjectApiController) GetDepartMentList() {
  392. limit, _ := this.GetInt64("limit")
  393. page, _ := this.GetInt64("page")
  394. adminUserInfo := this.GetAdminUserInfo()
  395. orgId := adminUserInfo.CurrentOrgId
  396. departMentList, total, err := service.GetDepartMentList(limit, page, orgId)
  397. if err != nil {
  398. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  399. return
  400. }
  401. this.ServeSuccessJSON(map[string]interface{}{
  402. "departMentList": departMentList,
  403. "total": total,
  404. })
  405. return
  406. }
  407. func (this *HisProjectApiController) GetDepartMentDetail() {
  408. id, _ := this.GetInt64("id")
  409. departDetail, err := service.GetDepartMentDetail(id)
  410. if err != nil {
  411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  412. return
  413. }
  414. this.ServeSuccessJSON(map[string]interface{}{
  415. "departDetail": departDetail,
  416. })
  417. return
  418. }
  419. func (this *HisProjectApiController) UpdatedDeparment() {
  420. id, _ := this.GetInt64("id")
  421. name := this.GetString("name")
  422. number := this.GetString("number")
  423. department := models.XtHisDepartment{
  424. Name: name,
  425. Number: number,
  426. }
  427. err := service.UpdatedDepartment(id, &department)
  428. if err != nil {
  429. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  430. return
  431. }
  432. this.ServeSuccessJSON(map[string]interface{}{
  433. "department": department,
  434. })
  435. return
  436. }
  437. func (this *HisProjectApiController) DeleteDepartment() {
  438. id, _ := this.GetInt64("id")
  439. err := service.DeleteDepartment(id)
  440. if err != nil {
  441. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  442. return
  443. }
  444. returnData := make(map[string]interface{}, 0)
  445. returnData["msg"] = "ok"
  446. this.ServeSuccessJSON(returnData)
  447. return
  448. }
  449. func (this *HisProjectApiController) GetBloodPatientList() {
  450. adminUserInfo := this.GetAdminUserInfo()
  451. orgId := adminUserInfo.CurrentOrgId
  452. fmt.Println("org", orgId)
  453. timeStr := time.Now().Format("2006-01-02")
  454. timeLayout := "2006-01-02 15:04:05"
  455. fmt.Println("timeStr:", timeStr)
  456. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  457. timenow := timeStringToTime.Unix()
  458. //统计血透排班的患者
  459. scheduleList, err := service.GetBloodPatientList(orgId, timenow)
  460. //统计当日挂号的患者
  461. hisPatient, _ := service.GetHisPatient(orgId, timenow)
  462. //统计今天开处方的患者
  463. prescription, _ := service.GetHisPrescriptionOther(orgId, timenow)
  464. if err != nil {
  465. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  466. return
  467. }
  468. this.ServeSuccessJSON(map[string]interface{}{
  469. "scheduleList": scheduleList,
  470. "hisPatient": hisPatient,
  471. "prescription": prescription,
  472. })
  473. return
  474. }
  475. func (this *HisProjectApiController) GetHisPrescription() {
  476. id, _ := this.GetInt64("id")
  477. timeStr := time.Now().Format("2006-01-02")
  478. timeLayout := "2006-01-02 15:04:05"
  479. fmt.Println("timeStr:", timeStr)
  480. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  481. timenow := timeStringToTime.Unix()
  482. prescriptionList, err := service.GetHisPrescriptionByPatientId(id, timenow)
  483. if err != nil {
  484. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  485. return
  486. }
  487. this.ServeSuccessJSON(map[string]interface{}{
  488. "prescriptionList": prescriptionList,
  489. })
  490. return
  491. }
  492. func (this *HisProjectApiController) AdditionalCharge() {
  493. dataBody := make(map[string]interface{}, 0)
  494. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  495. fmt.Println(err)
  496. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  497. patient_id := int64(dataBody["patient_id"].(float64))
  498. fmt.Println("patient_id2222222222", patient_id)
  499. medicineData, _ := dataBody["medicineData"].([]interface{})
  500. adminUserInfo := this.GetAdminUserInfo()
  501. orgId := adminUserInfo.CurrentOrgId
  502. admin_user_id := adminUserInfo.AdminUser.Id
  503. timeStr := time.Now().Format("2006-01-02")
  504. timeLayout := "2006-01-02 15:04:05"
  505. fmt.Println("timeStr:", timeStr)
  506. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  507. timenow := timeStringToTime.Unix()
  508. for _, item := range medicineData {
  509. items := item.(map[string]interface{})
  510. //drug_id := int64(items["id"].(float64))
  511. money := items["money"].(string)
  512. moneys, _ := strconv.ParseInt(money, 10, 64)
  513. monStr := strconv.FormatInt(moneys, 10)
  514. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  515. additionalCharge := models.HisAdditionalCharge{
  516. HisPatientId: his_patient_id,
  517. UserOrgId: orgId,
  518. PatientId: patient_id,
  519. RecordDate: timenow,
  520. Price: monneyStr,
  521. Status: 1,
  522. AdminUserId: admin_user_id,
  523. CreatedTime: time.Now().Unix(),
  524. }
  525. err := service.CreateAdditionalCharge(&additionalCharge)
  526. if err != nil {
  527. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  528. return
  529. }
  530. this.ServeSuccessJSON(map[string]interface{}{
  531. "additionalCharge": additionalCharge,
  532. })
  533. return
  534. }
  535. }
  536. func (this *HisProjectApiController) GetTreatmentList() {
  537. patient_id, _ := this.GetInt64("patient_id")
  538. timeStr := time.Now().Format("2006-01-02")
  539. timeLayout := "2006-01-02 15:04:05"
  540. fmt.Println("timeStr:", timeStr)
  541. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  542. timenow := timeStringToTime.Unix()
  543. treatmentList, err := service.GetTreatmentList(patient_id, timenow)
  544. if err != nil {
  545. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  546. return
  547. }
  548. this.ServeSuccessJSON(map[string]interface{}{
  549. "treatmentList": treatmentList,
  550. })
  551. return
  552. }
  553. func (this *HisProjectApiController) GetAllProjectList() {
  554. adminUserInfo := this.GetAdminUserInfo()
  555. orgId := adminUserInfo.CurrentOrgId
  556. projectList, err := service.GetAllProjectList(orgId)
  557. //获取列表数据
  558. hisprojectlist, err := service.GetHisProjectListByOrgId(orgId)
  559. if err != nil {
  560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  561. return
  562. }
  563. this.ServeSuccessJSON(map[string]interface{}{
  564. "projectList": projectList,
  565. "hisprojectlist": hisprojectlist,
  566. })
  567. return
  568. }
  569. func (this *HisProjectApiController) AddProjectList() {
  570. id, _ := this.GetInt64("id")
  571. number, _ := this.GetInt64("number")
  572. adminUserInfo := this.GetAdminUserInfo()
  573. orgId := adminUserInfo.CurrentOrgId
  574. projectList := models.XtHisProjectList{
  575. ProjectId: id,
  576. Number: number,
  577. UserOrgId: orgId,
  578. Status: 1,
  579. CreatedTime: time.Now().Unix(),
  580. }
  581. err := service.CreateProjectList(&projectList)
  582. if err != nil {
  583. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  584. return
  585. }
  586. this.ServeSuccessJSON(map[string]interface{}{
  587. "projectList": projectList,
  588. })
  589. return
  590. }
  591. func (this *HisProjectApiController) GetPatientInformation() {
  592. id, _ := this.GetInt64("id")
  593. information, err := service.GetHisPatientInformation(id)
  594. if err != nil {
  595. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  596. return
  597. }
  598. this.ServeSuccessJSON(map[string]interface{}{
  599. "information": information,
  600. })
  601. return
  602. }
  603. func (this *HisProjectApiController) DeleteProject() {
  604. id, _ := this.GetInt64("id")
  605. err := service.DeleteProjectList(id)
  606. if err != nil {
  607. this.ServeFailJsonSend(enums.ErrorCodeDataException, "添加设备失败")
  608. return
  609. }
  610. returnData := make(map[string]interface{}, 0)
  611. returnData["msg"] = "ok"
  612. this.ServeSuccessJSON(returnData)
  613. return
  614. }
  615. func (this *HisProjectApiController) GetHisProject() {
  616. adminUserInfo := this.GetAdminUserInfo()
  617. orgId := adminUserInfo.CurrentOrgId
  618. project, err := service.GetHisProject(orgId)
  619. if err != nil {
  620. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  621. return
  622. }
  623. this.ServeSuccessJSON(map[string]interface{}{
  624. "project": project,
  625. })
  626. }
  627. func (this *HisProjectApiController) GetProjectTeam() {
  628. strids := this.GetString("strids")
  629. idStrs := strings.Split(strids, ",")
  630. adminUserInfo := this.GetAdminUserInfo()
  631. orgId := adminUserInfo.CurrentOrgId
  632. team, err := service.GetProjectTeam(idStrs, orgId)
  633. if err != nil {
  634. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  635. return
  636. }
  637. this.ServeSuccessJSON(map[string]interface{}{
  638. "team": team,
  639. })
  640. }
  641. func (this *HisProjectApiController) GetAllDoctorList() {
  642. adminUserInfo := this.GetAdminUserInfo()
  643. orgId := adminUserInfo.CurrentOrgId
  644. appId := adminUserInfo.CurrentAppId
  645. //获取所有的医生
  646. doctor, err := service.GetAllDoctor(orgId, appId)
  647. //获取所有的科室
  648. department, err := service.GetAllDepartMent(orgId)
  649. if err != nil {
  650. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  651. return
  652. }
  653. this.ServeSuccessJSON(map[string]interface{}{
  654. "doctor": doctor,
  655. "department": department,
  656. })
  657. }
  658. func (this *HisProjectApiController) SaveHisPatient() {
  659. timeLayout := "2006-01-02"
  660. loc, _ := time.LoadLocation("Local")
  661. age, _ := this.GetInt64("age")
  662. birthday := this.GetString("birthDay")
  663. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  664. birthUnix := birthdays.Unix()
  665. certificates, _ := this.GetInt64("certificates")
  666. cost_checked, _ := this.GetInt64("costChecked")
  667. cost, _ := this.GetInt64("cost")
  668. costs := strconv.FormatInt(cost, 10)
  669. cost_float, _ := strconv.ParseFloat(costs, 64)
  670. department, _ := this.GetInt64("department")
  671. doctor, _ := this.GetInt64("doctor")
  672. medicalcare, _ := this.GetInt64("medicalCare")
  673. idcard := this.GetString("idCard")
  674. medicalExpenses, _ := this.GetInt64("medicalExpenses")
  675. medicalExpense := strconv.FormatInt(medicalExpenses, 10)
  676. medicalExpense_float, _ := strconv.ParseFloat(medicalExpense, 64)
  677. medicalinsurancecard := this.GetString("medicalInsuranceCard")
  678. name := this.GetString("name")
  679. register, _ := this.GetInt64("register")
  680. registrationfee, _ := this.GetInt64("registrationFee")
  681. registrationfees := strconv.FormatInt(registrationfee, 10)
  682. registrationfees_float, _ := strconv.ParseFloat(registrationfees, 64)
  683. settlementValue, _ := this.GetInt64("settlementValue")
  684. sex, _ := this.GetInt64("sex")
  685. total, _ := this.GetInt64("total")
  686. totals := strconv.FormatInt(total, 10)
  687. totals_float, _ := strconv.ParseFloat(totals, 64)
  688. adminUserInfo := this.GetAdminUserInfo()
  689. orgId := adminUserInfo.CurrentOrgId
  690. bloodPatient, errcode := service.GetBloodPatientByIdCard(idcard, orgId)
  691. if errcode == gorm.ErrRecordNotFound {
  692. patient := models.XtHisPatient{
  693. Age: age,
  694. Birthday: birthUnix,
  695. IdType: certificates,
  696. CostOfProduction: cost_float,
  697. Departments: department,
  698. AdminUserId: doctor,
  699. MedicalTreatmentType: medicalcare,
  700. IdCardNo: idcard,
  701. IsNeedCostOfProduction: cost_checked,
  702. TreatmentCost: medicalExpense_float,
  703. MedicalInsuranceNumber: medicalinsurancecard,
  704. Name: name,
  705. RegisterType: register,
  706. RegisterCost: registrationfees_float,
  707. BalanceAccountsType: settlementValue,
  708. Gender: sex,
  709. Total: totals_float,
  710. UserOrgId: orgId,
  711. }
  712. err := service.CreateHisPatient(&patient)
  713. if err != nil {
  714. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  715. return
  716. }
  717. this.ServeSuccessJSON(map[string]interface{}{
  718. "patient": patient,
  719. })
  720. } else if errcode == nil {
  721. patient := models.XtHisPatient{
  722. Age: age,
  723. Birthday: birthUnix,
  724. IdType: certificates,
  725. CostOfProduction: cost_float,
  726. Departments: department,
  727. AdminUserId: doctor,
  728. MedicalTreatmentType: medicalcare,
  729. IdCardNo: idcard,
  730. IsNeedCostOfProduction: cost_checked,
  731. TreatmentCost: medicalExpense_float,
  732. MedicalInsuranceNumber: medicalinsurancecard,
  733. Name: name,
  734. RegisterType: register,
  735. RegisterCost: registrationfees_float,
  736. BalanceAccountsType: settlementValue,
  737. Gender: sex,
  738. Total: totals_float,
  739. UserOrgId: orgId,
  740. PatientId: bloodPatient.ID,
  741. }
  742. err := service.CreateHisPatient(&patient)
  743. if err != nil {
  744. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  745. return
  746. }
  747. this.ServeSuccessJSON(map[string]interface{}{
  748. "patient": patient,
  749. })
  750. }
  751. }
  752. func (this *HisProjectApiController) GetAllProjectTeam() {
  753. adminUserInfo := this.GetAdminUserInfo()
  754. orgId := adminUserInfo.CurrentOrgId
  755. fmt.Println("aaa")
  756. team, err := service.GetAllProjectTeam(orgId)
  757. if err != nil {
  758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  759. return
  760. }
  761. this.ServeSuccessJSON(map[string]interface{}{
  762. "team": team,
  763. })
  764. }
  765. func (this *HisProjectApiController) GetProjectListById() {
  766. adminUserInfo := this.GetAdminUserInfo()
  767. orgId := adminUserInfo.CurrentOrgId
  768. project_id := this.GetString("project_id")
  769. idStrs := strings.Split(project_id, ",")
  770. project, err := service.GetProjectListById(orgId, idStrs)
  771. if err != nil {
  772. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  773. return
  774. }
  775. this.ServeSuccessJSON(map[string]interface{}{
  776. "project": project,
  777. })
  778. }
  779. func (this *HisProjectApiController) GetHisPatientHistory() {
  780. timeLayout := "2006-01-02"
  781. loc, _ := time.LoadLocation("Local")
  782. keyword := this.GetString("keyword")
  783. start_time := this.GetString("start_time")
  784. end_time := this.GetString("end_time")
  785. register_type, _ := this.GetInt64("register_type")
  786. limit, _ := this.GetInt64("limit")
  787. page, _ := this.GetInt64("page")
  788. fmt.Println(keyword, start_time, end_time, register_type, limit, 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. history, total, err := service.GetHisPatientHistory(keyword, startTime.Unix(), endTime.Unix(), register_type, limit, page)
  792. if err != nil {
  793. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  794. return
  795. }
  796. this.ServeSuccessJSON(map[string]interface{}{
  797. "history": history,
  798. "total": total,
  799. })
  800. }