his_api_controller.go 38KB

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