his_api_controller.go 90KB

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