his_api_controller.go 76KB

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