his_api_controller.go 42KB

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