his_api_controller.go 103KB

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