his_api_controller.go 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "bytes"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "io/ioutil"
  12. "math/rand"
  13. "net/http"
  14. "reflect"
  15. "strconv"
  16. "time"
  17. )
  18. type HisApiController struct {
  19. BaseAuthAPIController
  20. }
  21. func HisManagerApiRegistRouters() {
  22. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  23. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  24. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  25. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  26. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  27. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  28. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "post:CreateHisPatientCaseHistory")
  29. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "post:CreateCaseHistoryTemplate")
  30. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  31. beego.Router("/api/doctorworkstation/printcasehistory/get", &HisApiController{}, "get:GetPrintHisPatientCaseHistory")
  32. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  33. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  34. }
  35. func (c *HisApiController) GetHisPatientList() {
  36. types, _ := c.GetInt64("type", 0)
  37. record_date := c.GetString("record_date")
  38. timeLayout := "2006-01-02"
  39. loc, _ := time.LoadLocation("Local")
  40. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  41. if err != nil {
  42. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  43. return
  44. }
  45. recordDateTime := theTime.Unix()
  46. adminInfo := c.GetAdminUserInfo()
  47. patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  48. if types == 0 {
  49. c.ServeSuccessJSON(map[string]interface{}{
  50. "list": patients,
  51. })
  52. } else if types == 1 { //未就诊
  53. var patientsOne []*service.Schedule
  54. for _, item := range patients {
  55. if item.HisPrescription == nil || len(item.HisPrescription) <= 0 {
  56. patientsOne = append(patientsOne, item)
  57. }
  58. }
  59. c.ServeSuccessJSON(map[string]interface{}{
  60. "list": patientsOne,
  61. })
  62. } else if types == 2 { //已就诊
  63. var patientsTwo []*service.Schedule
  64. for _, item := range patients {
  65. if item.HisPrescription != nil && len(item.HisPrescription) > 0 {
  66. patientsTwo = append(patientsTwo, item)
  67. }
  68. }
  69. c.ServeSuccessJSON(map[string]interface{}{
  70. "list": patientsTwo,
  71. })
  72. }
  73. }
  74. func (c *HisApiController) GetHisPatientInfo() {
  75. patient_id, _ := c.GetInt64("patient_id")
  76. record_date := c.GetString("record_date")
  77. timeLayout := "2006-01-02"
  78. loc, _ := time.LoadLocation("Local")
  79. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  80. if err != nil {
  81. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  82. return
  83. }
  84. recordDateTime := theTime.Unix()
  85. admin := c.GetAdminUserInfo()
  86. his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  87. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  88. prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime)
  89. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  90. c.ServeSuccessJSON(map[string]interface{}{
  91. "his_info": his_patient_info,
  92. "xt_info": xt_patient_info,
  93. "prescription": prescriptions,
  94. "case_history": case_history,
  95. })
  96. return
  97. }
  98. func (c *HisApiController) GetHisPrescriptionConfig() {
  99. adminInfo := c.GetAdminUserInfo()
  100. //获取医嘱模版
  101. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  102. //获取所有基础药
  103. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  104. //drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  105. //drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  106. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  107. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  108. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  109. //获取所有科室信息
  110. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  111. c.ServeSuccessJSON(map[string]interface{}{
  112. "drugs": drugs,
  113. "advices_template": advices,
  114. "drugways": drugways,
  115. "efs": efs,
  116. "doctors": doctors,
  117. "department": department,
  118. })
  119. }
  120. func (c *HisApiController) CreateHisPrescription() {
  121. record_date := c.GetString("record_date")
  122. fmt.Println("record_date", record_date)
  123. patient_id, _ := c.GetInt64("patient_id")
  124. //diagnose := c.GetString("diagnose")
  125. //sick_history := c.GetString("sick_history")
  126. doctor, _ := c.GetInt64("doctor")
  127. //department, _ := c.GetInt64("department")
  128. his_patient_id, _ := c.GetInt64("his_patient_id")
  129. dataBody := make(map[string]interface{}, 0)
  130. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  131. if err != nil {
  132. utils.ErrorLog(err.Error())
  133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  134. return
  135. }
  136. timeLayout := "2006-01-02"
  137. loc, _ := time.LoadLocation("Local")
  138. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  139. if err != nil {
  140. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  141. return
  142. }
  143. adminInfo := c.GetAdminUserInfo()
  144. recordDateTime := theTime.Unix()
  145. //hpInfo := models.HisPrescriptionInfo{
  146. // UserOrgId: adminInfo.CurrentOrgId,
  147. // RecordDate: theTime.Unix(),
  148. // PatientId: patient_id,
  149. // Status: 1,
  150. // Ctime: time.Now().Unix(),
  151. // Mtime: time.Now().Unix(),
  152. // Creator: adminInfo.AdminUser.Id,
  153. // Modifier: adminInfo.AdminUser.Id,
  154. // Diagnosis: diagnose,
  155. // SickHistory: sick_history,
  156. // Departments:department,
  157. //
  158. //}
  159. //
  160. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  161. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  162. if len(prescriptions) > 0 {
  163. for _, item := range prescriptions {
  164. items := item.(map[string]interface{})
  165. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  166. utils.ErrorLog("type")
  167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. return
  169. }
  170. types := int64(items["type"].(float64))
  171. ctime := time.Now().Unix()
  172. prescription := &models.HisPrescription{
  173. PatientId: patient_id,
  174. UserOrgId: adminInfo.CurrentOrgId,
  175. RecordDate: recordDateTime,
  176. Ctime: ctime,
  177. Mtime: ctime,
  178. Type: types,
  179. Modifier: adminInfo.AdminUser.Id,
  180. Creator: adminInfo.AdminUser.Id,
  181. Status: 1,
  182. Doctor: doctor,
  183. HisPatientId: his_patient_id,
  184. }
  185. service.SaveHisPrescription(prescription)
  186. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  187. advices := items["advices"].([]interface{})
  188. group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  189. groupNo := group + 1
  190. ctime := time.Now().Unix()
  191. mtime := ctime
  192. if len(advices) > 0 {
  193. for _, advice := range advices {
  194. var s models.HisDoctorAdviceInfo
  195. s.PrescriptionId = prescription.ID
  196. s.AdviceType = 2
  197. s.AdviceDoctor = adminInfo.AdminUser.Id
  198. s.StopState = 2
  199. s.ExecutionState = 2
  200. s.AdviceDate = recordDateTime
  201. s.Status = 1
  202. s.UserOrgId = adminInfo.CurrentOrgId
  203. s.RecordDate = recordDateTime
  204. s.StartTime = recordDateTime
  205. s.Groupno = groupNo
  206. s.CreatedTime = ctime
  207. s.UpdatedTime = mtime
  208. s.PatientId = patient_id
  209. s.HisPatientId = his_patient_id
  210. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  211. if errcode > 0 {
  212. c.ServeFailJSONWithSGJErrorCode(errcode)
  213. return
  214. }
  215. service.CreateHisDoctorAdvice(&s)
  216. }
  217. }
  218. }
  219. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  220. projects := items["project"].([]interface{})
  221. if len(projects) > 0 {
  222. for _, project := range projects {
  223. var p models.HisPrescriptionProject
  224. p.PrescriptionId = prescription.ID
  225. p.Ctime = time.Now().Unix()
  226. p.Mtime = time.Now().Unix()
  227. p.PatientId = patient_id
  228. p.RecordDate = recordDateTime
  229. p.UserOrgId = adminInfo.CurrentOrgId
  230. p.HisPatientId = his_patient_id
  231. p.Status = 1
  232. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  233. if errcode > 0 {
  234. c.ServeFailJSONWithSGJErrorCode(errcode)
  235. return
  236. }
  237. service.CreateHisProjectTwo(&p)
  238. }
  239. }
  240. }
  241. }
  242. }
  243. //查询患者今日处方信息
  244. //_, errcode := service.GetHisPrescriptionTwo(his_patient_id, adminInfo.CurrentOrgId, recordDateTime)
  245. //if errcode == nil{
  246. // //改变患者信息状态
  247. // service.UpdatedHisPatient(his_patient_id, adminInfo.CurrentOrgId, recordDateTime)
  248. //
  249. //}
  250. }
  251. if err == nil {
  252. c.ServeSuccessJSON(map[string]interface{}{
  253. "msg": "保存成功",
  254. })
  255. return
  256. } else {
  257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  258. return
  259. }
  260. }
  261. func (c *HisApiController) CreateHisAdditionalCharge() {
  262. his_patient_id, _ := c.GetInt64("his_patient_id")
  263. patient_id, _ := c.GetInt64("patient_id")
  264. record_date := c.GetString("record_date")
  265. timeLayout := "2006-01-02"
  266. loc, _ := time.LoadLocation("Local")
  267. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  268. if err != nil {
  269. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  270. return
  271. }
  272. adminInfo := c.GetAdminUserInfo()
  273. recordDateTime := theTime.Unix()
  274. dataBody := make(map[string]interface{}, 0)
  275. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  276. if err != nil {
  277. utils.ErrorLog(err.Error())
  278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  279. return
  280. }
  281. var additions []*models.HisAdditionalCharge
  282. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  283. additions, _ := dataBody["addition"].([]interface{})
  284. if len(additions) > 0 {
  285. for _, item := range additions {
  286. items := item.(map[string]interface{})
  287. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  288. utils.ErrorLog("item_id")
  289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  290. return
  291. }
  292. item_id := int64(items["item_id"].(float64))
  293. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  294. utils.ErrorLog("item_name")
  295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  296. return
  297. }
  298. item_name := items["item_name"].(string)
  299. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  300. utils.ErrorLog("price")
  301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  302. return
  303. }
  304. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  305. ctime := time.Now().Unix()
  306. additional := &models.HisAdditionalCharge{
  307. PatientId: patient_id,
  308. HisPatientId: his_patient_id,
  309. UserOrgId: adminInfo.CurrentOrgId,
  310. RecordDate: recordDateTime,
  311. CreatedTime: ctime,
  312. UpdatedTime: ctime,
  313. Modifier: adminInfo.AdminUser.Id,
  314. Creator: adminInfo.AdminUser.Id,
  315. Price: price,
  316. ItemName: item_name,
  317. ItemId: item_id,
  318. Status: 1,
  319. }
  320. additions = append(additions, additional)
  321. }
  322. }
  323. }
  324. for _, item := range additions {
  325. service.CreateAddtionalCharge(item)
  326. }
  327. c.ServeSuccessJSON(map[string]interface{}{
  328. "msg": "创建成功",
  329. })
  330. }
  331. func (c *HisApiController) CreateHisPatientCaseHistory() {
  332. diagnostic := c.GetString("diagnostic")
  333. temperature, _ := c.GetFloat("temperature")
  334. blood_sugar, _ := c.GetFloat("blood_sugar")
  335. pulse, _ := c.GetFloat("pulse")
  336. sbp, _ := c.GetFloat("sbp")
  337. dbp, _ := c.GetFloat("dbp")
  338. blood_fat, _ := c.GetFloat("blood_fat")
  339. height, _ := c.GetFloat("height")
  340. sick_type, _ := c.GetInt64("sick_type")
  341. symptom := c.GetString("symptom")
  342. sick_date := c.GetString("sick_date")
  343. is_infect, _ := c.GetInt64("is_infect")
  344. chief_conplaint := c.GetString("chief_conplaint")
  345. history_of_present_illness := c.GetString("history_of_present_illness")
  346. past_history := c.GetString("past_history")
  347. personal_history := c.GetString("personal_history")
  348. family_history := c.GetString("family_history")
  349. record_date := c.GetString("record_date")
  350. patient_id, _ := c.GetInt64("patient_id")
  351. timeLayout := "2006-01-02"
  352. loc, _ := time.LoadLocation("Local")
  353. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  354. if err != nil {
  355. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  356. return
  357. }
  358. recordDateTime := theTime.Unix()
  359. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  360. if err != nil {
  361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  362. return
  363. }
  364. sickTimes := sickTime.Unix()
  365. ctime := time.Now().Unix()
  366. caseHistory := models.HisPatientCaseHistory{
  367. HisPatientId: patient_id,
  368. Temperature: temperature,
  369. BloodSugar: blood_sugar,
  370. Pulse: pulse,
  371. Sbp: sbp,
  372. Dbp: dbp,
  373. Height: height,
  374. BloodFat: blood_fat,
  375. SickType: sick_type,
  376. Symptom: symptom,
  377. SickDate: sickTimes,
  378. IsInfect: is_infect,
  379. HistoryOfPresentIllness: history_of_present_illness,
  380. PastHistory: past_history,
  381. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  382. ChiefConplaint: chief_conplaint,
  383. PersonalHistory: personal_history,
  384. FamilyHistory: family_history,
  385. Diagnostic: diagnostic,
  386. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  387. Status: 1,
  388. Ctime: ctime,
  389. Mtime: ctime,
  390. RecordDate: recordDateTime,
  391. }
  392. err = service.SaveHisPatientCaseHistory(caseHistory)
  393. if err != nil {
  394. c.ServeSuccessJSON(map[string]interface{}{
  395. "msg": "保存成功",
  396. })
  397. }
  398. }
  399. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  400. patient_id, _ := c.GetInt64("patient_id", 0)
  401. adminUser := c.GetAdminUserInfo()
  402. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  403. c.ServeSuccessJSON(map[string]interface{}{
  404. "list": caseHistorys,
  405. })
  406. }
  407. func (c *HisApiController) GetHisPatientCaseHistory() {
  408. record_date, _ := c.GetInt64("record_date", 0)
  409. patient_id, _ := c.GetInt64("patient_id", 0)
  410. admin := c.GetAdminUserInfo()
  411. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  412. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  413. c.ServeSuccessJSON(map[string]interface{}{
  414. "info": info,
  415. "case_history": case_history,
  416. })
  417. }
  418. func (c *HisApiController) CreateCaseHistoryTemplate() {
  419. template_name := c.GetString("template_name")
  420. template_remark := c.GetString("template_remark")
  421. doctor := c.GetAdminUserInfo().AdminUser.Id
  422. diagnostic := c.GetString("diagnostic")
  423. chief_conplaint := c.GetString("chief_conplaint")
  424. history_of_present_illness := c.GetString("history_of_present_illness")
  425. past_history := c.GetString("past_history")
  426. personal_history := c.GetString("personal_history")
  427. family_history := c.GetString("family_history")
  428. record_date := c.GetString("record_date")
  429. timeLayout := "2006-01-02"
  430. loc, _ := time.LoadLocation("Local")
  431. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  432. if err != nil {
  433. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  434. return
  435. }
  436. recordDateTime := theTime.Unix()
  437. ctime := time.Now().Unix()
  438. template := models.HisCaseHistoryTemplate{
  439. HistoryOfPresentIllness: history_of_present_illness,
  440. PastHistory: past_history,
  441. ChiefConplaint: chief_conplaint,
  442. PersonalHistory: personal_history,
  443. FamilyHistory: family_history,
  444. Diagnostic: diagnostic,
  445. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  446. Status: 1,
  447. Ctime: ctime,
  448. Mtime: ctime,
  449. RecordDate: recordDateTime,
  450. TemplateName: template_name,
  451. TemplateRemark: template_remark,
  452. Creator: doctor,
  453. Modifier: doctor,
  454. }
  455. err = service.SaveHisPatientCaseHistoryTemplate(template)
  456. if err == nil {
  457. c.ServeSuccessJSON(map[string]interface{}{
  458. "msg": "保存成功",
  459. })
  460. } else {
  461. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  462. return
  463. }
  464. }
  465. func (c *HisApiController) GetCaseHistoryTemplate() {
  466. admin := c.GetAdminUserInfo()
  467. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId)
  468. c.ServeSuccessJSON(map[string]interface{}{
  469. "template": template,
  470. })
  471. }
  472. type ResultTwo struct {
  473. ErrMsg interface{} `json:"err_msg"`
  474. InfRefmsgid string `json:"inf_refmsgid"`
  475. Infcode int64 `json:"infcode"`
  476. Output struct {
  477. Baseinfo struct {
  478. Age float64 `json:"age"`
  479. Brdy string `json:"brdy"`
  480. Certno string `json:"certno"`
  481. Gend string `json:"gend"`
  482. Naty string `json:"naty"`
  483. PsnCertType string `json:"psn_cert_type"`
  484. PsnName string `json:"psn_name"`
  485. PsnNo string `json:"psn_no"`
  486. } `json:"baseinfo"`
  487. Idetinfo []interface{} `json:"idetinfo"`
  488. Iinfo []struct {
  489. Balc int64 `json:"balc"`
  490. CvlservFlag string `json:"cvlserv_flag"`
  491. EmpName string `json:"emp_name"`
  492. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  493. Insutype string `json:"insutype"`
  494. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  495. PausInsuDate interface{} `json:"paus_insu_date"`
  496. PsnInsuDate string `json:"psn_insu_date"`
  497. PsnInsuStas string `json:"psn_insu_stas"`
  498. PsnType string `json:"psn_type"`
  499. } `json:"insuinfo"`
  500. } `json:"output"`
  501. RefmsgTime string `json:"refmsg_time"`
  502. RespondTime string `json:"respond_time"`
  503. Signtype interface{} `json:"signtype"`
  504. WarnInfo interface{} `json:"warn_info"`
  505. }
  506. type ResultThree struct {
  507. Cainfo interface{} `json:"cainfo"`
  508. ErrMsg interface{} `json:"err_msg"`
  509. InfRefmsgid string `json:"inf_refmsgid"`
  510. Infcode int64 `json:"infcode"`
  511. Output struct {
  512. Data struct {
  513. IptOtpNo string `json:"ipt_otp_no"`
  514. MdtrtID string `json:"mdtrt_id"`
  515. PsnNo string `json:"psn_no"`
  516. } `json:"data"`
  517. } `json:"output"`
  518. RefmsgTime string `json:"refmsg_time"`
  519. RespondTime string `json:"respond_time"`
  520. Signtype interface{} `json:"signtype"`
  521. WarnMsg interface{} `json:"warn_msg"`
  522. }
  523. func (c *HisApiController) GetRegisterInfo() {
  524. id, _ := c.GetInt64("id")
  525. record_time := c.GetString("record_time")
  526. adminInfo := c.GetAdminUserInfo()
  527. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  528. if patient == nil {
  529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  530. return
  531. }
  532. if len(patient.IdCardNo) == 0 {
  533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  534. return
  535. }
  536. timeLayout := "2006-01-02"
  537. loc, _ := time.LoadLocation("Local")
  538. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  539. if err != nil {
  540. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  541. return
  542. }
  543. api := "http://127.0.0.1:9531/" + "gdyb/one?cert_no=" + "44020219710324062X"
  544. resp, requestErr := http.Get(api)
  545. if requestErr != nil {
  546. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  547. return
  548. }
  549. defer resp.Body.Close()
  550. body, ioErr := ioutil.ReadAll(resp.Body)
  551. if ioErr != nil {
  552. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  554. return
  555. }
  556. var respJSON map[string]interface{}
  557. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  558. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  560. return
  561. }
  562. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  563. userJSONBytes, _ := json.Marshal(userJSON)
  564. var res ResultTwo
  565. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  566. utils.ErrorLog("解析失败:%v", err)
  567. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  568. return
  569. }
  570. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  571. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  572. infoStr := string(Iinfos)
  573. idetinfoStr := string(Idetinfos)
  574. his := models.VMHisPatient{
  575. PsnNo: res.Output.Baseinfo.PsnNo,
  576. PsnCertType: res.Output.Baseinfo.PsnCertType,
  577. Certno: res.Output.Baseinfo.Certno,
  578. PsnName: res.Output.Baseinfo.PsnName,
  579. Gend: res.Output.Baseinfo.Gend,
  580. Naty: res.Output.Baseinfo.Naty,
  581. Brdy: res.Output.Baseinfo.Brdy,
  582. Age: res.Output.Baseinfo.Age,
  583. Iinfo: infoStr,
  584. Idetinfo: idetinfoStr,
  585. PatientId: patient.ID,
  586. RecordDate: theTime.Unix(),
  587. }
  588. fmt.Println(his)
  589. if res.Output.Iinfo == nil || len(res.Output.Iinfo) == 0 {
  590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterOneException)
  591. return
  592. }
  593. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  594. if count <= 0 {
  595. api := "http://127.0.0.1:9531/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" + res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo
  596. resp, requestErr := http.Get(api)
  597. if requestErr != nil {
  598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  599. return
  600. }
  601. defer resp.Body.Close()
  602. body, ioErr := ioutil.ReadAll(resp.Body)
  603. if ioErr != nil {
  604. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  606. return
  607. }
  608. var respJSON map[string]interface{}
  609. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  610. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  612. return
  613. }
  614. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  615. userJSONBytes, _ := json.Marshal(respJSON)
  616. var res ResultThree
  617. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  618. utils.ErrorLog("解析失败:%v", err)
  619. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  620. return
  621. }
  622. if res.Infcode == -1 {
  623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  624. return
  625. }
  626. fmt.Println("000!!!!!!")
  627. fmt.Println(res)
  628. fmt.Println(res.Output.Data.MdtrtID)
  629. fmt.Println(res.Output.Data.PsnNo)
  630. fmt.Println(res.Output.Data.IptOtpNo)
  631. his.Number = res.Output.Data.MdtrtID
  632. his.PsnNo = res.Output.Data.PsnNo
  633. his.IptOtpNo = res.Output.Data.IptOtpNo
  634. his.IdCardNo = patient.IdCardNo
  635. his.PhoneNumber = patient.Phone
  636. his.UserOrgId = adminInfo.CurrentOrgId
  637. his.Status = 1
  638. his.Ctime = time.Now().Unix()
  639. his.Mtime = time.Now().Unix()
  640. err := service.CreateHisPatientTwo(&his)
  641. if err == nil {
  642. c.ServeSuccessJSON(map[string]interface{}{
  643. "his_info": his,
  644. })
  645. } else {
  646. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  647. return
  648. }
  649. }
  650. }
  651. func (c *HisApiController) GetPrintHisPatientCaseHistory() {
  652. }
  653. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  654. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  655. utils.ErrorLog("drug_name")
  656. return enums.ErrorCodeParamWrong
  657. }
  658. adviceName, _ := json["drug_name"].(string)
  659. if len(adviceName) == 0 {
  660. utils.ErrorLog("len(advice_name) == 0")
  661. return enums.ErrorCodeParamWrong
  662. }
  663. advice.AdviceName = adviceName
  664. adviceDesc, _ := json["advice_desc"].(string)
  665. advice.AdviceDesc = adviceDesc
  666. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  667. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  668. advice.DrugSpec = drugSpec
  669. }
  670. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  671. remark, _ := json["remark"].(string)
  672. advice.Remark = remark
  673. }
  674. if json["id"] == nil {
  675. advice.DrugId = 0
  676. } else {
  677. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  678. drug_id := int64(json["id"].(float64))
  679. advice.DrugId = drug_id
  680. }
  681. }
  682. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  683. drugSpecUnit, _ := json["min_unit"].(string)
  684. advice.DrugSpecUnit = drugSpecUnit
  685. }
  686. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  687. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  688. advice.SingleDose = singleDose
  689. }
  690. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  691. singleDoseUnit, _ := json["min_unit"].(string)
  692. advice.SingleDoseUnit = singleDoseUnit
  693. }
  694. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  695. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  696. advice.PrescribingNumber = prescribingNumber
  697. }
  698. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  699. prescribingNumberUnit, _ := json["min_unit"].(string)
  700. advice.PrescribingNumberUnit = prescribingNumberUnit
  701. }
  702. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  703. deliveryWay, _ := json["delivery_way"].(string)
  704. advice.DeliveryWay = deliveryWay
  705. }
  706. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  707. executionFrequency, _ := json["execution_frequency"].(string)
  708. advice.ExecutionFrequency = executionFrequency
  709. }
  710. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  711. remark, _ := json["remark"].(string)
  712. advice.Remark = remark
  713. }
  714. //if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  715. // advice.Price = json["retail_price"].(float64)
  716. //}
  717. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  718. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  719. advice.Price = price
  720. }
  721. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  722. med_list_codg, _ := json["medical_insurance_number"].(string)
  723. advice.MedListCodg = med_list_codg
  724. }
  725. return 0
  726. }
  727. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  728. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  729. project_id := int64(json["id"].(float64))
  730. project.ProjectId = project_id
  731. }
  732. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  733. price := int64(json["price"].(float64))
  734. formatInt_price := strconv.FormatInt(price, 10)
  735. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  736. project.Price = float_price
  737. }
  738. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  739. total, _ := json["total"].(string)
  740. totals, _ := strconv.ParseInt(total, 10, 64)
  741. project.Count = totals
  742. }
  743. return 0
  744. }
  745. type ResultFour struct {
  746. Cainfo string `json:"cainfo"`
  747. ErrMsg string `json:"err_msg"`
  748. InfRefmsgid string `json:"inf_refmsgid"`
  749. Infcode int64 `json:"infcode"`
  750. Output struct {
  751. Result []struct {
  752. BasMednFlag string `json:"bas_medn_flag"`
  753. ChldMedcFlag string `json:"chld_medc_flag"`
  754. ChrgitmLv string `json:"chrgitm_lv"`
  755. Cnt int64 `json:"cnt"`
  756. DetItemFeeSumamt int64 `json:"det_item_fee_sumamt"`
  757. DrtReimFlag string `json:"drt_reim_flag"`
  758. FeedetlSn string `json:"feedetl_sn"`
  759. FulamtOwnpayAmt int64 `json:"fulamt_ownpay_amt"`
  760. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  761. InscpScpAmt int64 `json:"inscp_scp_amt"`
  762. ListSpItemFlag string `json:"list_sp_item_flag"`
  763. LmtUsedFlag string `json:"lmt_used_flag"`
  764. MedChrgitmType string `json:"med_chrgitm_type"`
  765. Memo string `json:"memo"`
  766. OverlmtAmt int64 `json:"overlmt_amt"`
  767. PreselfpayAmt int64 `json:"preselfpay_amt"`
  768. Pric int64 `json:"pric"`
  769. PricUplmtAmt int64 `json:"pric_uplmt_amt"`
  770. SelfpayProp int64 `json:"selfpay_prop"`
  771. } `json:"result"`
  772. } `json:"output"`
  773. RefmsgTime string `json:"refmsg_time"`
  774. RespondTime string `json:"respond_time"`
  775. Signtype string `json:"signtype"`
  776. WarnMsg string `json:"warn_msg"`
  777. }
  778. type ResultFive struct {
  779. Insutype string `json:"insutype"`
  780. }
  781. func (c *HisApiController) GetUploadInfo() {
  782. id, _ := c.GetInt64("id")
  783. record_time := c.GetString("record_time")
  784. //record_date := c.GetString("record_date")
  785. timeLayout := "2006-01-02"
  786. loc, _ := time.LoadLocation("Local")
  787. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  788. if err != nil {
  789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  790. return
  791. }
  792. recordDateTime := theTime.Unix()
  793. adminUser := c.GetAdminUserInfo()
  794. prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  795. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  796. timestamp := time.Now().Unix()
  797. tempTime := time.Unix(timestamp, 0)
  798. timeFormat := tempTime.Format("20060102150405")
  799. chrgBchno := rand.Intn(100000) + 10000
  800. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10)
  801. client := &http.Client{}
  802. data := make(map[string]interface{})
  803. data["psn_no"] = his.PsnNo
  804. data["mdtrt_id"] = his.Number
  805. data["pre"] = prescriptions
  806. data["chrg_bchno"] = chrg_bchno
  807. bytesData, _ := json.Marshal(data)
  808. req, _ := http.NewRequest("POST", "http://127.0.0.1:9531/"+"gdyb/five", bytes.NewReader(bytesData))
  809. resp, _ := client.Do(req)
  810. defer resp.Body.Close()
  811. body, ioErr := ioutil.ReadAll(resp.Body)
  812. if ioErr != nil {
  813. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  814. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  815. return
  816. }
  817. var respJSON map[string]interface{}
  818. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  819. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  821. return
  822. }
  823. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  824. userJSONBytes, _ := json.Marshal(respJSON)
  825. var res ResultFour
  826. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  827. utils.ErrorLog("解析失败:%v", err)
  828. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  829. return
  830. }
  831. var total float64
  832. for _, item := range prescriptions {
  833. if item.Type == 1 { //药品
  834. for _, subItem := range item.HisDoctorAdviceInfo {
  835. total = total + (subItem.Price * subItem.PrescribingNumber)
  836. }
  837. }
  838. if item.Type == 2 { //项目
  839. for _, subItem := range item.HisPrescriptionProject {
  840. total = total + (subItem.Price * float64(subItem.Count))
  841. }
  842. }
  843. }
  844. allTotal := fmt.Sprintf("%.2f", total)
  845. fmt.Println(allTotal)
  846. if res.Infcode == 0 {
  847. var rf []*ResultFive
  848. json.Unmarshal([]byte(his.Iinfo), &rf)
  849. psn_no := his.PsnNo
  850. mdtrt_id := his.Number
  851. chrg_bchno := chrg_bchno
  852. cert_no := his.Certno
  853. insutype := rf[0].Insutype
  854. api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  855. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  856. "&total=" + allTotal
  857. resp, requestErr := http.Get(api)
  858. if requestErr != nil {
  859. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  860. return
  861. }
  862. defer resp.Body.Close()
  863. body, ioErr := ioutil.ReadAll(resp.Body)
  864. if ioErr != nil {
  865. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  867. return
  868. }
  869. var respJSON map[string]interface{}
  870. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  871. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  873. return
  874. }
  875. fmt.Println(respJSON)
  876. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  877. userJSONBytes, _ := json.Marshal(respJSON)
  878. var res ResultFour
  879. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  880. utils.ErrorLog("解析失败:%v", err)
  881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  882. return
  883. }
  884. } else {
  885. }
  886. }