his_api_controller.go 45KB

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