his_api_controller.go 69KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "bytes"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "io/ioutil"
  13. "math/rand"
  14. "net/http"
  15. "reflect"
  16. "strconv"
  17. "strings"
  18. "time"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  35. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  36. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  39. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  40. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  41. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  42. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  43. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  44. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  45. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  46. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  47. //新增附加费用
  48. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  49. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  50. }
  51. func (c *HisApiController) GetHisPatientList() {
  52. types, _ := c.GetInt64("type", 0)
  53. record_date := c.GetString("record_date")
  54. timeLayout := "2006-01-02"
  55. loc, _ := time.LoadLocation("Local")
  56. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  57. if err != nil {
  58. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  59. return
  60. }
  61. recordDateTime := theTime.Unix()
  62. adminInfo := c.GetAdminUserInfo()
  63. patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  64. var total_one int64
  65. var total_two int64
  66. //获取当前用户的信息
  67. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  68. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  69. //获取所有科室信息
  70. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  71. for _, item := range patients {
  72. if item.HisPrescription == nil || len(item.HisPrescription) <= 0 {
  73. total_one = total_one + 1
  74. }
  75. if item.HisPrescription != nil && len(item.HisPrescription) > 0 {
  76. total_two = total_two + 1
  77. }
  78. }
  79. if types == 0 {
  80. c.ServeSuccessJSON(map[string]interface{}{
  81. "list": patients,
  82. "total_one": total_one,
  83. "total_two": total_two,
  84. "info": adminUserInfo,
  85. "doctors": doctors,
  86. "department": department,
  87. })
  88. } else if types == 1 { //未就诊
  89. var patientsOne []*service.Schedule
  90. for _, item := range patients {
  91. if item.HisPrescription == nil || len(item.HisPrescription) <= 0 {
  92. patientsOne = append(patientsOne, item)
  93. }
  94. }
  95. c.ServeSuccessJSON(map[string]interface{}{
  96. "list": patientsOne,
  97. "total_one": total_one,
  98. "total_two": total_two,
  99. "info": adminUserInfo,
  100. "doctors": doctors,
  101. "department": department,
  102. })
  103. } else if types == 2 { //已就诊
  104. var patientsTwo []*service.Schedule
  105. for _, item := range patients {
  106. if item.HisPrescription != nil && len(item.HisPrescription) > 0 {
  107. patientsTwo = append(patientsTwo, item)
  108. }
  109. }
  110. c.ServeSuccessJSON(map[string]interface{}{
  111. "list": patientsTwo,
  112. "total_one": total_one,
  113. "total_two": total_two,
  114. "info": adminUserInfo,
  115. "doctors": doctors,
  116. "department": department,
  117. })
  118. }
  119. }
  120. func (c *HisApiController) GetHisPatientInfo() {
  121. patient_id, _ := c.GetInt64("patient_id")
  122. record_date := c.GetString("record_date")
  123. number := c.GetString("number")
  124. timeLayout := "2006-01-02"
  125. loc, _ := time.LoadLocation("Local")
  126. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  127. if err != nil {
  128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  129. return
  130. }
  131. recordDateTime := theTime.Unix()
  132. admin := c.GetAdminUserInfo()
  133. his_patient_info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  134. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  135. prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime)
  136. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  137. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  138. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  139. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  140. //addtions, _ := service.GetAllAdditionCharge(admin.CurrentOrgId, patient_id, recordDateTime)
  141. c.ServeSuccessJSON(map[string]interface{}{
  142. "his_info": his_patient_info,
  143. "xt_info": xt_patient_info,
  144. "prescription": prescriptions,
  145. "case_history": case_history,
  146. "info": patientPrescriptionInfo,
  147. "last_info": lastPatientPrescriptionInfo,
  148. "order": order,
  149. })
  150. return
  151. }
  152. func (c *HisApiController) GetHisPrescriptionConfig() {
  153. adminInfo := c.GetAdminUserInfo()
  154. //获取医嘱模版
  155. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  156. //获取所有基础药
  157. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  158. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  159. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  160. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  161. //获取所有科室信息
  162. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  163. //获取诊断信息
  164. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  165. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  166. c.ServeSuccessJSON(map[string]interface{}{
  167. "drugs": drugs,
  168. "advices_template": advices,
  169. "drugways": drugways,
  170. "efs": efs,
  171. "doctors": doctors,
  172. "department": department,
  173. "sick": sick,
  174. "additions": additions,
  175. })
  176. }
  177. func (c *HisApiController) CreateHisPrescription() {
  178. record_date := c.GetString("record_date")
  179. patient_id, _ := c.GetInt64("patient_id")
  180. reg_type := c.GetString("reg_type")
  181. diagnose := c.GetString("diagnose")
  182. sick_history := c.GetString("sick_history")
  183. doctor_id, _ := c.GetInt64("doctor", 0)
  184. department, _ := c.GetInt64("department", 0)
  185. his_patient_id, _ := c.GetInt64("his_patient_id")
  186. dataBody := make(map[string]interface{}, 0)
  187. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  188. if err != nil {
  189. utils.ErrorLog(err.Error())
  190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  191. return
  192. }
  193. timeLayout := "2006-01-02"
  194. loc, _ := time.LoadLocation("Local")
  195. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  196. if err != nil {
  197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  198. return
  199. }
  200. adminInfo := c.GetAdminUserInfo()
  201. recordDateTime := theTime.Unix()
  202. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  203. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  204. var hpInfo models.HisPrescriptionInfo
  205. if info.ID == 0 {
  206. var randNum int
  207. randNum = rand.Intn(10000) + 1000
  208. timestamp := time.Now().Unix()
  209. tempTime := time.Unix(timestamp, 0)
  210. timeFormat := tempTime.Format("20060102150405")
  211. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  212. hpInfo = models.HisPrescriptionInfo{
  213. UserOrgId: adminInfo.CurrentOrgId,
  214. RecordDate: theTime.Unix(),
  215. PatientId: patient_id,
  216. Status: 1,
  217. Ctime: time.Now().Unix(),
  218. Mtime: time.Now().Unix(),
  219. Creator: adminInfo.AdminUser.Id,
  220. Modifier: adminInfo.AdminUser.Id,
  221. Diagnosis: diagnose,
  222. SickHistory: sick_history,
  223. Departments: department,
  224. RegisterType: reg_type,
  225. PrescriptionNumber: p_number,
  226. PrescriptionStatus: 1,
  227. Doctor: role.UserName,
  228. DoctorId: doctor_id,
  229. }
  230. service.SavePatientPrescriptionInfo(hpInfo)
  231. } else {
  232. hpInfo = models.HisPrescriptionInfo{
  233. ID: info.ID,
  234. UserOrgId: adminInfo.CurrentOrgId,
  235. RecordDate: info.RecordDate,
  236. PatientId: info.PatientId,
  237. Status: 1,
  238. Ctime: info.Ctime,
  239. Mtime: time.Now().Unix(),
  240. Creator: info.Creator,
  241. Modifier: adminInfo.AdminUser.Id,
  242. Diagnosis: diagnose,
  243. SickHistory: sick_history,
  244. Departments: department,
  245. RegisterType: reg_type,
  246. PrescriptionNumber: info.PrescriptionNumber,
  247. Doctor: role.UserName,
  248. PrescriptionStatus: info.PrescriptionStatus,
  249. DoctorId: doctor_id,
  250. }
  251. service.SavePatientPrescriptionInfo(hpInfo)
  252. }
  253. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  254. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  255. if len(prescriptions) > 0 {
  256. for _, item := range prescriptions {
  257. items := item.(map[string]interface{})
  258. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  259. utils.ErrorLog("id")
  260. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  261. return
  262. }
  263. id := int64(items["id"].(float64))
  264. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  265. utils.ErrorLog("type")
  266. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  267. return
  268. }
  269. types := int64(items["type"].(float64))
  270. ctime := time.Now().Unix()
  271. prescription := &models.HisPrescription{
  272. ID: id,
  273. PatientId: patient_id,
  274. UserOrgId: adminInfo.CurrentOrgId,
  275. RecordDate: recordDateTime,
  276. Ctime: ctime,
  277. Mtime: ctime,
  278. Type: types,
  279. Modifier: adminInfo.AdminUser.Id,
  280. Creator: adminInfo.AdminUser.Id,
  281. Status: 1,
  282. Doctor: role.UserName,
  283. HisPatientId: his_patient_id,
  284. OrderStatus: 1,
  285. BatchNumber: "",
  286. PrescriptionNumber: hpInfo.PrescriptionNumber,
  287. }
  288. service.SaveHisPrescription(prescription)
  289. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  290. advices := items["advices"].([]interface{})
  291. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  292. groupNo := int64(0)
  293. ctime := time.Now().Unix()
  294. mtime := ctime
  295. if len(advices) > 0 {
  296. for _, advice := range advices {
  297. var s models.HisDoctorAdviceInfo
  298. s.PrescriptionId = prescription.ID
  299. s.AdviceType = 2
  300. s.AdviceDoctor = adminInfo.AdminUser.Id
  301. s.StopState = 2
  302. s.ExecutionState = 2
  303. s.AdviceDate = recordDateTime
  304. s.Status = 1
  305. s.UserOrgId = adminInfo.CurrentOrgId
  306. s.RecordDate = recordDateTime
  307. s.StartTime = recordDateTime
  308. s.Groupno = groupNo
  309. s.CreatedTime = ctime
  310. s.UpdatedTime = mtime
  311. s.PatientId = patient_id
  312. s.HisPatientId = his_patient_id
  313. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  314. if errcode > 0 {
  315. c.ServeFailJSONWithSGJErrorCode(errcode)
  316. return
  317. }
  318. service.CreateHisDoctorAdvice(&s)
  319. var randNum int
  320. randNum = rand.Intn(10000) + 1000
  321. timestamp := time.Now().Unix()
  322. tempTime := time.Unix(timestamp, 0)
  323. timeFormat := tempTime.Format("20060102150405")
  324. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  325. service.CreateHisDoctorAdvice(&s)
  326. }
  327. }
  328. }
  329. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  330. projects := items["project"].([]interface{})
  331. if len(projects) > 0 {
  332. for _, project := range projects {
  333. var p models.HisPrescriptionProject
  334. p.PrescriptionId = prescription.ID
  335. p.Ctime = time.Now().Unix()
  336. p.Mtime = time.Now().Unix()
  337. p.PatientId = patient_id
  338. p.RecordDate = recordDateTime
  339. p.UserOrgId = adminInfo.CurrentOrgId
  340. p.HisPatientId = his_patient_id
  341. p.Status = 1
  342. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  343. if errcode > 0 {
  344. c.ServeFailJSONWithSGJErrorCode(errcode)
  345. return
  346. }
  347. service.CreateHisProjectTwo(&p)
  348. var randNum int
  349. randNum = rand.Intn(10000) + 1000
  350. timestamp := time.Now().Unix()
  351. tempTime := time.Unix(timestamp, 0)
  352. timeFormat := tempTime.Format("20060102150405")
  353. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  354. service.SaveHisProjectTwo(&p)
  355. }
  356. }
  357. }
  358. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  359. addition := items["addition"].([]interface{})
  360. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  361. ctime := time.Now().Unix()
  362. mtime := ctime
  363. if len(addition) > 0 {
  364. for _, item := range addition {
  365. var s models.HisAdditionalCharge
  366. s.PrescriptionId = prescription.ID
  367. s.Status = 1
  368. s.UserOrgId = adminInfo.CurrentOrgId
  369. s.RecordDate = recordDateTime
  370. s.CreatedTime = ctime
  371. s.UpdatedTime = mtime
  372. s.PatientId = patient_id
  373. s.HisPatientId = his_patient_id
  374. errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}))
  375. if errcode > 0 {
  376. c.ServeFailJSONWithSGJErrorCode(errcode)
  377. return
  378. }
  379. service.CreateAdditionalCharge(&s)
  380. var randNum int
  381. randNum = rand.Intn(10000) + 1000
  382. timestamp := time.Now().Unix()
  383. tempTime := time.Unix(timestamp, 0)
  384. timeFormat := tempTime.Format("20060102150405")
  385. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  386. service.CreateAdditionalCharge(&s)
  387. }
  388. }
  389. }
  390. }
  391. }
  392. }
  393. if err == nil {
  394. c.ServeSuccessJSON(map[string]interface{}{
  395. "msg": "保存成功",
  396. })
  397. return
  398. } else {
  399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  400. return
  401. }
  402. }
  403. func (c *HisApiController) DeletePrescription() {
  404. prescription_id, _ := c.GetInt64("id")
  405. //TODO 需要判断是否已经结算
  406. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  407. if err == nil {
  408. c.ServeSuccessJSON(map[string]interface{}{
  409. "msg": "删除成功",
  410. })
  411. return
  412. } else {
  413. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  414. return
  415. }
  416. }
  417. func (c *HisApiController) DeleteDoctorAdvice() {
  418. id, _ := c.GetInt64("id")
  419. //TODO 需要判断是否已经结算
  420. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  421. if err == nil {
  422. c.ServeSuccessJSON(map[string]interface{}{
  423. "msg": "删除成功",
  424. })
  425. return
  426. } else {
  427. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  428. return
  429. }
  430. }
  431. func (c *HisApiController) DeleteProject() {
  432. id, _ := c.GetInt64("id")
  433. //TODO 需要判断是否已经结算
  434. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  435. if err == nil {
  436. c.ServeSuccessJSON(map[string]interface{}{
  437. "msg": "删除成功",
  438. })
  439. return
  440. } else {
  441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  442. return
  443. }
  444. }
  445. func (c *HisApiController) CreateHisAdditionalCharge() {
  446. his_patient_id, _ := c.GetInt64("his_patient_id")
  447. patient_id, _ := c.GetInt64("patient_id")
  448. record_date := c.GetString("record_date")
  449. timeLayout := "2006-01-02"
  450. loc, _ := time.LoadLocation("Local")
  451. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  452. if err != nil {
  453. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  454. return
  455. }
  456. adminInfo := c.GetAdminUserInfo()
  457. recordDateTime := theTime.Unix()
  458. dataBody := make(map[string]interface{}, 0)
  459. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  460. if err != nil {
  461. utils.ErrorLog(err.Error())
  462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  463. return
  464. }
  465. var additions []*models.HisAdditionalCharge
  466. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  467. additions, _ := dataBody["addition"].([]interface{})
  468. if len(additions) > 0 {
  469. for _, item := range additions {
  470. items := item.(map[string]interface{})
  471. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  472. utils.ErrorLog("item_id")
  473. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  474. return
  475. }
  476. item_id := int64(items["item_id"].(float64))
  477. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  478. utils.ErrorLog("item_name")
  479. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  480. return
  481. }
  482. item_name := items["item_name"].(string)
  483. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  484. utils.ErrorLog("price")
  485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  486. return
  487. }
  488. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  489. ctime := time.Now().Unix()
  490. additional := &models.HisAdditionalCharge{
  491. PatientId: patient_id,
  492. HisPatientId: his_patient_id,
  493. UserOrgId: adminInfo.CurrentOrgId,
  494. RecordDate: recordDateTime,
  495. CreatedTime: ctime,
  496. UpdatedTime: ctime,
  497. Modifier: adminInfo.AdminUser.Id,
  498. Creator: adminInfo.AdminUser.Id,
  499. Price: price,
  500. ItemName: item_name,
  501. ItemId: item_id,
  502. Status: 1,
  503. }
  504. additions = append(additions, additional)
  505. }
  506. }
  507. }
  508. for _, item := range additions {
  509. service.CreateAddtionalCharge(item)
  510. }
  511. c.ServeSuccessJSON(map[string]interface{}{
  512. "msg": "创建成功",
  513. })
  514. }
  515. func (c *HisApiController) CreateHisPatientCaseHistory() {
  516. blood_fat := c.GetString("blood_fat")
  517. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  518. fmt.Println("33333333", bloodfatfloat)
  519. blood_sugar := c.GetString("blood_sugar")
  520. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  521. fmt.Println(bloodsugarfloat)
  522. chief_conplaint := c.GetString("chief_conplaint")
  523. dbp := c.GetString("dbp")
  524. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  525. delivery_way, _ := c.GetInt64("delivery_way")
  526. diagnostic := c.GetString("diagnostic")
  527. fmt.Println("diagnostic", diagnostic)
  528. family_history := c.GetString("family_history")
  529. fmt.Println(family_history)
  530. height := c.GetString("height")
  531. history_of_present_illness := c.GetString("history_of_present_illness")
  532. is_infect, _ := c.GetInt64("is_infect")
  533. fmt.Println("is", is_infect)
  534. past_history := c.GetString("past_history")
  535. patient_id, _ := c.GetInt64("patient_id")
  536. his_patient_id, _ := c.GetInt64("his_patient_id")
  537. fmt.Println("patient_id", patient_id)
  538. personal_history := c.GetString("personal_history")
  539. pulse := c.GetString("pulse")
  540. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  541. sbp := c.GetString("sbp")
  542. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  543. heightfloat, _ := strconv.ParseFloat(height, 64)
  544. sicktype := c.GetString("sick_type")
  545. fmt.Println("sicketype", sicktype)
  546. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  547. symptom := c.GetString("symptom")
  548. sick_date := c.GetString("sick_date")
  549. temperatures := c.GetString("temperature")
  550. fmt.Println("temperatures", temperatures)
  551. temperature, _ := strconv.ParseFloat(temperatures, 64)
  552. record_date := c.GetString("record_date")
  553. breathing := c.GetString("breathing")
  554. doctor_advice := c.GetString("doctor_advice")
  555. remark := c.GetString("remark")
  556. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  557. fmt.Println("breathingfloat", breathingfloat)
  558. timeLayout := "2006-01-02"
  559. loc, _ := time.LoadLocation("Local")
  560. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  561. if err != nil {
  562. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  563. return
  564. }
  565. recordDateTime := theTime.Unix()
  566. fmt.Println("recordDataTime", recordDateTime)
  567. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  568. if err != nil {
  569. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  570. return
  571. }
  572. sickTimes := sickTime.Unix()
  573. ctime := time.Now().Unix()
  574. caseHistory := models.HisPatientCaseHistory{
  575. HisPatientId: his_patient_id,
  576. PatientId: patient_id,
  577. Temperature: temperature,
  578. BloodSugar: bloodsugarfloat,
  579. Pulse: pulsefloat,
  580. Sbp: sbpfloat,
  581. Dbp: dbpfloat,
  582. Height: heightfloat,
  583. BloodFat: bloodfatfloat,
  584. SickType: sick_type,
  585. Symptom: symptom,
  586. SickDate: sickTimes,
  587. IsInfect: is_infect,
  588. HistoryOfPresentIllness: history_of_present_illness,
  589. PastHistory: past_history,
  590. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  591. ChiefConplaint: chief_conplaint,
  592. PersonalHistory: personal_history,
  593. FamilyHistory: family_history,
  594. Diagnostic: diagnostic,
  595. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  596. Status: 1,
  597. Ctime: ctime,
  598. Mtime: ctime,
  599. RecordDate: recordDateTime,
  600. DeliveryWay: delivery_way,
  601. Breathing: breathingfloat,
  602. DoctorAdvice: doctor_advice,
  603. Remark: remark,
  604. }
  605. err = service.SaveHisPatientCaseHistory(&caseHistory)
  606. if err != nil {
  607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  608. return
  609. }
  610. c.ServeSuccessJSON(map[string]interface{}{
  611. "caseHistory": caseHistory,
  612. })
  613. return
  614. //查询该患者是否有病历
  615. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  616. //if errcode == gorm.ErrRecordNotFound {
  617. // err = service.SaveHisPatientCaseHistory(caseHistory)
  618. // if err != nil {
  619. // c.ServeSuccessJSON(map[string]interface{}{
  620. // "msg": "保存成功",
  621. // })
  622. // }
  623. //} else if errcode == nil {
  624. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  625. // return
  626. //}
  627. }
  628. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  629. patient_id, _ := c.GetInt64("patient_id", 0)
  630. adminUser := c.GetAdminUserInfo()
  631. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  632. c.ServeSuccessJSON(map[string]interface{}{
  633. "list": caseHistorys,
  634. })
  635. }
  636. func (c *HisApiController) GetHisPatientCaseHistory() {
  637. record_date, _ := c.GetInt64("record_date", 0)
  638. patient_id, _ := c.GetInt64("patient_id", 0)
  639. admin := c.GetAdminUserInfo()
  640. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  641. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  642. c.ServeSuccessJSON(map[string]interface{}{
  643. "info": info,
  644. "case_history": case_history,
  645. })
  646. }
  647. func (c *HisApiController) CreateCaseHistoryTemplate() {
  648. template_name := c.GetString("template_name")
  649. fmt.Println("template_name22222222222222", template_name)
  650. template_remark := c.GetString("template_remark")
  651. doctor := c.GetAdminUserInfo().AdminUser.Id
  652. diagnostic := c.GetString("diagnostic")
  653. chief_conplaint := c.GetString("chief_conplain")
  654. history_of_present_illness := c.GetString("history_of_present_illness")
  655. past_history := c.GetString("past_history")
  656. personal_history := c.GetString("personal_history")
  657. family_history := c.GetString("family_history")
  658. user_name := c.GetString("user_name")
  659. //record_date := c.GetString("record_date")
  660. //fmt.Println("record_date--------",record_date)
  661. //timeLayout := "2006-01-02"
  662. //loc, _ := time.LoadLocation("Local")
  663. //
  664. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  665. //if err != nil {
  666. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  667. // return
  668. //}
  669. //recordDateTime := theTime.Unix()
  670. ctime := time.Now().Unix()
  671. template := models.HisCaseHistoryTemplate{
  672. HistoryOfPresentIllness: history_of_present_illness,
  673. PastHistory: past_history,
  674. ChiefConplaint: chief_conplaint,
  675. PersonalHistory: personal_history,
  676. FamilyHistory: family_history,
  677. Diagnostic: diagnostic,
  678. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  679. Status: 1,
  680. Ctime: ctime,
  681. Mtime: ctime,
  682. RecordDate: time.Now().Unix(),
  683. TemplateName: template_name,
  684. TemplateRemark: template_remark,
  685. Creator: doctor,
  686. Modifier: doctor,
  687. UserName: user_name,
  688. }
  689. err := service.SaveHisPatientCaseHistoryTemplate(template)
  690. if err == nil {
  691. c.ServeSuccessJSON(map[string]interface{}{
  692. "msg": "保存成功",
  693. })
  694. } else {
  695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  696. return
  697. }
  698. }
  699. func (c *HisApiController) GetCaseHistoryTemplate() {
  700. timeLayout := "2006-01-02"
  701. loc, _ := time.LoadLocation("Local")
  702. keyword := c.GetString("keyword")
  703. start_time := c.GetString("start_time")
  704. end_time := c.GetString("end_time")
  705. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  706. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  707. admin := c.GetAdminUserInfo()
  708. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  709. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  710. c.ServeSuccessJSON(map[string]interface{}{
  711. "template": template,
  712. //"history": history,
  713. })
  714. }
  715. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  716. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  717. utils.ErrorLog("drug_name")
  718. return enums.ErrorCodeParamWrong
  719. }
  720. adviceName, _ := json["drug_name"].(string)
  721. if len(adviceName) == 0 {
  722. utils.ErrorLog("len(advice_name) == 0")
  723. return enums.ErrorCodeParamWrong
  724. }
  725. advice.AdviceName = adviceName
  726. adviceDesc, _ := json["advice_desc"].(string)
  727. advice.AdviceDesc = adviceDesc
  728. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  729. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  730. advice.DrugSpec = drugSpec
  731. }
  732. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  733. remark, _ := json["remark"].(string)
  734. advice.Remark = remark
  735. }
  736. if json["id"] == nil {
  737. advice.DrugId = 0
  738. } else {
  739. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  740. drug_id := int64(json["id"].(float64))
  741. advice.DrugId = drug_id
  742. }
  743. }
  744. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  745. advice_id := int64(json["advice_id"].(float64))
  746. advice.ID = advice_id
  747. }
  748. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  749. drugSpecUnit, _ := json["min_unit"].(string)
  750. advice.DrugSpecUnit = drugSpecUnit
  751. }
  752. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  753. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  754. advice.SingleDose = singleDose
  755. }
  756. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  757. singleDoseUnit, _ := json["single_dose_unit"].(string)
  758. advice.SingleDoseUnit = singleDoseUnit
  759. }
  760. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  761. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  762. advice.PrescribingNumber = prescribingNumber
  763. }
  764. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  765. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  766. advice.PrescribingNumberUnit = prescribingNumberUnit
  767. }
  768. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  769. deliveryWay, _ := json["delivery_way"].(string)
  770. advice.DeliveryWay = deliveryWay
  771. }
  772. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  773. executionFrequency, _ := json["execution_frequency"].(string)
  774. advice.ExecutionFrequency = executionFrequency
  775. }
  776. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  777. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  778. advice.Price = price
  779. }
  780. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  781. med_list_codg, _ := json["medical_insurance_number"].(string)
  782. advice.MedListCodg = med_list_codg
  783. }
  784. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  785. day := int64(json["day"].(float64))
  786. advice.Day = day
  787. }
  788. return 0
  789. }
  790. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  791. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  792. id := int64(json["id"].(float64))
  793. project.ID = id
  794. }
  795. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  796. project_id := int64(json["project_id"].(float64))
  797. project.ProjectId = project_id
  798. fmt.Println(project_id)
  799. fmt.Println(project.ProjectId)
  800. }
  801. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  802. price := int64(json["price"].(float64))
  803. formatInt_price := strconv.FormatInt(price, 10)
  804. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  805. project.Price = float_price
  806. }
  807. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  808. total, _ := json["total"].(string)
  809. totals, _ := strconv.ParseInt(total, 10, 64)
  810. project.Count = totals
  811. }
  812. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  813. medical_code, _ := json["medical_code"].(string)
  814. project.MedListCodg = medical_code
  815. }
  816. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  817. single_dose, _ := json["single_dose"].(string)
  818. project.SingleDose = single_dose
  819. }
  820. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  821. delivery_way, _ := json["delivery_way"].(string)
  822. project.DeliveryWay = delivery_way
  823. }
  824. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  825. execution_frequency, _ := json["execution_frequency"].(string)
  826. project.ExecutionFrequency = execution_frequency
  827. }
  828. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  829. remark, _ := json["remark"].(string)
  830. project.Remark = remark
  831. }
  832. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  833. day, _ := json["number_days"].(string)
  834. project.Day = day
  835. }
  836. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  837. unit, _ := json["unit"].(string)
  838. project.Unit = unit
  839. }
  840. return 0
  841. }
  842. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}) int {
  843. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  844. id := int64(json["id"].(float64))
  845. additionalCharge.ID = id
  846. }
  847. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  848. item_id := int64(json["item_id"].(float64))
  849. additionalCharge.ItemId = item_id
  850. }
  851. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  852. price := int64(json["price"].(float64))
  853. formatInt_price := strconv.FormatInt(price, 10)
  854. float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  855. additionalCharge.Price = float_price
  856. }
  857. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  858. count, _ := json["count"].(string)
  859. counts, _ := strconv.ParseInt(count, 10, 64)
  860. additionalCharge.Count = counts
  861. }
  862. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  863. item_name, _ := json["item_name"].(string)
  864. additionalCharge.ItemName = item_name
  865. }
  866. return 0
  867. }
  868. func (c *HisApiController) GetHisOrderList() {
  869. page, _ := c.GetInt64("page", -1)
  870. limit, _ := c.GetInt64("limit", -1)
  871. start_time := c.GetString("start_time")
  872. end_time := c.GetString("end_time")
  873. types, _ := c.GetInt64("type", 0)
  874. keywords := c.GetString("keywords")
  875. timeLayout := "2006-01-02"
  876. loc, _ := time.LoadLocation("Local")
  877. var startTime int64
  878. if len(start_time) > 0 {
  879. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  880. if err != nil {
  881. fmt.Println(err)
  882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  883. return
  884. }
  885. startTime = theTime.Unix()
  886. }
  887. var endTime int64
  888. if len(end_time) > 0 {
  889. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  890. if err != nil {
  891. utils.ErrorLog(err.Error())
  892. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  893. return
  894. }
  895. endTime = theTime.Unix()
  896. }
  897. adminUser := c.GetAdminUserInfo()
  898. org_id := adminUser.CurrentOrgId
  899. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords)
  900. if err == nil {
  901. c.ServeSuccessJSON(map[string]interface{}{
  902. "order": order,
  903. "total": total,
  904. })
  905. } else {
  906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  907. return
  908. }
  909. }
  910. func (c *HisApiController) GetHisOrder() {
  911. patient_id, _ := c.GetInt64("patient_id", 0)
  912. number := c.GetString("number")
  913. adminInfo := c.GetAdminUserInfo()
  914. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  915. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.SettleAccountsDate, order.Number)
  916. if err == nil {
  917. c.ServeSuccessJSON(map[string]interface{}{
  918. "order": order,
  919. "prescription": prescriptions,
  920. })
  921. } else {
  922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  923. return
  924. }
  925. }
  926. func (c *HisApiController) GetHisPrescriptionList() {
  927. record_date := c.GetString("record_date")
  928. keywords := c.GetString("keywords")
  929. page, _ := c.GetInt64("page")
  930. limit, _ := c.GetInt64("limit")
  931. timeLayout := "2006-01-02"
  932. loc, _ := time.LoadLocation("Local")
  933. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  934. if err != nil {
  935. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  936. return
  937. }
  938. recordDateTime := theTime.Unix()
  939. adminInfo := c.GetAdminUserInfo()
  940. prescriptionOrder, err, total := service.GetHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  941. //adminInfo := c.GetAdminUserInfo()
  942. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  943. //fmt.Println(prescriptionOrder)
  944. if err == nil {
  945. c.ServeSuccessJSON(map[string]interface{}{
  946. "order": prescriptionOrder,
  947. "total": total,
  948. })
  949. } else {
  950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  951. return
  952. }
  953. }
  954. func (c *HisApiController) GetHisPrescriptionInfo() {
  955. id, _ := c.GetInt64("id")
  956. adminInfo := c.GetAdminUserInfo()
  957. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  958. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  959. if err == nil {
  960. c.ServeSuccessJSON(map[string]interface{}{
  961. "order": prescriptionOrder,
  962. "prescription": prescription,
  963. })
  964. } else {
  965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  966. return
  967. }
  968. }
  969. func (c *HisApiController) GetMedicalInsuranceConfig() {
  970. adminUser := c.GetAdminUserInfo()
  971. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  972. c.ServeSuccessJSON(map[string]interface{}{
  973. "config": config,
  974. })
  975. }
  976. type ResultTwo struct {
  977. ErrMsg interface{} `json:"err_msg"`
  978. InfRefmsgid string `json:"inf_refmsgid"`
  979. Infcode int64 `json:"infcode"`
  980. Output struct {
  981. Baseinfo struct {
  982. Age float64 `json:"age"`
  983. Brdy string `json:"brdy"`
  984. Certno string `json:"certno"`
  985. Gend string `json:"gend"`
  986. Naty string `json:"naty"`
  987. PsnCertType string `json:"psn_cert_type"`
  988. PsnName string `json:"psn_name"`
  989. PsnNo string `json:"psn_no"`
  990. } `json:"baseinfo"`
  991. Idetinfo []interface{} `json:"idetinfo"`
  992. Iinfo []struct {
  993. Balc int64 `json:"balc"`
  994. CvlservFlag string `json:"cvlserv_flag"`
  995. EmpName string `json:"emp_name"`
  996. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  997. Insutype string `json:"insutype"`
  998. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  999. PausInsuDate interface{} `json:"paus_insu_date"`
  1000. PsnInsuDate string `json:"psn_insu_date"`
  1001. PsnInsuStas string `json:"psn_insu_stas"`
  1002. PsnType string `json:"psn_type"`
  1003. } `json:"insuinfo"`
  1004. } `json:"output"`
  1005. RefmsgTime string `json:"refmsg_time"`
  1006. RespondTime string `json:"respond_time"`
  1007. Signtype interface{} `json:"signtype"`
  1008. WarnInfo interface{} `json:"warn_info"`
  1009. }
  1010. type ResultThree struct {
  1011. Cainfo interface{} `json:"cainfo"`
  1012. ErrMsg interface{} `json:"err_msg"`
  1013. InfRefmsgid string `json:"inf_refmsgid"`
  1014. Infcode int64 `json:"infcode"`
  1015. Output struct {
  1016. Data struct {
  1017. IptOtpNo string `json:"ipt_otp_no"`
  1018. MdtrtID string `json:"mdtrt_id"`
  1019. PsnNo string `json:"psn_no"`
  1020. } `json:"data"`
  1021. } `json:"output"`
  1022. RefmsgTime string `json:"refmsg_time"`
  1023. RespondTime string `json:"respond_time"`
  1024. Signtype interface{} `json:"signtype"`
  1025. WarnMsg interface{} `json:"warn_msg"`
  1026. }
  1027. type ResultFour struct {
  1028. Cainfo string `json:"cainfo"`
  1029. ErrMsg string `json:"err_msg"`
  1030. InfRefmsgid string `json:"inf_refmsgid"`
  1031. Infcode int64 `json:"infcode"`
  1032. Output struct {
  1033. Result []struct {
  1034. BasMednFlag string `json:"bas_medn_flag"`
  1035. ChldMedcFlag string `json:"chld_medc_flag"`
  1036. ChrgitmLv string `json:"chrgitm_lv"`
  1037. Cnt float64 `json:"cnt"`
  1038. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  1039. DrtReimFlag string `json:"drt_reim_flag"`
  1040. FeedetlSn string `json:"feedetl_sn"`
  1041. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1042. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  1043. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1044. ListSpItemFlag string `json:"list_sp_item_flag"`
  1045. LmtUsedFlag string `json:"lmt_used_flag"`
  1046. MedChrgitmType string `json:"med_chrgitm_type"`
  1047. Memo string `json:"memo"`
  1048. OverlmtAmt float64 `json:"overlmt_amt"`
  1049. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1050. Pric float64 `json:"pric"`
  1051. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  1052. SelfpayProp float64 `json:"selfpay_prop"`
  1053. } `json:"result"`
  1054. } `json:"output"`
  1055. RefmsgTime string `json:"refmsg_time"`
  1056. RespondTime string `json:"respond_time"`
  1057. Signtype string `json:"signtype"`
  1058. WarnMsg string `json:"warn_msg"`
  1059. }
  1060. type ResultFive struct {
  1061. Insutype string `json:"insutype"`
  1062. }
  1063. type ResultSix struct {
  1064. Cainfo interface{} `json:"cainfo"`
  1065. ErrMsg interface{} `json:"err_msg"`
  1066. InfRefmsgid string `json:"inf_refmsgid"`
  1067. Infcode int64 `json:"infcode"`
  1068. Output struct {
  1069. } `json:"output"`
  1070. RefmsgTime string `json:"refmsg_time"`
  1071. RespondTime string `json:"respond_time"`
  1072. Signtype interface{} `json:"signtype"`
  1073. WarnMsg interface{} `json:"warn_msg"`
  1074. }
  1075. type ResultSeven struct {
  1076. Cainfo string `json:"cainfo"`
  1077. ErrMsg string `json:"err_msg"`
  1078. InfRefmsgid string `json:"inf_refmsgid"`
  1079. Infcode int64 `json:"infcode"`
  1080. Output struct {
  1081. Setldetail []interface{} `json:"setldetail"`
  1082. Setlinfo struct {
  1083. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1084. AcctPay float64 `json:"acct_pay"`
  1085. ActPayDedc float64 `json:"act_pay_dedc"`
  1086. Age float64 `json:"age"`
  1087. Balc float64 `json:"balc"`
  1088. Brdy string `json:"brdy"`
  1089. Certno string `json:"certno"`
  1090. ClrOptins string `json:"clr_optins"`
  1091. ClrType string `json:"clr_type"`
  1092. ClrWay string `json:"clr_way"`
  1093. CvlservFlag string `json:"cvlserv_flag"`
  1094. CvlservPay float64 `json:"cvlserv_pay"`
  1095. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1096. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1097. Gend string `json:"gend"`
  1098. HifesPay float64 `json:"hifes_pay"`
  1099. HifmiPay float64 `json:"hifmi_pay"`
  1100. HifobPay float64 `json:"hifob_pay"`
  1101. HifpPay float64 `json:"hifp_pay"`
  1102. HospPartAmt float64 `json:"hosp_part_amt"`
  1103. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1104. Insutype string `json:"insutype"`
  1105. MafPay float64 `json:"maf_pay"`
  1106. MdtrtCertType string `json:"mdtrt_cert_type"`
  1107. MdtrtID string `json:"mdtrt_id"`
  1108. MedType string `json:"med_type"`
  1109. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1110. MedinsSetlID string `json:"medins_setl_id"`
  1111. Naty string `json:"naty"`
  1112. OthPay float64 `json:"oth_pay"`
  1113. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1114. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1115. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1116. PsnCashPay float64 `json:"psn_cash_pay"`
  1117. PsnCertType string `json:"psn_cert_type"`
  1118. PsnName string `json:"psn_name"`
  1119. PsnNo string `json:"psn_no"`
  1120. PsnPartAmt float64 `json:"psn_part_amt"`
  1121. PsnType string `json:"psn_type"`
  1122. SetlID string `json:"setl_id"`
  1123. SetlTime string `json:"setl_time"`
  1124. } `json:"setlinfo"`
  1125. } `json:"output"`
  1126. RefmsgTime string `json:"refmsg_time"`
  1127. RespondTime string `json:"respond_time"`
  1128. Signtype interface{} `json:"signtype"`
  1129. WarnMsg interface{} `json:"warn_msg"`
  1130. }
  1131. type Custom struct {
  1132. DetItemFeeSumamt string
  1133. Cut string
  1134. FeedetlSn string
  1135. Price string
  1136. MedListCodg string
  1137. Type int64
  1138. AdviceId int64
  1139. ProjectId int64
  1140. ItemId int64
  1141. }
  1142. //获取个人信息----挂号-----上传就诊信息
  1143. func (c *HisApiController) GetRegisterInfo() {
  1144. id, _ := c.GetInt64("id")
  1145. record_time := c.GetString("record_time")
  1146. timeLayout := "2006-01-02"
  1147. loc, _ := time.LoadLocation("Local")
  1148. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1149. if err != nil {
  1150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1151. return
  1152. }
  1153. recordDateTime := theTime.Unix()
  1154. adminInfo := c.GetAdminUserInfo()
  1155. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  1156. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1157. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1158. if patient == nil {
  1159. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1160. return
  1161. }
  1162. if len(patient.IdCardNo) == 0 {
  1163. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1164. return
  1165. }
  1166. //org, _ := service.GetOrgById(adminInfo.CurrentOrgId)
  1167. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1168. if config.IsOpen == 1 {
  1169. api := "http://127.0.0.1:9531/" + "gdyb/one?cert_no=" + patient.IdCardNo + "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code
  1170. resp, requestErr := http.Get(api)
  1171. if requestErr != nil {
  1172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1173. return
  1174. }
  1175. defer resp.Body.Close()
  1176. body, ioErr := ioutil.ReadAll(resp.Body)
  1177. if ioErr != nil {
  1178. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1180. return
  1181. }
  1182. var respJSON map[string]interface{}
  1183. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1184. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1185. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1186. return
  1187. }
  1188. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1189. userJSONBytes, _ := json.Marshal(userJSON)
  1190. var res ResultTwo
  1191. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1192. utils.ErrorLog("解析失败:%v", err)
  1193. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1194. return
  1195. }
  1196. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1197. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1198. infoStr := string(Iinfos)
  1199. idetinfoStr := string(Idetinfos)
  1200. his := models.VMHisPatient{
  1201. PsnNo: res.Output.Baseinfo.PsnNo,
  1202. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1203. Certno: res.Output.Baseinfo.Certno,
  1204. PsnName: res.Output.Baseinfo.PsnName,
  1205. Gend: res.Output.Baseinfo.Gend,
  1206. Naty: res.Output.Baseinfo.Naty,
  1207. Brdy: res.Output.Baseinfo.Brdy,
  1208. Age: res.Output.Baseinfo.Age,
  1209. Iinfo: infoStr,
  1210. Idetinfo: idetinfoStr,
  1211. PatientId: patient.ID,
  1212. RecordDate: theTime.Unix(),
  1213. }
  1214. fmt.Println(his)
  1215. if res.Output.Iinfo == nil || len(res.Output.Iinfo) == 0 {
  1216. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterOneException)
  1217. return
  1218. }
  1219. timestamp := time.Now().Unix()
  1220. tempTime := time.Unix(timestamp, 0)
  1221. timeFormat := tempTime.Format("20060102150405")
  1222. chrgBchno := rand.Intn(100000) + 10000
  1223. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1224. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1225. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1226. if count <= 0 {
  1227. api := "http://127.0.0.1:9531/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  1228. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  1229. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  1230. "&dept=" + department.Name + "&fixmedins_code=" + miConfig.Code
  1231. resp, requestErr := http.Get(api)
  1232. if requestErr != nil {
  1233. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1234. return
  1235. }
  1236. defer resp.Body.Close()
  1237. body, ioErr := ioutil.ReadAll(resp.Body)
  1238. if ioErr != nil {
  1239. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1240. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1241. return
  1242. }
  1243. var respJSON map[string]interface{}
  1244. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1245. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1246. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1247. return
  1248. }
  1249. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1250. userJSONBytes, _ := json.Marshal(respJSON)
  1251. var res ResultThree
  1252. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1253. utils.ErrorLog("解析失败:%v", err)
  1254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1255. return
  1256. }
  1257. if res.Infcode == -1 {
  1258. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1259. return
  1260. }
  1261. fmt.Println("000!!!!!!")
  1262. fmt.Println(res)
  1263. fmt.Println(res.Output.Data.MdtrtID)
  1264. fmt.Println(res.Output.Data.PsnNo)
  1265. fmt.Println(res.Output.Data.IptOtpNo)
  1266. his.Number = res.Output.Data.MdtrtID
  1267. his.PsnNo = res.Output.Data.PsnNo
  1268. his.IptOtpNo = res.Output.Data.IptOtpNo
  1269. his.IdCardNo = patient.IdCardNo
  1270. his.PhoneNumber = patient.Phone
  1271. his.UserOrgId = adminInfo.CurrentOrgId
  1272. his.Status = 1
  1273. his.Ctime = time.Now().Unix()
  1274. his.Mtime = time.Now().Unix()
  1275. err := service.CreateHisPatientTwo(&his)
  1276. if err == nil {
  1277. api := "http://127.0.0.1:9531/" + "gdyb/four?psn_no=" + his.PsnNo +
  1278. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1279. "&diag=" + patientPrescription.Diagnosis + "&org_name=" + miConfig.OrgName + "&med_type=" + "11" + "&doctor_id=" + strconv.FormatInt(patientPrescription.DoctorId, 10) + "&fixmedins_code=" + miConfig.Code
  1280. resp, requestErr := http.Get(api)
  1281. if requestErr != nil {
  1282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1283. return
  1284. }
  1285. body, ioErr := ioutil.ReadAll(resp.Body)
  1286. if ioErr != nil {
  1287. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1289. return
  1290. }
  1291. var respJSON map[string]interface{}
  1292. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1293. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1295. return
  1296. }
  1297. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1298. userJSONBytes, _ := json.Marshal(respJSON)
  1299. fmt.Println(respJSON)
  1300. fmt.Println(userJSONBytes)
  1301. var res ResultSix
  1302. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1303. utils.ErrorLog("解析失败:%v", err)
  1304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1305. return
  1306. }
  1307. if res.Infcode == -1 {
  1308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1309. return
  1310. }
  1311. c.ServeSuccessJSON(map[string]interface{}{
  1312. "his_info": his,
  1313. })
  1314. } else {
  1315. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1316. return
  1317. }
  1318. }
  1319. } else {
  1320. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1321. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1322. patient := models.XtHisPatient{
  1323. Age: patient.Age,
  1324. Birthday: patient.Birthday,
  1325. AdminUserId: adminInfo.AdminUser.Id,
  1326. IdCardNo: patient.IdCardNo,
  1327. Name: patient.Name,
  1328. Gender: patient.Gender,
  1329. UserOrgId: adminInfo.CurrentOrgId,
  1330. Status: 1,
  1331. RecordDate: recordDateTime,
  1332. IsReturn: 1,
  1333. PatientId: patient.ID,
  1334. Ctime: time.Now().Unix(),
  1335. Mtime: time.Now().Unix(),
  1336. }
  1337. service.CreateHisPatient(&patient)
  1338. }
  1339. c.ServeSuccessJSON(map[string]interface{}{
  1340. "his_info": patient,
  1341. })
  1342. }
  1343. }
  1344. //上传明细----结算
  1345. func (c *HisApiController) GetUploadInfo() {
  1346. id, _ := c.GetInt64("id")
  1347. record_time := c.GetString("record_time")
  1348. timeLayout := "2006-01-02"
  1349. loc, _ := time.LoadLocation("Local")
  1350. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1351. if err != nil {
  1352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1353. return
  1354. }
  1355. recordDateTime := theTime.Unix()
  1356. adminUser := c.GetAdminUserInfo()
  1357. prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1358. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1359. timestamp := time.Now().Unix()
  1360. tempTime := time.Unix(timestamp, 0)
  1361. timeFormat := tempTime.Format("20060102150405")
  1362. chrgBchno := rand.Intn(100000) + 10000
  1363. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1364. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1365. //org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1366. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1367. client := &http.Client{}
  1368. data := make(map[string]interface{})
  1369. data["psn_no"] = his.PsnNo
  1370. data["mdtrt_id"] = his.Number
  1371. data["pre"] = prescriptions
  1372. data["chrg_bchno"] = chrg_bchno
  1373. data["org_name"] = miConfig.OrgName
  1374. data["doctor"] = patientPrescription.Doctor
  1375. data["dept"] = patientPrescription.Departments
  1376. data["fixmedins_code"] = miConfig.Code
  1377. var ids []int64
  1378. //var idsTwo []int64
  1379. //
  1380. for _, item := range prescriptions {
  1381. ids = append(ids, item.ID)
  1382. }
  1383. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1384. if config.IsOpen == 1 { //对接了医保,走医保流程
  1385. bytesData, _ := json.Marshal(data)
  1386. req, _ := http.NewRequest("POST", "http://127.0.0.1:9531/"+"gdyb/five", bytes.NewReader(bytesData))
  1387. resp, _ := client.Do(req)
  1388. defer resp.Body.Close()
  1389. body, ioErr := ioutil.ReadAll(resp.Body)
  1390. if ioErr != nil {
  1391. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1393. return
  1394. }
  1395. var respJSON map[string]interface{}
  1396. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1397. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1399. return
  1400. }
  1401. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1402. userJSONBytes, _ := json.Marshal(respJSON)
  1403. var res ResultFour
  1404. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1405. utils.ErrorLog("解析失败:%v", err)
  1406. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1407. return
  1408. }
  1409. if res.Infcode == 0 {
  1410. order := &models.HisOrder{
  1411. UserOrgId: adminUser.CurrentOrgId,
  1412. HisPatientId: his.ID,
  1413. PatientId: his.PatientId,
  1414. SettleAccountsDate: recordDateTime,
  1415. Ctime: time.Now().Unix(),
  1416. Mtime: time.Now().Unix(),
  1417. Status: 1,
  1418. Number: chrg_bchno,
  1419. Infcode: res.Infcode,
  1420. WarnMsg: res.WarnMsg,
  1421. Cainfo: res.Cainfo,
  1422. ErrMsg: res.ErrMsg,
  1423. RespondTime: res.RefmsgTime,
  1424. InfRefmsgid: res.InfRefmsgid,
  1425. OrderStatus: 1,
  1426. }
  1427. err = service.CreateOrder(order)
  1428. if err != nil {
  1429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1430. return
  1431. }
  1432. for _, item := range res.Output.Result {
  1433. temp := strings.Split(item.FeedetlSn, "-")
  1434. var advice_id int64 = 0
  1435. var project_id int64 = 0
  1436. var types int64 = 0
  1437. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1438. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1439. if temp[1] == "1" {
  1440. advice_id = id
  1441. project_id = 0
  1442. } else if temp[1] == "2" {
  1443. advice_id = 0
  1444. project_id = id
  1445. }
  1446. info := &models.HisOrderInfo{
  1447. OrderNumber: order.Number,
  1448. FeedetlSn: item.FeedetlSn,
  1449. UploadDate: time.Now().Unix(),
  1450. AdviceId: advice_id,
  1451. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1452. Cnt: item.Cnt,
  1453. Pric: float64(item.Pric),
  1454. PatientId: his.PatientId,
  1455. PricUplmtAmt: item.PricUplmtAmt,
  1456. SelfpayProp: item.SelfpayProp,
  1457. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1458. OverlmtAmt: item.OverlmtAmt,
  1459. PreselfpayAmt: item.PreselfpayAmt,
  1460. BasMednFlag: item.BasMednFlag,
  1461. MedChrgitmType: item.MedChrgitmType,
  1462. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1463. Status: 1,
  1464. Memo: item.Memo,
  1465. Mtime: time.Now().Unix(),
  1466. InscpScpAmt: item.InscpScpAmt,
  1467. DrtReimFlag: item.DrtReimFlag,
  1468. Ctime: time.Now().Unix(),
  1469. ListSpItemFlag: item.ListSpItemFlag,
  1470. ChldMedcFlag: item.ChldMedcFlag,
  1471. LmtUsedFlag: item.LmtUsedFlag,
  1472. ChrgitmLv: item.ChrgitmLv,
  1473. UserOrgId: adminUser.CurrentOrgId,
  1474. HisPatientId: his.ID,
  1475. OrderId: order.ID,
  1476. ProjectId: project_id,
  1477. Type: types,
  1478. }
  1479. service.CreateOrderInfo(info)
  1480. }
  1481. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1482. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1483. var total float64
  1484. for _, item := range prescriptions {
  1485. if item.Type == 1 { //药品
  1486. for _, subItem := range item.HisDoctorAdviceInfo {
  1487. total = total + (subItem.Price * subItem.PrescribingNumber)
  1488. }
  1489. }
  1490. if item.Type == 2 { //项目
  1491. for _, subItem := range item.HisPrescriptionProject {
  1492. total = total + (subItem.Price * float64(subItem.Count))
  1493. }
  1494. }
  1495. }
  1496. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1497. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1498. allTotal := fmt.Sprintf("%.2f", total)
  1499. if res.Infcode == 0 {
  1500. var rf []*ResultFive
  1501. json.Unmarshal([]byte(his.Iinfo), &rf)
  1502. psn_no := his.PsnNo
  1503. mdtrt_id := his.Number
  1504. chrg_bchno := chrg_bchno
  1505. cert_no := his.Certno
  1506. insutype := rf[0].Insutype
  1507. api := "http://127.0.0.1:9531/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1508. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1509. "&total=" + allTotal + "&org_name=" + org.OrgName + "&doctor=" + patientPrescription.Doctor + "&fixmedins_code=" + miConfig.Code
  1510. resp, requestErr := http.Get(api)
  1511. if requestErr != nil {
  1512. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1513. return
  1514. }
  1515. defer resp.Body.Close()
  1516. body, ioErr := ioutil.ReadAll(resp.Body)
  1517. if ioErr != nil {
  1518. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1520. return
  1521. }
  1522. var respJSON map[string]interface{}
  1523. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1524. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1525. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1526. return
  1527. }
  1528. fmt.Println(respJSON)
  1529. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1530. userJSONBytes, _ := json.Marshal(respJSON)
  1531. var res ResultSeven
  1532. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1533. utils.ErrorLog("解析失败:%v", err)
  1534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1535. return
  1536. }
  1537. if res.Infcode == -1 {
  1538. errlog := &models.HisOrderError{
  1539. UserOrgId: adminUser.CurrentOrgId,
  1540. Ctime: time.Now().Unix(),
  1541. Mtime: time.Now().Unix(),
  1542. Number: chrg_bchno,
  1543. ErrMsg: res.ErrMsg,
  1544. Status: 1,
  1545. PatientId: id,
  1546. RecordTime: recordDateTime,
  1547. Stage: 7,
  1548. }
  1549. service.CreateErrMsgLog(errlog)
  1550. } else {
  1551. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1552. order.OrderStatus = 2
  1553. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1554. order.SetlId = res.Output.Setlinfo.SetlID
  1555. order.PsnNo = res.Output.Setlinfo.PsnNo
  1556. order.PsnName = res.Output.Setlinfo.PsnName
  1557. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1558. order.Certno = res.Output.Setlinfo.Certno
  1559. order.Gend = res.Output.Setlinfo.Gend
  1560. order.Naty = res.Output.Setlinfo.Naty
  1561. order.Age = res.Output.Setlinfo.Age
  1562. order.Insutype = res.Output.Setlinfo.Insutype
  1563. order.PsnType = res.Output.Setlinfo.PsnType
  1564. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1565. order.SetlTime = res.Output.Setlinfo.SetlTime
  1566. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1567. order.MedType = res.Output.Setlinfo.MedType
  1568. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1569. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1570. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1571. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1572. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1573. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1574. order.HifpPay = res.Output.Setlinfo.HifpPay
  1575. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1576. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1577. order.HifesPay = res.Output.Setlinfo.HifesPay
  1578. order.HifobPay = res.Output.Setlinfo.HifobPay
  1579. order.MafPay = res.Output.Setlinfo.MafPay
  1580. order.OthPay = res.Output.Setlinfo.OthPay
  1581. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1582. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1583. order.AcctPay = res.Output.Setlinfo.AcctPay
  1584. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1585. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1586. order.Balc = res.Output.Setlinfo.Balc
  1587. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1588. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1589. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1590. order.ClrWay = res.Output.Setlinfo.ClrWay
  1591. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1592. detailStr := string(setlDetail)
  1593. order.SetlDetail = detailStr
  1594. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1595. err = service.UpDateOrder(order)
  1596. if err == nil {
  1597. c.ServeSuccessJSON(map[string]interface{}{
  1598. "msg": "结算成功",
  1599. })
  1600. }
  1601. }
  1602. } else {
  1603. }
  1604. } else {
  1605. }
  1606. } else {
  1607. var total float64
  1608. for _, item := range prescriptions {
  1609. if item.Type == 1 { //药品
  1610. for _, subItem := range item.HisDoctorAdviceInfo {
  1611. total = total + (subItem.Price * subItem.PrescribingNumber)
  1612. }
  1613. }
  1614. if item.Type == 2 { //项目
  1615. for _, subItem := range item.HisPrescriptionProject {
  1616. total = total + (subItem.Price * float64(subItem.Count))
  1617. }
  1618. }
  1619. for _, subItem := range item.HisAdditionalCharge {
  1620. total = total + (subItem.Price * float64(subItem.Count))
  1621. }
  1622. }
  1623. allTotal := fmt.Sprintf("%.2f", total)
  1624. totals, _ := strconv.ParseFloat(allTotal, 64)
  1625. order := &models.HisOrder{
  1626. UserOrgId: adminUser.CurrentOrgId,
  1627. HisPatientId: his.ID,
  1628. PatientId: id,
  1629. SettleAccountsDate: recordDateTime,
  1630. Ctime: time.Now().Unix(),
  1631. Mtime: time.Now().Unix(),
  1632. Status: 1,
  1633. OrderStatus: 2,
  1634. Number: chrg_bchno,
  1635. MedfeeSumamt: totals,
  1636. }
  1637. err = service.CreateOrder(order)
  1638. if err != nil {
  1639. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1640. return
  1641. }
  1642. var customs []*Custom
  1643. for _, item := range prescriptions {
  1644. if item.Type == 1 { //药品
  1645. for _, subItem := range item.HisDoctorAdviceInfo {
  1646. cus := &Custom{
  1647. AdviceId: subItem.ID,
  1648. ProjectId: 0,
  1649. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1650. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1651. FeedetlSn: subItem.FeedetlSn,
  1652. Price: fmt.Sprintf("%.2f", subItem.Price),
  1653. MedListCodg: subItem.MedListCodg,
  1654. Type: 1,
  1655. }
  1656. customs = append(customs, cus)
  1657. }
  1658. }
  1659. if item.Type == 2 { //项目
  1660. for _, subItem := range item.HisPrescriptionProject {
  1661. cus := &Custom{
  1662. AdviceId: 0,
  1663. ProjectId: subItem.ID,
  1664. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1665. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1666. FeedetlSn: subItem.FeedetlSn,
  1667. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1668. MedListCodg: subItem.MedListCodg,
  1669. Type: 2,
  1670. }
  1671. customs = append(customs, cus)
  1672. }
  1673. }
  1674. for _, item := range item.HisAdditionalCharge {
  1675. cus := &Custom{
  1676. ItemId: item.ID,
  1677. AdviceId: 0,
  1678. ProjectId: 0,
  1679. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1680. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1681. FeedetlSn: item.FeedetlSn,
  1682. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1683. MedListCodg: item.XtHisAddtionConfig.Code,
  1684. Type: 3,
  1685. }
  1686. customs = append(customs, cus)
  1687. }
  1688. }
  1689. for _, item := range customs {
  1690. var advice_id int64 = 0
  1691. var project_id int64 = 0
  1692. var item_id int64 = 0
  1693. var types int64 = 0
  1694. if item.Type == 1 {
  1695. advice_id = item.AdviceId
  1696. project_id = 0
  1697. item_id = 0
  1698. } else if item.Type == 2 {
  1699. advice_id = 0
  1700. item_id = 0
  1701. project_id = item.ProjectId
  1702. } else if item.Type == 3 {
  1703. advice_id = 0
  1704. item_id = item.ItemId
  1705. project_id = 0
  1706. }
  1707. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1708. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1709. pric, _ := strconv.ParseFloat(item.Price, 32)
  1710. info := &models.HisOrderInfo{
  1711. OrderNumber: order.Number,
  1712. UploadDate: time.Now().Unix(),
  1713. AdviceId: advice_id,
  1714. DetItemFeeSumamt: detItemFeeSumamt,
  1715. Cnt: cut,
  1716. Pric: pric,
  1717. PatientId: id,
  1718. Status: 1,
  1719. Mtime: time.Now().Unix(),
  1720. Ctime: time.Now().Unix(),
  1721. UserOrgId: adminUser.CurrentOrgId,
  1722. HisPatientId: his.ID,
  1723. OrderId: order.ID,
  1724. ProjectId: project_id,
  1725. Type: types,
  1726. ItemId: item_id,
  1727. }
  1728. service.CreateOrderInfo(info)
  1729. }
  1730. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1731. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1732. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1733. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1734. if err == nil {
  1735. c.ServeSuccessJSON(map[string]interface{}{
  1736. "msg": "结算成功",
  1737. })
  1738. }
  1739. }
  1740. }
  1741. //退款
  1742. func (c *HisApiController) Refund() {
  1743. order_id, _ := c.GetInt64("order_id")
  1744. number := c.GetString("number")
  1745. adminUser := c.GetAdminUserInfo()
  1746. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1747. if config.IsOpen == 1 { //对接了医保,走医保流程
  1748. } else {
  1749. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  1750. if err == nil {
  1751. c.ServeSuccessJSON(map[string]interface{}{
  1752. "msg": "退费成功",
  1753. })
  1754. } else {
  1755. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1756. return
  1757. }
  1758. }
  1759. }
  1760. func (this *HisApiController) AdditionalCharge() {
  1761. dataBody := make(map[string]interface{}, 0)
  1762. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  1763. fmt.Println(err)
  1764. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  1765. patient_id := int64(dataBody["patient_id"].(float64))
  1766. medicineData, _ := dataBody["medicineData"].([]interface{})
  1767. adminUserInfo := this.GetAdminUserInfo()
  1768. orgId := adminUserInfo.CurrentOrgId
  1769. admin_user_id := adminUserInfo.AdminUser.Id
  1770. timeStr := time.Now().Format("2006-01-02")
  1771. timeLayout := "2006-01-02 15:04:05"
  1772. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  1773. timenow := timeStringToTime.Unix()
  1774. var additionalCharges []*models.HisAdditionalCharge
  1775. for _, item := range medicineData {
  1776. var randNum int
  1777. randNum = rand.Intn(10000) + 1000
  1778. timestamp := time.Now().Unix()
  1779. tempTime := time.Unix(timestamp, 0)
  1780. timeFormat := tempTime.Format("20060102150405")
  1781. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1782. items := item.(map[string]interface{})
  1783. money := items["price"].(string)
  1784. item_id_str := items["item_id"].(string)
  1785. name := items["name"].(string)
  1786. id_str := items["id"].(string)
  1787. moneys, _ := strconv.ParseInt(money, 10, 64)
  1788. monStr := strconv.FormatInt(moneys, 10)
  1789. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  1790. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  1791. id, _ := strconv.ParseInt(id_str, 10, 64)
  1792. additionalCharge := &models.HisAdditionalCharge{
  1793. ID: id,
  1794. HisPatientId: his_patient_id,
  1795. UserOrgId: orgId,
  1796. PatientId: patient_id,
  1797. RecordDate: timenow,
  1798. Price: monneyStr,
  1799. Status: 1,
  1800. ItemName: name,
  1801. ItemId: item_id,
  1802. AdminUserId: admin_user_id,
  1803. CreatedTime: time.Now().Unix(),
  1804. OrderStatus: 0,
  1805. PrescriptionNumber: "",
  1806. BatchNumber: "",
  1807. FeedetlSn: p_number,
  1808. }
  1809. service.CreateAdditionalCharge(additionalCharge)
  1810. additionalCharges = append(additionalCharges, additionalCharge)
  1811. }
  1812. this.ServeSuccessJSON(map[string]interface{}{
  1813. "msg": "添加成功",
  1814. "additional_charges": additionalCharges,
  1815. })
  1816. }
  1817. func (this *HisApiController) DeleteAddition() {
  1818. id, _ := this.GetInt64("id")
  1819. //TODO 需要判断是否已经结算
  1820. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  1821. if err == nil {
  1822. this.ServeSuccessJSON(map[string]interface{}{
  1823. "msg": "删除成功",
  1824. })
  1825. return
  1826. } else {
  1827. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1828. return
  1829. }
  1830. }
  1831. func (this *HisApiController) GetAdminUsers() {
  1832. adminUser := this.GetAdminUserInfo()
  1833. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  1834. this.ServeSuccessJSON(map[string]interface{}{
  1835. "doctors": doctors,
  1836. })
  1837. }