his_api_controller.go 38KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156
  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. fmt.Println(project_id)
  821. fmt.Println(project.ProjectId)
  822. }
  823. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  824. price := int64(json["price"].(float64))
  825. formatInt_price := strconv.FormatInt(price, 10)
  826. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  827. project.Price = float_price
  828. }
  829. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  830. total, _ := json["total"].(string)
  831. totals, _ := strconv.ParseInt(total, 10, 64)
  832. project.Count = totals
  833. }
  834. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  835. medical_code, _ := json["medical_code"].(string)
  836. project.MedListCodg = medical_code
  837. }
  838. return 0
  839. }
  840. type ResultFour struct {
  841. Cainfo string `json:"cainfo"`
  842. ErrMsg string `json:"err_msg"`
  843. InfRefmsgid string `json:"inf_refmsgid"`
  844. Infcode int64 `json:"infcode"`
  845. Output struct {
  846. Result []struct {
  847. BasMednFlag string `json:"bas_medn_flag"`
  848. ChldMedcFlag string `json:"chld_medc_flag"`
  849. ChrgitmLv string `json:"chrgitm_lv"`
  850. Cnt float64 `json:"cnt"`
  851. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  852. DrtReimFlag string `json:"drt_reim_flag"`
  853. FeedetlSn string `json:"feedetl_sn"`
  854. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  855. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  856. InscpScpAmt float64 `json:"inscp_scp_amt"`
  857. ListSpItemFlag string `json:"list_sp_item_flag"`
  858. LmtUsedFlag string `json:"lmt_used_flag"`
  859. MedChrgitmType string `json:"med_chrgitm_type"`
  860. Memo string `json:"memo"`
  861. OverlmtAmt float64 `json:"overlmt_amt"`
  862. PreselfpayAmt float64 `json:"preselfpay_amt"`
  863. Pric float64 `json:"pric"`
  864. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  865. SelfpayProp float64 `json:"selfpay_prop"`
  866. } `json:"result"`
  867. } `json:"output"`
  868. RefmsgTime string `json:"refmsg_time"`
  869. RespondTime string `json:"respond_time"`
  870. Signtype string `json:"signtype"`
  871. WarnMsg string `json:"warn_msg"`
  872. }
  873. type ResultFive struct {
  874. Insutype string `json:"insutype"`
  875. }
  876. func (c *HisApiController) GetUploadInfo() {
  877. id, _ := c.GetInt64("id")
  878. record_time := c.GetString("record_time")
  879. timeLayout := "2006-01-02"
  880. loc, _ := time.LoadLocation("Local")
  881. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  882. if err != nil {
  883. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  884. return
  885. }
  886. recordDateTime := theTime.Unix()
  887. adminUser := c.GetAdminUserInfo()
  888. prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  889. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  890. timestamp := time.Now().Unix()
  891. tempTime := time.Unix(timestamp, 0)
  892. timeFormat := tempTime.Format("20060102150405")
  893. chrgBchno := rand.Intn(100000) + 10000
  894. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  895. client := &http.Client{}
  896. data := make(map[string]interface{})
  897. data["psn_no"] = his.PsnNo
  898. data["mdtrt_id"] = his.Number
  899. data["pre"] = prescriptions
  900. data["chrg_bchno"] = chrg_bchno
  901. bytesData, _ := json.Marshal(data)
  902. req, _ := http.NewRequest("POST", "http://127.0.0.1:9531/"+"gdyb/five", bytes.NewReader(bytesData))
  903. resp, _ := client.Do(req)
  904. defer resp.Body.Close()
  905. body, ioErr := ioutil.ReadAll(resp.Body)
  906. if ioErr != nil {
  907. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  908. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  909. return
  910. }
  911. var respJSON map[string]interface{}
  912. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  913. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  915. return
  916. }
  917. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  918. userJSONBytes, _ := json.Marshal(respJSON)
  919. var res ResultFour
  920. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  921. utils.ErrorLog("解析失败:%v", err)
  922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  923. return
  924. }
  925. if res.Infcode == 0 {
  926. order := &models.HisOrder{
  927. UserOrgId: adminUser.CurrentOrgId,
  928. HisPatientId: his.ID,
  929. PatientId: his.PatientId,
  930. SettleAccountsDate: recordDateTime,
  931. Ctime: time.Now().Unix(),
  932. Mtime: time.Now().Unix(),
  933. Status: 1,
  934. Number: chrg_bchno,
  935. Infcode: res.Infcode,
  936. WarnMsg: res.WarnMsg,
  937. Cainfo: res.Cainfo,
  938. ErrMsg: res.ErrMsg,
  939. RespondTime: res.RefmsgTime,
  940. InfRefmsgid: res.InfRefmsgid,
  941. OrderStatus: 1,
  942. }
  943. err = service.CreateOrder(order)
  944. if err != nil {
  945. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  946. return
  947. }
  948. for _, item := range res.Output.Result {
  949. temp := strings.Split(item.FeedetlSn, "-")
  950. var advice_id int64 = 0
  951. var project_id int64 = 0
  952. var types int64 = 0
  953. id, _ := strconv.ParseInt(temp[2], 10, 64)
  954. types, _ = strconv.ParseInt(temp[1], 10, 64)
  955. if temp[1] == "1" {
  956. advice_id = id
  957. project_id = 0
  958. } else if temp[1] == "2" {
  959. advice_id = 0
  960. project_id = id
  961. }
  962. info := &models.HisOrderInfo{
  963. OrderNumber: order.Number,
  964. FeedetlSn: item.FeedetlSn,
  965. UploadDate: time.Now().Unix(),
  966. AdviceId: advice_id,
  967. DetItemFeeSumamt: item.DetItemFeeSumamt,
  968. Cnt: item.Cnt,
  969. Pric: float64(item.Pric),
  970. PatientId: his.PatientId,
  971. PricUplmtAmt: item.PricUplmtAmt,
  972. SelfpayProp: item.SelfpayProp,
  973. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  974. OverlmtAmt: item.OverlmtAmt,
  975. PreselfpayAmt: item.PreselfpayAmt,
  976. BasMednFlag: item.BasMednFlag,
  977. MedChrgitmType: item.MedChrgitmType,
  978. HiNegoDrugFlag: item.HiNegoDrugFlag,
  979. Status: 1,
  980. Memo: item.Memo,
  981. Mtime: time.Now().Unix(),
  982. InscpScpAmt: item.InscpScpAmt,
  983. DrtReimFlag: item.DrtReimFlag,
  984. Ctime: time.Now().Unix(),
  985. ListSpItemFlag: item.ListSpItemFlag,
  986. ChldMedcFlag: item.ChldMedcFlag,
  987. LmtUsedFlag: item.LmtUsedFlag,
  988. ChrgitmLv: item.ChrgitmLv,
  989. UserOrgId: adminUser.CurrentOrgId,
  990. HisPatientId: his.ID,
  991. OrderId: order.ID,
  992. ProjectId: project_id,
  993. Type: types,
  994. }
  995. service.CreateOrderInfo(info)
  996. }
  997. var total float64
  998. for _, item := range prescriptions {
  999. if item.Type == 1 { //药品
  1000. for _, subItem := range item.HisDoctorAdviceInfo {
  1001. total = total + (subItem.Price * subItem.PrescribingNumber)
  1002. }
  1003. }
  1004. if item.Type == 2 { //项目
  1005. for _, subItem := range item.HisPrescriptionProject {
  1006. total = total + (subItem.Price * float64(subItem.Count))
  1007. }
  1008. }
  1009. }
  1010. allTotal := fmt.Sprintf("%.2f", total)
  1011. if res.Infcode == 0 {
  1012. var rf []*ResultFive
  1013. json.Unmarshal([]byte(his.Iinfo), &rf)
  1014. psn_no := his.PsnNo
  1015. mdtrt_id := his.Number
  1016. chrg_bchno := chrg_bchno
  1017. cert_no := his.Certno
  1018. insutype := rf[0].Insutype
  1019. api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1020. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1021. "&total=" + allTotal
  1022. resp, requestErr := http.Get(api)
  1023. if requestErr != nil {
  1024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1025. return
  1026. }
  1027. defer resp.Body.Close()
  1028. body, ioErr := ioutil.ReadAll(resp.Body)
  1029. if ioErr != nil {
  1030. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1031. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1032. return
  1033. }
  1034. var respJSON map[string]interface{}
  1035. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1036. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1038. return
  1039. }
  1040. fmt.Println(respJSON)
  1041. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1042. userJSONBytes, _ := json.Marshal(respJSON)
  1043. var res ResultFour
  1044. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1045. utils.ErrorLog("解析失败:%v", err)
  1046. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1047. return
  1048. }
  1049. } else {
  1050. }
  1051. } else {
  1052. c.ServeSuccessJSON(map[string]interface{}{
  1053. "msg": res.ErrMsg,
  1054. })
  1055. }
  1056. }