his_api_controller.go 46KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  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. fmt.Println("recordDataTime", recordDateTime)
  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. err = service.SaveHisPatientCaseHistory(&caseHistory)
  517. if err != nil {
  518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  519. return
  520. }
  521. c.ServeSuccessJSON(map[string]interface{}{
  522. "caseHistory": caseHistory,
  523. })
  524. return
  525. //查询该患者是否有病历
  526. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  527. //if errcode == gorm.ErrRecordNotFound {
  528. // err = service.SaveHisPatientCaseHistory(caseHistory)
  529. // if err != nil {
  530. // c.ServeSuccessJSON(map[string]interface{}{
  531. // "msg": "保存成功",
  532. // })
  533. // }
  534. //} else if errcode == nil {
  535. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  536. // return
  537. //}
  538. }
  539. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  540. patient_id, _ := c.GetInt64("patient_id", 0)
  541. adminUser := c.GetAdminUserInfo()
  542. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  543. c.ServeSuccessJSON(map[string]interface{}{
  544. "list": caseHistorys,
  545. })
  546. }
  547. func (c *HisApiController) GetHisPatientCaseHistory() {
  548. record_date, _ := c.GetInt64("record_date", 0)
  549. patient_id, _ := c.GetInt64("patient_id", 0)
  550. admin := c.GetAdminUserInfo()
  551. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  552. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  553. c.ServeSuccessJSON(map[string]interface{}{
  554. "info": info,
  555. "case_history": case_history,
  556. })
  557. }
  558. func (c *HisApiController) CreateCaseHistoryTemplate() {
  559. template_name := c.GetString("template_name")
  560. fmt.Println("template_name22222222222222", template_name)
  561. template_remark := c.GetString("template_remark")
  562. doctor := c.GetAdminUserInfo().AdminUser.Id
  563. diagnostic := c.GetString("diagnostic")
  564. chief_conplaint := c.GetString("chief_conplain")
  565. history_of_present_illness := c.GetString("history_of_present_illness")
  566. past_history := c.GetString("past_history")
  567. personal_history := c.GetString("personal_history")
  568. family_history := c.GetString("family_history")
  569. user_name := c.GetString("user_name")
  570. //record_date := c.GetString("record_date")
  571. //fmt.Println("record_date--------",record_date)
  572. //timeLayout := "2006-01-02"
  573. //loc, _ := time.LoadLocation("Local")
  574. //
  575. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  576. //if err != nil {
  577. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  578. // return
  579. //}
  580. //recordDateTime := theTime.Unix()
  581. ctime := time.Now().Unix()
  582. template := models.HisCaseHistoryTemplate{
  583. HistoryOfPresentIllness: history_of_present_illness,
  584. PastHistory: past_history,
  585. ChiefConplaint: chief_conplaint,
  586. PersonalHistory: personal_history,
  587. FamilyHistory: family_history,
  588. Diagnostic: diagnostic,
  589. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  590. Status: 1,
  591. Ctime: ctime,
  592. Mtime: ctime,
  593. RecordDate: time.Now().Unix(),
  594. TemplateName: template_name,
  595. TemplateRemark: template_remark,
  596. Creator: doctor,
  597. Modifier: doctor,
  598. UserName: user_name,
  599. }
  600. err := service.SaveHisPatientCaseHistoryTemplate(template)
  601. if err == nil {
  602. c.ServeSuccessJSON(map[string]interface{}{
  603. "msg": "保存成功",
  604. })
  605. } else {
  606. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  607. return
  608. }
  609. }
  610. func (c *HisApiController) GetCaseHistoryTemplate() {
  611. timeLayout := "2006-01-02"
  612. loc, _ := time.LoadLocation("Local")
  613. keyword := c.GetString("keyword")
  614. start_time := c.GetString("start_time")
  615. end_time := c.GetString("end_time")
  616. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  617. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  618. admin := c.GetAdminUserInfo()
  619. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  620. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  621. c.ServeSuccessJSON(map[string]interface{}{
  622. "template": template,
  623. //"history": history,
  624. })
  625. }
  626. type ResultTwo struct {
  627. ErrMsg interface{} `json:"err_msg"`
  628. InfRefmsgid string `json:"inf_refmsgid"`
  629. Infcode int64 `json:"infcode"`
  630. Output struct {
  631. Baseinfo struct {
  632. Age float64 `json:"age"`
  633. Brdy string `json:"brdy"`
  634. Certno string `json:"certno"`
  635. Gend string `json:"gend"`
  636. Naty string `json:"naty"`
  637. PsnCertType string `json:"psn_cert_type"`
  638. PsnName string `json:"psn_name"`
  639. PsnNo string `json:"psn_no"`
  640. } `json:"baseinfo"`
  641. Idetinfo []interface{} `json:"idetinfo"`
  642. Iinfo []struct {
  643. Balc int64 `json:"balc"`
  644. CvlservFlag string `json:"cvlserv_flag"`
  645. EmpName string `json:"emp_name"`
  646. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  647. Insutype string `json:"insutype"`
  648. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  649. PausInsuDate interface{} `json:"paus_insu_date"`
  650. PsnInsuDate string `json:"psn_insu_date"`
  651. PsnInsuStas string `json:"psn_insu_stas"`
  652. PsnType string `json:"psn_type"`
  653. } `json:"insuinfo"`
  654. } `json:"output"`
  655. RefmsgTime string `json:"refmsg_time"`
  656. RespondTime string `json:"respond_time"`
  657. Signtype interface{} `json:"signtype"`
  658. WarnInfo interface{} `json:"warn_info"`
  659. }
  660. type ResultThree struct {
  661. Cainfo interface{} `json:"cainfo"`
  662. ErrMsg interface{} `json:"err_msg"`
  663. InfRefmsgid string `json:"inf_refmsgid"`
  664. Infcode int64 `json:"infcode"`
  665. Output struct {
  666. Data struct {
  667. IptOtpNo string `json:"ipt_otp_no"`
  668. MdtrtID string `json:"mdtrt_id"`
  669. PsnNo string `json:"psn_no"`
  670. } `json:"data"`
  671. } `json:"output"`
  672. RefmsgTime string `json:"refmsg_time"`
  673. RespondTime string `json:"respond_time"`
  674. Signtype interface{} `json:"signtype"`
  675. WarnMsg interface{} `json:"warn_msg"`
  676. }
  677. func (c *HisApiController) GetRegisterInfo() {
  678. id, _ := c.GetInt64("id")
  679. record_time := c.GetString("record_time")
  680. timeLayout := "2006-01-02"
  681. loc, _ := time.LoadLocation("Local")
  682. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  683. if err != nil {
  684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  685. return
  686. }
  687. recordDateTime := theTime.Unix()
  688. adminInfo := c.GetAdminUserInfo()
  689. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  690. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  691. if patient == nil {
  692. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  693. return
  694. }
  695. if len(patient.IdCardNo) == 0 {
  696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  697. return
  698. }
  699. org, _ := service.GetOrgById(adminInfo.CurrentOrgId)
  700. api := "http://127.0.0.1:9531/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + org.OrgName + "&doctor=" + patientPrescription.Doctor
  701. resp, requestErr := http.Get(api)
  702. if requestErr != nil {
  703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  704. return
  705. }
  706. defer resp.Body.Close()
  707. body, ioErr := ioutil.ReadAll(resp.Body)
  708. if ioErr != nil {
  709. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  711. return
  712. }
  713. var respJSON map[string]interface{}
  714. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  715. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  716. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  717. return
  718. }
  719. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  720. userJSONBytes, _ := json.Marshal(userJSON)
  721. var res ResultTwo
  722. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  723. utils.ErrorLog("解析失败:%v", err)
  724. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  725. return
  726. }
  727. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  728. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  729. infoStr := string(Iinfos)
  730. idetinfoStr := string(Idetinfos)
  731. his := models.VMHisPatient{
  732. PsnNo: res.Output.Baseinfo.PsnNo,
  733. PsnCertType: res.Output.Baseinfo.PsnCertType,
  734. Certno: res.Output.Baseinfo.Certno,
  735. PsnName: res.Output.Baseinfo.PsnName,
  736. Gend: res.Output.Baseinfo.Gend,
  737. Naty: res.Output.Baseinfo.Naty,
  738. Brdy: res.Output.Baseinfo.Brdy,
  739. Age: res.Output.Baseinfo.Age,
  740. Iinfo: infoStr,
  741. Idetinfo: idetinfoStr,
  742. PatientId: patient.ID,
  743. RecordDate: theTime.Unix(),
  744. }
  745. fmt.Println(his)
  746. if res.Output.Iinfo == nil || len(res.Output.Iinfo) == 0 {
  747. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterOneException)
  748. return
  749. }
  750. timestamp := time.Now().Unix()
  751. tempTime := time.Unix(timestamp, 0)
  752. timeFormat := tempTime.Format("20060102150405")
  753. chrgBchno := rand.Intn(100000) + 10000
  754. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  755. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  756. if count <= 0 {
  757. api := "http://127.0.0.1:9531/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  758. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  759. "&org_name=" + org.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  760. "&dept=" + patientPrescription.Departments
  761. resp, requestErr := http.Get(api)
  762. if requestErr != nil {
  763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  764. return
  765. }
  766. defer resp.Body.Close()
  767. body, ioErr := ioutil.ReadAll(resp.Body)
  768. if ioErr != nil {
  769. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  771. return
  772. }
  773. var respJSON map[string]interface{}
  774. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  775. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  777. return
  778. }
  779. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  780. userJSONBytes, _ := json.Marshal(respJSON)
  781. var res ResultThree
  782. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  783. utils.ErrorLog("解析失败:%v", err)
  784. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  785. return
  786. }
  787. if res.Infcode == -1 {
  788. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  789. return
  790. }
  791. fmt.Println("000!!!!!!")
  792. fmt.Println(res)
  793. fmt.Println(res.Output.Data.MdtrtID)
  794. fmt.Println(res.Output.Data.PsnNo)
  795. fmt.Println(res.Output.Data.IptOtpNo)
  796. his.Number = res.Output.Data.MdtrtID
  797. his.PsnNo = res.Output.Data.PsnNo
  798. his.IptOtpNo = res.Output.Data.IptOtpNo
  799. his.IdCardNo = patient.IdCardNo
  800. his.PhoneNumber = patient.Phone
  801. his.UserOrgId = adminInfo.CurrentOrgId
  802. his.Status = 1
  803. his.Ctime = time.Now().Unix()
  804. his.Mtime = time.Now().Unix()
  805. err := service.CreateHisPatientTwo(&his)
  806. if err == nil {
  807. c.ServeSuccessJSON(map[string]interface{}{
  808. "his_info": his,
  809. })
  810. } else {
  811. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  812. return
  813. }
  814. }
  815. }
  816. //func (c *HisApiController) GetPrintHisPatientCaseHistory() {
  817. //
  818. //}
  819. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  820. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  821. utils.ErrorLog("drug_name")
  822. return enums.ErrorCodeParamWrong
  823. }
  824. adviceName, _ := json["drug_name"].(string)
  825. if len(adviceName) == 0 {
  826. utils.ErrorLog("len(advice_name) == 0")
  827. return enums.ErrorCodeParamWrong
  828. }
  829. advice.AdviceName = adviceName
  830. adviceDesc, _ := json["advice_desc"].(string)
  831. advice.AdviceDesc = adviceDesc
  832. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  833. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  834. advice.DrugSpec = drugSpec
  835. }
  836. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  837. remark, _ := json["remark"].(string)
  838. advice.Remark = remark
  839. }
  840. if json["id"] == nil {
  841. advice.DrugId = 0
  842. } else {
  843. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  844. drug_id := int64(json["id"].(float64))
  845. advice.DrugId = drug_id
  846. }
  847. }
  848. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  849. advice_id := int64(json["advice_id"].(float64))
  850. advice.ID = advice_id
  851. }
  852. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  853. drugSpecUnit, _ := json["min_unit"].(string)
  854. advice.DrugSpecUnit = drugSpecUnit
  855. }
  856. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  857. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  858. advice.SingleDose = singleDose
  859. }
  860. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  861. singleDoseUnit, _ := json["min_unit"].(string)
  862. advice.SingleDoseUnit = singleDoseUnit
  863. }
  864. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  865. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  866. advice.PrescribingNumber = prescribingNumber
  867. }
  868. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  869. prescribingNumberUnit, _ := json["min_unit"].(string)
  870. advice.PrescribingNumberUnit = prescribingNumberUnit
  871. }
  872. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  873. deliveryWay, _ := json["delivery_way"].(string)
  874. advice.DeliveryWay = deliveryWay
  875. }
  876. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  877. executionFrequency, _ := json["execution_frequency"].(string)
  878. advice.ExecutionFrequency = executionFrequency
  879. }
  880. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  881. remark, _ := json["remark"].(string)
  882. advice.Remark = remark
  883. }
  884. //if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  885. // advice.Price = json["retail_price"].(float64)
  886. //}
  887. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  888. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  889. advice.Price = price
  890. }
  891. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  892. med_list_codg, _ := json["medical_insurance_number"].(string)
  893. advice.MedListCodg = med_list_codg
  894. }
  895. return 0
  896. }
  897. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  898. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  899. id := int64(json["id"].(float64))
  900. project.ID = id
  901. }
  902. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  903. project_id := int64(json["project_id"].(float64))
  904. project.ProjectId = project_id
  905. fmt.Println(project_id)
  906. fmt.Println(project.ProjectId)
  907. }
  908. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  909. price := int64(json["price"].(float64))
  910. formatInt_price := strconv.FormatInt(price, 10)
  911. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  912. project.Price = float_price
  913. }
  914. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  915. total, _ := json["total"].(string)
  916. totals, _ := strconv.ParseInt(total, 10, 64)
  917. project.Count = totals
  918. }
  919. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  920. medical_code, _ := json["medical_code"].(string)
  921. project.MedListCodg = medical_code
  922. }
  923. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  924. single_dose, _ := json["single_dose"].(string)
  925. project.SingleDose = single_dose
  926. }
  927. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  928. delivery_way, _ := json["delivery_way"].(string)
  929. project.DeliveryWay = delivery_way
  930. }
  931. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  932. execution_frequency, _ := json["execution_frequency"].(string)
  933. project.ExecutionFrequency = execution_frequency
  934. }
  935. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  936. day, _ := json["number_days"].(string)
  937. project.Day = day
  938. }
  939. return 0
  940. }
  941. type ResultFour struct {
  942. Cainfo string `json:"cainfo"`
  943. ErrMsg string `json:"err_msg"`
  944. InfRefmsgid string `json:"inf_refmsgid"`
  945. Infcode int64 `json:"infcode"`
  946. Output struct {
  947. Result []struct {
  948. BasMednFlag string `json:"bas_medn_flag"`
  949. ChldMedcFlag string `json:"chld_medc_flag"`
  950. ChrgitmLv string `json:"chrgitm_lv"`
  951. Cnt float64 `json:"cnt"`
  952. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  953. DrtReimFlag string `json:"drt_reim_flag"`
  954. FeedetlSn string `json:"feedetl_sn"`
  955. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  956. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  957. InscpScpAmt float64 `json:"inscp_scp_amt"`
  958. ListSpItemFlag string `json:"list_sp_item_flag"`
  959. LmtUsedFlag string `json:"lmt_used_flag"`
  960. MedChrgitmType string `json:"med_chrgitm_type"`
  961. Memo string `json:"memo"`
  962. OverlmtAmt float64 `json:"overlmt_amt"`
  963. PreselfpayAmt float64 `json:"preselfpay_amt"`
  964. Pric float64 `json:"pric"`
  965. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  966. SelfpayProp float64 `json:"selfpay_prop"`
  967. } `json:"result"`
  968. } `json:"output"`
  969. RefmsgTime string `json:"refmsg_time"`
  970. RespondTime string `json:"respond_time"`
  971. Signtype string `json:"signtype"`
  972. WarnMsg string `json:"warn_msg"`
  973. }
  974. type ResultFive struct {
  975. Insutype string `json:"insutype"`
  976. }
  977. func (c *HisApiController) GetUploadInfo() {
  978. id, _ := c.GetInt64("id")
  979. record_time := c.GetString("record_time")
  980. timeLayout := "2006-01-02"
  981. loc, _ := time.LoadLocation("Local")
  982. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  983. if err != nil {
  984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  985. return
  986. }
  987. recordDateTime := theTime.Unix()
  988. adminUser := c.GetAdminUserInfo()
  989. prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  990. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  991. timestamp := time.Now().Unix()
  992. tempTime := time.Unix(timestamp, 0)
  993. timeFormat := tempTime.Format("20060102150405")
  994. chrgBchno := rand.Intn(100000) + 10000
  995. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  996. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  997. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  998. client := &http.Client{}
  999. data := make(map[string]interface{})
  1000. data["psn_no"] = his.PsnNo
  1001. data["mdtrt_id"] = his.Number
  1002. data["pre"] = prescriptions
  1003. data["chrg_bchno"] = chrg_bchno
  1004. data["org_name"] = org.OrgName
  1005. data["doctor"] = patientPrescription.Doctor
  1006. data["dept"] = patientPrescription.Departments
  1007. var ids []int64
  1008. for _, item := range prescriptions {
  1009. ids = append(ids, item.ID)
  1010. }
  1011. bytesData, _ := json.Marshal(data)
  1012. req, _ := http.NewRequest("POST", "http://127.0.0.1:9531/"+"gdyb/five", bytes.NewReader(bytesData))
  1013. resp, _ := client.Do(req)
  1014. defer resp.Body.Close()
  1015. body, ioErr := ioutil.ReadAll(resp.Body)
  1016. if ioErr != nil {
  1017. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1018. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1019. return
  1020. }
  1021. var respJSON map[string]interface{}
  1022. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1023. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1025. return
  1026. }
  1027. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1028. userJSONBytes, _ := json.Marshal(respJSON)
  1029. var res ResultFour
  1030. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1031. utils.ErrorLog("解析失败:%v", err)
  1032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1033. return
  1034. }
  1035. if res.Infcode == 0 {
  1036. order := &models.HisOrder{
  1037. UserOrgId: adminUser.CurrentOrgId,
  1038. HisPatientId: his.ID,
  1039. PatientId: his.PatientId,
  1040. SettleAccountsDate: recordDateTime,
  1041. Ctime: time.Now().Unix(),
  1042. Mtime: time.Now().Unix(),
  1043. Status: 1,
  1044. Number: chrg_bchno,
  1045. Infcode: res.Infcode,
  1046. WarnMsg: res.WarnMsg,
  1047. Cainfo: res.Cainfo,
  1048. ErrMsg: res.ErrMsg,
  1049. RespondTime: res.RefmsgTime,
  1050. InfRefmsgid: res.InfRefmsgid,
  1051. OrderStatus: 1,
  1052. }
  1053. err = service.CreateOrder(order)
  1054. if err != nil {
  1055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1056. return
  1057. }
  1058. for _, item := range res.Output.Result {
  1059. temp := strings.Split(item.FeedetlSn, "-")
  1060. var advice_id int64 = 0
  1061. var project_id int64 = 0
  1062. var types int64 = 0
  1063. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1064. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1065. if temp[1] == "1" {
  1066. advice_id = id
  1067. project_id = 0
  1068. } else if temp[1] == "2" {
  1069. advice_id = 0
  1070. project_id = id
  1071. }
  1072. info := &models.HisOrderInfo{
  1073. OrderNumber: order.Number,
  1074. FeedetlSn: item.FeedetlSn,
  1075. UploadDate: time.Now().Unix(),
  1076. AdviceId: advice_id,
  1077. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1078. Cnt: item.Cnt,
  1079. Pric: float64(item.Pric),
  1080. PatientId: his.PatientId,
  1081. PricUplmtAmt: item.PricUplmtAmt,
  1082. SelfpayProp: item.SelfpayProp,
  1083. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1084. OverlmtAmt: item.OverlmtAmt,
  1085. PreselfpayAmt: item.PreselfpayAmt,
  1086. BasMednFlag: item.BasMednFlag,
  1087. MedChrgitmType: item.MedChrgitmType,
  1088. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1089. Status: 1,
  1090. Memo: item.Memo,
  1091. Mtime: time.Now().Unix(),
  1092. InscpScpAmt: item.InscpScpAmt,
  1093. DrtReimFlag: item.DrtReimFlag,
  1094. Ctime: time.Now().Unix(),
  1095. ListSpItemFlag: item.ListSpItemFlag,
  1096. ChldMedcFlag: item.ChldMedcFlag,
  1097. LmtUsedFlag: item.LmtUsedFlag,
  1098. ChrgitmLv: item.ChrgitmLv,
  1099. UserOrgId: adminUser.CurrentOrgId,
  1100. HisPatientId: his.ID,
  1101. OrderId: order.ID,
  1102. ProjectId: project_id,
  1103. Type: types,
  1104. }
  1105. service.CreateOrderInfo(info)
  1106. }
  1107. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1108. var total float64
  1109. for _, item := range prescriptions {
  1110. if item.Type == 1 { //药品
  1111. for _, subItem := range item.HisDoctorAdviceInfo {
  1112. total = total + (subItem.Price * subItem.PrescribingNumber)
  1113. }
  1114. }
  1115. if item.Type == 2 { //项目
  1116. for _, subItem := range item.HisPrescriptionProject {
  1117. total = total + (subItem.Price * float64(subItem.Count))
  1118. }
  1119. }
  1120. }
  1121. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1122. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1123. allTotal := fmt.Sprintf("%.2f", total)
  1124. if res.Infcode == 0 {
  1125. var rf []*ResultFive
  1126. json.Unmarshal([]byte(his.Iinfo), &rf)
  1127. psn_no := his.PsnNo
  1128. mdtrt_id := his.Number
  1129. chrg_bchno := chrg_bchno
  1130. cert_no := his.Certno
  1131. insutype := rf[0].Insutype
  1132. api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1133. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1134. "&total=" + allTotal + "&org_name=" + org.OrgName + "&doctor=" + patientPrescription.Doctor
  1135. resp, requestErr := http.Get(api)
  1136. if requestErr != nil {
  1137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1138. return
  1139. }
  1140. defer resp.Body.Close()
  1141. body, ioErr := ioutil.ReadAll(resp.Body)
  1142. if ioErr != nil {
  1143. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1145. return
  1146. }
  1147. var respJSON map[string]interface{}
  1148. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1149. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1151. return
  1152. }
  1153. fmt.Println(respJSON)
  1154. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1155. userJSONBytes, _ := json.Marshal(respJSON)
  1156. var res ResultFour
  1157. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1158. utils.ErrorLog("解析失败:%v", err)
  1159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1160. return
  1161. }
  1162. } else {
  1163. }
  1164. } else {
  1165. c.ServeSuccessJSON(map[string]interface{}{
  1166. "msg": res.ErrMsg,
  1167. })
  1168. }
  1169. }
  1170. func (c *HisApiController) GetHisOrderList() {
  1171. adminUser := c.GetAdminUserInfo()
  1172. org_id := adminUser.CurrentOrgId
  1173. order, err := service.GetHisOrderList(org_id)
  1174. if err == nil {
  1175. c.ServeSuccessJSON(map[string]interface{}{
  1176. "order": order,
  1177. })
  1178. } else {
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1180. return
  1181. }
  1182. }
  1183. func (c *HisApiController) GetHisOrder() {
  1184. patient_id, _ := c.GetInt64("patient_id", 0)
  1185. number := c.GetString("number")
  1186. adminInfo := c.GetAdminUserInfo()
  1187. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  1188. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.SettleAccountsDate, order.Number)
  1189. if err == nil {
  1190. c.ServeSuccessJSON(map[string]interface{}{
  1191. "order": order,
  1192. "prescription": prescriptions,
  1193. })
  1194. } else {
  1195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1196. return
  1197. }
  1198. }
  1199. func (c *HisApiController) GetHisPrescriptionList() {
  1200. adminInfo := c.GetAdminUserInfo()
  1201. fmt.Println("11111dassdfs11")
  1202. prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  1203. fmt.Println(prescriptionOrder)
  1204. if err == nil {
  1205. c.ServeSuccessJSON(map[string]interface{}{
  1206. "order": prescriptionOrder,
  1207. })
  1208. } else {
  1209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1210. return
  1211. }
  1212. }
  1213. func (c *HisApiController) GetHisPrescriptionInfo() {
  1214. patient_id, _ := c.GetInt64("patient_id")
  1215. his_patient_id, _ := c.GetInt64("his_patient_id")
  1216. adminInfo := c.GetAdminUserInfo()
  1217. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(patient_id, his_patient_id, adminInfo.CurrentOrgId)
  1218. if err == nil {
  1219. c.ServeSuccessJSON(map[string]interface{}{
  1220. "order": prescriptionOrder,
  1221. })
  1222. } else {
  1223. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1224. return
  1225. }
  1226. }