his_api_controller.go 45KB

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