his_api_controller.go 103KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916
  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. HifpPay float64 `json:"hifp_pay"`
  1124. HospPartAmt float64 `json:"hosp_part_amt"`
  1125. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1126. Insutype string `json:"insutype"`
  1127. MafPay float64 `json:"maf_pay"`
  1128. MdtrtCertType string `json:"mdtrt_cert_type"`
  1129. HifobPay float64 `json:"hifob_pay"`
  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. PsnName string `json:"psn_name"`
  1210. HifobPay float64 `json:"hifob_pay"`
  1211. Gend string `json:"gend"`
  1212. Brdy string `json:"brdy"`
  1213. PsnCertType string `json:"psn_cert_type"`
  1214. PsnType string `json:"psn_type"`
  1215. EmpName string `json:"emp_name"`
  1216. Certno string `json:"certno"`
  1217. Insutype string `json:"insutype"`
  1218. MedfeeSumamt float64 `json:"medfee_sumamt"`
  1219. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  1220. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  1221. PreselfpayAmt float64 `json:"preselfpay_amt"`
  1222. InscpScpAmt float64 `json:"inscp_scp_amt"`
  1223. ActPayDedc float64 `json:"act_pay_dedc"`
  1224. HifpPay float64 `json:"hifp_pay"`
  1225. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  1226. CvlservPay float64 `json:"cvlserv_pay"`
  1227. HifesPay float64 `json:"hifes_pay"`
  1228. HifmiPay float64 `json:"hifmi_pay"`
  1229. MafPay float64 `json:"maf_pay"`
  1230. OthPay float64 `json:"oth_pay"`
  1231. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  1232. PsnPay float64 `json:"psn_pay"`
  1233. AcctPay float64 `json:"acct_pay"`
  1234. CashPayamt float64 `json:"cash_payamt"`
  1235. Balc float64 `json:"balc"`
  1236. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  1237. MedinsSetlId string `json:"medins_setl_id"`
  1238. RefdSetlFlag string `json:"refd_setl_flag"`
  1239. SetlTime string `json:"setl_time"`
  1240. } `json:"setlinfo"`
  1241. } `json:"output"`
  1242. RefmsgTime string `json:"refmsg_time"`
  1243. RespondTime string `json:"respond_time"`
  1244. Signtype interface{} `json:"signtype"`
  1245. WarnMsg interface{} `json:"warn_msg"`
  1246. }
  1247. type Custom struct {
  1248. DetItemFeeSumamt string
  1249. Cut string
  1250. FeedetlSn string
  1251. Price string
  1252. MedListCodg string
  1253. Type int64
  1254. AdviceId int64
  1255. ProjectId int64
  1256. ItemId int64
  1257. }
  1258. //获取个人信息----挂号-----上传就诊信息
  1259. func (c *HisApiController) GetRegisterInfo() {
  1260. id, _ := c.GetInt64("id")
  1261. record_time := c.GetString("record_time")
  1262. name := c.GetString("name")
  1263. gender, _ := c.GetInt64("gender")
  1264. age, _ := c.GetInt64("age")
  1265. birthday := c.GetString("birthday")
  1266. phone := c.GetString("phone")
  1267. medical_care, _ := c.GetInt64("medical_care")
  1268. id_card := c.GetString("id_card")
  1269. register_type, _ := c.GetInt64("register_type")
  1270. registration_fee, _ := c.GetFloat("registration_fee")
  1271. medical_expenses, _ := c.GetFloat("medical_expenses")
  1272. certificates, _ := c.GetInt64("certificates")
  1273. settlementValue, _ := c.GetInt64("settlement_value")
  1274. social_type, _ := c.GetInt64("social_type")
  1275. medical_insurance_card := c.GetString("medical_insurance_card")
  1276. timeLayout := "2006-01-02"
  1277. loc, _ := time.LoadLocation("Local")
  1278. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  1279. birthUnix := birthdays.Unix()
  1280. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1281. if err != nil {
  1282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1283. return
  1284. }
  1285. recordDateTime := theTime.Unix()
  1286. adminInfo := c.GetAdminUserInfo()
  1287. patient, _ := service.GetPatientByID(adminInfo.CurrentOrgId, id)
  1288. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, id, recordDateTime)
  1289. miConfig, _ := service.FindMedicalInsuranceInfo(adminInfo.CurrentOrgId)
  1290. if patient == nil {
  1291. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  1292. return
  1293. }
  1294. if len(patient.IdCardNo) == 0 {
  1295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  1296. return
  1297. }
  1298. //org, _ := service.GetOrgById(adminInfo.CurrentOrgId)
  1299. config, _ := service.GetMedicalInsuranceConfig(adminInfo.CurrentOrgId)
  1300. if config.IsOpen == 1 {
  1301. 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
  1302. resp, requestErr := http.Get(api)
  1303. if requestErr != nil {
  1304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1305. return
  1306. }
  1307. defer resp.Body.Close()
  1308. body, ioErr := ioutil.ReadAll(resp.Body)
  1309. if ioErr != nil {
  1310. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1312. return
  1313. }
  1314. var respJSON map[string]interface{}
  1315. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1316. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1318. return
  1319. }
  1320. userJSON := respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1321. userJSONBytes, _ := json.Marshal(userJSON)
  1322. var res ResultTwo
  1323. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1324. utils.ErrorLog("解析失败:%v", err)
  1325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1326. return
  1327. }
  1328. Iinfos, _ := json.Marshal(res.Output.Iinfo)
  1329. Idetinfos, _ := json.Marshal(res.Output.Idetinfo)
  1330. infoStr := string(Iinfos)
  1331. idetinfoStr := string(Idetinfos)
  1332. his := models.VMHisPatient{
  1333. PsnNo: res.Output.Baseinfo.PsnNo,
  1334. PsnCertType: res.Output.Baseinfo.PsnCertType,
  1335. Certno: res.Output.Baseinfo.Certno,
  1336. PsnName: res.Output.Baseinfo.PsnName,
  1337. Gend: res.Output.Baseinfo.Gend,
  1338. Naty: res.Output.Baseinfo.Naty,
  1339. Brdy: res.Output.Baseinfo.Brdy,
  1340. Age: res.Output.Baseinfo.Age,
  1341. Iinfo: infoStr,
  1342. Idetinfo: idetinfoStr,
  1343. PatientId: patient.ID,
  1344. RecordDate: theTime.Unix(),
  1345. UserOrgId: adminInfo.CurrentOrgId,
  1346. AdminUserId: adminInfo.AdminUser.Id,
  1347. IsReturn: 1,
  1348. }
  1349. fmt.Println(his)
  1350. lastPatient, _ := service.GetLastPatient(adminInfo.CurrentOrgId)
  1351. timeStr := time.Now().Format("2006-01-02")
  1352. timeArr := strings.Split(timeStr, "-")
  1353. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(lastPatient.ID, 10)
  1354. hisPatient := models.HisPatient{
  1355. Number: str,
  1356. }
  1357. err = service.UpdateHisPatient(lastPatient.ID, hisPatient)
  1358. if res.Output.Iinfo == nil || len(res.Output.Iinfo) == 0 {
  1359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterOneException)
  1360. return
  1361. }
  1362. timestamp := time.Now().Unix()
  1363. tempTime := time.Unix(timestamp, 0)
  1364. timeFormat := tempTime.Format("20060102150405")
  1365. chrgBchno := rand.Intn(100000) + 10000
  1366. ipt_otp_no := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1367. count, _ := service.FindHisRegisterRecord(theTime.Unix(), patient.ID, adminInfo.CurrentOrgId)
  1368. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1369. //department_id := strconv.FormatInt(department.ID, 10)
  1370. doctor_id := strconv.FormatInt(patientPrescription.DoctorId, 10)
  1371. if count <= 0 {
  1372. api := "http://127.0.0.1:9532/" + "gdyb/two?cert_no=" + patient.IdCardNo + "&insutype=" +
  1373. res.Output.Iinfo[0].Insutype + "&psn_no=" + res.Output.Baseinfo.PsnNo +
  1374. "&org_name=" + miConfig.OrgName + "&doctor=" + patientPrescription.Doctor + "&ipt_otp_no=" + ipt_otp_no +
  1375. "&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
  1376. resp, requestErr := http.Get(api)
  1377. if requestErr != nil {
  1378. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1379. return
  1380. }
  1381. defer resp.Body.Close()
  1382. body, ioErr := ioutil.ReadAll(resp.Body)
  1383. if ioErr != nil {
  1384. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1385. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1386. return
  1387. }
  1388. var respJSON map[string]interface{}
  1389. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1390. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1391. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1392. return
  1393. }
  1394. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1395. userJSONBytes, _ := json.Marshal(respJSON)
  1396. var res ResultThree
  1397. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1398. utils.ErrorLog("解析失败:%v", err)
  1399. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1400. return
  1401. }
  1402. if res.Infcode == -1 {
  1403. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1404. return
  1405. }
  1406. fmt.Println("000!!!!!!")
  1407. fmt.Println(res)
  1408. fmt.Println(res.Output.Data.MdtrtID)
  1409. fmt.Println(res.Output.Data.PsnNo)
  1410. fmt.Println(res.Output.Data.IptOtpNo)
  1411. his.Number = res.Output.Data.MdtrtID
  1412. his.PsnNo = res.Output.Data.PsnNo
  1413. his.IptOtpNo = res.Output.Data.IptOtpNo
  1414. his.IdCardNo = patient.IdCardNo
  1415. his.PhoneNumber = patient.Phone
  1416. his.UserOrgId = adminInfo.CurrentOrgId
  1417. his.Status = 1
  1418. his.Ctime = time.Now().Unix()
  1419. his.Mtime = time.Now().Unix()
  1420. err := service.CreateHisPatientTwo(&his)
  1421. diagnosisConfig, _ := service.FindDiagnoseById(patientPrescription.Diagnosis)
  1422. if err == nil {
  1423. api := "http://127.0.0.1:9532/" + "gdyb/four?psn_no=" + his.PsnNo +
  1424. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&department=" + department.Name +
  1425. "&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 +
  1426. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1427. resp, requestErr := http.Get(api)
  1428. if requestErr != nil {
  1429. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1430. return
  1431. }
  1432. body, ioErr := ioutil.ReadAll(resp.Body)
  1433. if ioErr != nil {
  1434. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1436. return
  1437. }
  1438. var respJSON map[string]interface{}
  1439. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1440. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1441. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1442. return
  1443. }
  1444. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1445. userJSONBytes, _ := json.Marshal(respJSON)
  1446. fmt.Println(respJSON)
  1447. fmt.Println(userJSONBytes)
  1448. var res ResultSix
  1449. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1450. utils.ErrorLog("解析失败:%v", err)
  1451. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1452. return
  1453. }
  1454. if res.Infcode == -1 {
  1455. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRegisterTwoException)
  1456. return
  1457. }
  1458. c.ServeSuccessJSON(map[string]interface{}{
  1459. "his_info": his,
  1460. })
  1461. } else {
  1462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1463. return
  1464. }
  1465. }
  1466. } else {
  1467. timeStr := time.Now().Format("2006-01-02")
  1468. timeArr := strings.Split(timeStr, "-")
  1469. var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)
  1470. his, err := service.GetHisPatientInfo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  1471. var hisPatient models.XtHisPatient
  1472. if err == gorm.ErrRecordNotFound || his.ID == 0 {
  1473. hisPatient = models.XtHisPatient{
  1474. Name: name,
  1475. Age: age,
  1476. Gender: gender,
  1477. Birthday: birthUnix,
  1478. Phone: phone,
  1479. MedicalTreatmentType: medical_care,
  1480. IdType: certificates,
  1481. IdCardNo: id_card,
  1482. BalanceAccountsType: settlementValue,
  1483. SocialType: social_type,
  1484. MedicalInsuranceNumber: medical_insurance_card,
  1485. RegisterType: register_type,
  1486. RegisterCost: registration_fee,
  1487. TreatmentCost: medical_expenses,
  1488. AdminUserId: adminInfo.AdminUser.Id,
  1489. UserOrgId: adminInfo.CurrentOrgId,
  1490. Status: 1,
  1491. RecordDate: recordDateTime,
  1492. IsReturn: 1,
  1493. PatientId: patient.ID,
  1494. Ctime: time.Now().Unix(),
  1495. Mtime: time.Now().Unix(),
  1496. Number: str,
  1497. }
  1498. service.CreateHisPatient(&hisPatient)
  1499. }
  1500. c.ServeSuccessJSON(map[string]interface{}{
  1501. "his_info": hisPatient,
  1502. })
  1503. }
  1504. }
  1505. //上传明细----结算
  1506. func (c *HisApiController) GetUploadInfo() {
  1507. id, _ := c.GetInt64("id")
  1508. record_time := c.GetString("record_time")
  1509. pay_way, _ := c.GetInt64("pay_way")
  1510. pay_price, _ := c.GetFloat("pay_price")
  1511. pay_card_no := c.GetString("pay_card_no")
  1512. discount_price, _ := c.GetFloat("discount_price")
  1513. preferential_price, _ := c.GetFloat("preferential_price")
  1514. reality_price, _ := c.GetFloat("reality_price")
  1515. found_price, _ := c.GetFloat("found_price")
  1516. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  1517. private_price, _ := c.GetFloat("private_price")
  1518. timeLayout := "2006-01-02"
  1519. loc, _ := time.LoadLocation("Local")
  1520. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1521. if err != nil {
  1522. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1523. return
  1524. }
  1525. recordDateTime := theTime.Unix()
  1526. adminUser := c.GetAdminUserInfo()
  1527. prescriptions, _ := service.GetHisPrescription(adminUser.CurrentOrgId, id, recordDateTime)
  1528. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1529. timestamp := time.Now().Unix()
  1530. tempTime := time.Unix(timestamp, 0)
  1531. timeFormat := tempTime.Format("20060102150405")
  1532. chrgBchno := rand.Intn(100000) + 10000
  1533. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  1534. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1535. //org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1536. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1537. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  1538. strconv.FormatInt(his.PatientId, 10)
  1539. client := &http.Client{}
  1540. data := make(map[string]interface{})
  1541. data["psn_no"] = his.PsnNo
  1542. data["mdtrt_id"] = his.Number
  1543. data["pre"] = prescriptions
  1544. data["chrg_bchno"] = chrg_bchno
  1545. data["org_name"] = miConfig.OrgName
  1546. data["doctor"] = patientPrescription.Doctor
  1547. data["doctor_id"] = strconv.FormatInt(patientPrescription.DoctorId, 10)
  1548. data["dept"] = strconv.FormatInt(patientPrescription.Departments, 10)
  1549. data["fixmedins_code"] = miConfig.Code
  1550. data["dept_code"] = department.Number
  1551. data["insuplc_admdvs"] = miConfig.InsuplcAdmdvs
  1552. data["mdtrtarea_admvs"] = miConfig.MdtrtareaAdmvs
  1553. data["secret_key"] = miConfig.SecretKey
  1554. fmt.Println(his.PsnNo)
  1555. fmt.Println(his.Number)
  1556. fmt.Println(miConfig.OrgName)
  1557. fmt.Println(chrg_bchno)
  1558. fmt.Println(patientPrescription.Doctor)
  1559. fmt.Println(miConfig.Code)
  1560. fmt.Println(department.Number)
  1561. fmt.Println(strconv.FormatInt(patientPrescription.Departments, 10))
  1562. fmt.Println(miConfig.InsuplcAdmdvs)
  1563. fmt.Println(miConfig.MdtrtareaAdmvs)
  1564. fmt.Println(miConfig.SecretKey)
  1565. var ids []int64
  1566. //var idsTwo []int64
  1567. //
  1568. for _, item := range prescriptions {
  1569. ids = append(ids, item.ID)
  1570. }
  1571. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1572. if config.IsOpen == 1 { //对接了医保,走医保流程
  1573. bytesData, _ := json.Marshal(data)
  1574. req, _ := http.NewRequest("POST", "http://127.0.0.1:9532/"+"gdyb/five", bytes.NewReader(bytesData))
  1575. resp, _ := client.Do(req)
  1576. defer resp.Body.Close()
  1577. body, ioErr := ioutil.ReadAll(resp.Body)
  1578. if ioErr != nil {
  1579. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1580. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1581. return
  1582. }
  1583. var respJSON map[string]interface{}
  1584. if err := json.Unmarshal([]byte(body), &respJSON); err != nil {
  1585. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1586. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1587. return
  1588. }
  1589. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1590. userJSONBytes, _ := json.Marshal(respJSON)
  1591. var res ResultFour
  1592. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1593. utils.ErrorLog("解析失败:%v", err)
  1594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1595. return
  1596. }
  1597. if res.Infcode == 0 {
  1598. order := &models.HisOrder{
  1599. UserOrgId: adminUser.CurrentOrgId,
  1600. HisPatientId: his.ID,
  1601. PatientId: his.PatientId,
  1602. SettleAccountsDate: recordDateTime,
  1603. Ctime: time.Now().Unix(),
  1604. Mtime: time.Now().Unix(),
  1605. Status: 1,
  1606. Number: chrg_bchno,
  1607. Infcode: res.Infcode,
  1608. WarnMsg: res.WarnMsg,
  1609. Cainfo: res.Cainfo,
  1610. ErrMsg: res.ErrMsg,
  1611. RespondTime: res.RefmsgTime,
  1612. InfRefmsgid: res.InfRefmsgid,
  1613. OrderStatus: 1,
  1614. PayWay: pay_way,
  1615. PayPrice: pay_price,
  1616. PayCardNo: pay_card_no,
  1617. DiscountPrice: discount_price,
  1618. PreferentialPrice: preferential_price,
  1619. RealityPrice: reality_price,
  1620. FoundPrice: found_price,
  1621. MedicalInsurancePrice: medical_insurance_price,
  1622. PrivatePrice: private_price,
  1623. IsMedicineInsurance: 1,
  1624. }
  1625. err = service.CreateOrder(order)
  1626. if err != nil {
  1627. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1628. return
  1629. }
  1630. for _, item := range res.Output.Result {
  1631. temp := strings.Split(item.FeedetlSn, "-")
  1632. var advice_id int64 = 0
  1633. var project_id int64 = 0
  1634. var types int64 = 0
  1635. id, _ := strconv.ParseInt(temp[2], 10, 64)
  1636. types, _ = strconv.ParseInt(temp[1], 10, 64)
  1637. if temp[1] == "1" {
  1638. advice_id = id
  1639. project_id = 0
  1640. } else if temp[1] == "2" {
  1641. advice_id = 0
  1642. project_id = id
  1643. }
  1644. info := &models.HisOrderInfo{
  1645. OrderNumber: order.Number,
  1646. FeedetlSn: item.FeedetlSn,
  1647. UploadDate: time.Now().Unix(),
  1648. AdviceId: advice_id,
  1649. DetItemFeeSumamt: item.DetItemFeeSumamt,
  1650. Cnt: item.Cnt,
  1651. Pric: float64(item.Pric),
  1652. PatientId: his.PatientId,
  1653. PricUplmtAmt: item.PricUplmtAmt,
  1654. SelfpayProp: item.SelfpayProp,
  1655. FulamtOwnpayAmt: item.FulamtOwnpayAmt,
  1656. OverlmtAmt: item.OverlmtAmt,
  1657. PreselfpayAmt: item.PreselfpayAmt,
  1658. BasMednFlag: item.BasMednFlag,
  1659. MedChrgitmType: item.MedChrgitmType,
  1660. HiNegoDrugFlag: item.HiNegoDrugFlag,
  1661. Status: 1,
  1662. Memo: item.Memo,
  1663. Mtime: time.Now().Unix(),
  1664. InscpScpAmt: item.InscpScpAmt,
  1665. DrtReimFlag: item.DrtReimFlag,
  1666. Ctime: time.Now().Unix(),
  1667. ListSpItemFlag: item.ListSpItemFlag,
  1668. ChldMedcFlag: item.ChldMedcFlag,
  1669. LmtUsedFlag: item.LmtUsedFlag,
  1670. ChrgitmLv: item.ChrgitmLv,
  1671. UserOrgId: adminUser.CurrentOrgId,
  1672. HisPatientId: his.ID,
  1673. OrderId: order.ID,
  1674. ProjectId: project_id,
  1675. Type: types,
  1676. }
  1677. service.CreateOrderInfo(info)
  1678. }
  1679. service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1680. service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, patientPrescription.PatientId, chrg_bchno, recordDateTime)
  1681. var total float64
  1682. for _, item := range prescriptions {
  1683. if item.Type == 1 { //药品
  1684. for _, subItem := range item.HisDoctorAdviceInfo {
  1685. total = total + (subItem.Price * subItem.PrescribingNumber)
  1686. }
  1687. }
  1688. if item.Type == 2 { //项目
  1689. for _, subItem := range item.HisPrescriptionProject {
  1690. total = total + (subItem.Price * float64(subItem.Count))
  1691. }
  1692. }
  1693. }
  1694. //org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1695. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, id, recordDateTime)
  1696. allTotal := fmt.Sprintf("%.2f", total)
  1697. if res.Infcode == 0 {
  1698. var rf []*ResultFive
  1699. json.Unmarshal([]byte(his.Iinfo), &rf)
  1700. psn_no := his.PsnNo
  1701. mdtrt_id := his.Number
  1702. chrg_bchno := chrg_bchno
  1703. cert_no := his.Certno
  1704. insutype := rf[0].Insutype
  1705. api := "http://127.0.0.1:9532/" + "gdyb/eight?cert_no=" + cert_no + "&insutype=" +
  1706. insutype + "&psn_no=" + psn_no + "&chrg_bchno=" + chrg_bchno + "&mdtrt_id=" + mdtrt_id +
  1707. "&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
  1708. resp, requestErr := http.Get(api)
  1709. if requestErr != nil {
  1710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1711. return
  1712. }
  1713. defer resp.Body.Close()
  1714. body, ioErr := ioutil.ReadAll(resp.Body)
  1715. if ioErr != nil {
  1716. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1718. return
  1719. }
  1720. var respJSON map[string]interface{}
  1721. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1722. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1724. return
  1725. }
  1726. fmt.Println(respJSON)
  1727. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1728. userJSONBytes, _ := json.Marshal(respJSON)
  1729. var res ResultSeven
  1730. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  1731. utils.ErrorLog("解析失败:%v", err)
  1732. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1733. return
  1734. }
  1735. if res.Infcode == -1 {
  1736. errlog := &models.HisOrderError{
  1737. UserOrgId: adminUser.CurrentOrgId,
  1738. Ctime: time.Now().Unix(),
  1739. Mtime: time.Now().Unix(),
  1740. Number: chrg_bchno,
  1741. ErrMsg: res.ErrMsg,
  1742. Status: 1,
  1743. PatientId: id,
  1744. RecordTime: recordDateTime,
  1745. Stage: 7,
  1746. }
  1747. service.CreateErrMsgLog(errlog)
  1748. } else {
  1749. order, _ := service.GetHisOrderTwo(adminUser.CurrentOrgId, chrg_bchno, id)
  1750. order.OrderStatus = 2
  1751. order.MdtrtId = res.Output.Setlinfo.MdtrtID
  1752. order.SetlId = res.Output.Setlinfo.SetlID
  1753. order.PsnNo = res.Output.Setlinfo.PsnNo
  1754. order.PsnName = res.Output.Setlinfo.PsnName
  1755. order.PsnCertType = res.Output.Setlinfo.PsnCertType
  1756. order.Certno = res.Output.Setlinfo.Certno
  1757. order.Gend = res.Output.Setlinfo.Gend
  1758. order.Naty = res.Output.Setlinfo.Naty
  1759. order.Age = res.Output.Setlinfo.Age
  1760. order.Insutype = res.Output.Setlinfo.Insutype
  1761. order.PsnType = res.Output.Setlinfo.PsnType
  1762. order.CvlservFlag = res.Output.Setlinfo.CvlservFlag
  1763. order.SetlTime = res.Output.Setlinfo.SetlTime
  1764. order.MdtrtCertType = res.Output.Setlinfo.MdtrtCertType
  1765. order.MedType = res.Output.Setlinfo.MedType
  1766. order.MedfeeSumamt = res.Output.Setlinfo.MedfeeSumamt
  1767. order.FulamtOwnpayAmt = res.Output.Setlinfo.FulamtOwnpayAmt
  1768. order.OverlmtSelfPay = res.Output.Setlinfo.OverlmtSelfpay
  1769. order.PreselfpayAmt = res.Output.Setlinfo.PreselfpayAmt
  1770. order.InscpScpAmt = res.Output.Setlinfo.InscpScpAmt
  1771. order.ActPayDedc = res.Output.Setlinfo.ActPayDedc
  1772. order.HifpPay = res.Output.Setlinfo.HifpPay
  1773. order.CvlservPay = res.Output.Setlinfo.CvlservPay
  1774. order.PoolPropSelfpay = res.Output.Setlinfo.PoolPropSelfpay
  1775. order.HifesPay = res.Output.Setlinfo.HifesPay
  1776. order.HifobPay = res.Output.Setlinfo.HifobPay
  1777. order.MafPay = res.Output.Setlinfo.MafPay
  1778. order.OthPay = res.Output.Setlinfo.OthPay
  1779. order.FundPaySumamt = res.Output.Setlinfo.FundPaySumamt
  1780. order.PsnPartAmt = res.Output.Setlinfo.PsnPartAmt
  1781. order.AcctPay = res.Output.Setlinfo.AcctPay
  1782. order.PsnCashPay = res.Output.Setlinfo.PsnCashPay
  1783. order.HospPartAmt = res.Output.Setlinfo.HospPartAmt
  1784. order.Balc = res.Output.Setlinfo.Balc
  1785. order.AcctMulaidPay = res.Output.Setlinfo.AcctMulaidPay
  1786. order.MedinsSetlId = res.Output.Setlinfo.MedinsSetlID
  1787. order.ClrOptins = res.Output.Setlinfo.ClrOptins
  1788. order.ClrWay = res.Output.Setlinfo.ClrWay
  1789. setlDetail, _ := json.Marshal(res.Output.Setldetail)
  1790. detailStr := string(setlDetail)
  1791. order.SetlDetail = detailStr
  1792. err := service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1793. err = service.UpDateOrder(order)
  1794. if err == nil {
  1795. c.ServeSuccessJSON(map[string]interface{}{
  1796. "msg": "结算成功",
  1797. })
  1798. }
  1799. }
  1800. } else {
  1801. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCalOrderException)
  1802. return
  1803. }
  1804. } else {
  1805. }
  1806. } else {
  1807. var total float64
  1808. for _, item := range prescriptions {
  1809. if item.Type == 1 { //药品
  1810. for _, subItem := range item.HisDoctorAdviceInfo {
  1811. total = total + (subItem.Price * subItem.PrescribingNumber)
  1812. }
  1813. }
  1814. if item.Type == 2 { //项目
  1815. for _, subItem := range item.HisPrescriptionProject {
  1816. total = total + (subItem.Price * float64(subItem.Count))
  1817. }
  1818. }
  1819. for _, subItem := range item.HisAdditionalCharge {
  1820. total = total + (subItem.Price * float64(subItem.Count))
  1821. }
  1822. }
  1823. allTotal := fmt.Sprintf("%.2f", total)
  1824. totals, _ := strconv.ParseFloat(allTotal, 64)
  1825. order := &models.HisOrder{
  1826. UserOrgId: adminUser.CurrentOrgId,
  1827. HisPatientId: his.ID,
  1828. PatientId: id,
  1829. SettleAccountsDate: recordDateTime,
  1830. Ctime: time.Now().Unix(),
  1831. Mtime: time.Now().Unix(),
  1832. Status: 1,
  1833. OrderStatus: 2,
  1834. Number: chrg_bchno,
  1835. MedfeeSumamt: totals,
  1836. PayWay: pay_way,
  1837. PayPrice: pay_price,
  1838. PayCardNo: pay_card_no,
  1839. DiscountPrice: discount_price,
  1840. PreferentialPrice: preferential_price,
  1841. RealityPrice: reality_price,
  1842. FoundPrice: found_price,
  1843. MedicalInsurancePrice: medical_insurance_price,
  1844. PrivatePrice: private_price,
  1845. }
  1846. err = service.CreateOrder(order)
  1847. if err != nil {
  1848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  1849. return
  1850. }
  1851. var customs []*Custom
  1852. for _, item := range prescriptions {
  1853. if item.Type == 1 { //药品
  1854. for _, subItem := range item.HisDoctorAdviceInfo {
  1855. cus := &Custom{
  1856. AdviceId: subItem.ID,
  1857. ProjectId: 0,
  1858. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  1859. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  1860. FeedetlSn: subItem.FeedetlSn,
  1861. Price: fmt.Sprintf("%.2f", subItem.Price),
  1862. MedListCodg: subItem.MedListCodg,
  1863. Type: 1,
  1864. }
  1865. customs = append(customs, cus)
  1866. }
  1867. }
  1868. if item.Type == 2 { //项目
  1869. for _, subItem := range item.HisPrescriptionProject {
  1870. cus := &Custom{
  1871. AdviceId: 0,
  1872. ProjectId: subItem.ID,
  1873. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  1874. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  1875. FeedetlSn: subItem.FeedetlSn,
  1876. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  1877. MedListCodg: subItem.MedListCodg,
  1878. Type: 2,
  1879. }
  1880. customs = append(customs, cus)
  1881. }
  1882. }
  1883. for _, item := range item.HisAdditionalCharge {
  1884. cus := &Custom{
  1885. ItemId: item.ID,
  1886. AdviceId: 0,
  1887. ProjectId: 0,
  1888. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  1889. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  1890. FeedetlSn: item.FeedetlSn,
  1891. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  1892. MedListCodg: item.XtHisAddtionConfig.Code,
  1893. Type: 3,
  1894. }
  1895. customs = append(customs, cus)
  1896. }
  1897. }
  1898. for _, item := range customs {
  1899. var advice_id int64 = 0
  1900. var project_id int64 = 0
  1901. var item_id int64 = 0
  1902. var types int64 = 0
  1903. if item.Type == 1 {
  1904. advice_id = item.AdviceId
  1905. project_id = 0
  1906. item_id = 0
  1907. } else if item.Type == 2 {
  1908. advice_id = 0
  1909. item_id = 0
  1910. project_id = item.ProjectId
  1911. } else if item.Type == 3 {
  1912. advice_id = 0
  1913. item_id = item.ItemId
  1914. project_id = 0
  1915. }
  1916. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  1917. cut, _ := strconv.ParseFloat(item.Cut, 32)
  1918. pric, _ := strconv.ParseFloat(item.Price, 32)
  1919. info := &models.HisOrderInfo{
  1920. OrderNumber: order.Number,
  1921. UploadDate: time.Now().Unix(),
  1922. AdviceId: advice_id,
  1923. DetItemFeeSumamt: detItemFeeSumamt,
  1924. Cnt: cut,
  1925. Pric: pric,
  1926. PatientId: id,
  1927. Status: 1,
  1928. Mtime: time.Now().Unix(),
  1929. Ctime: time.Now().Unix(),
  1930. UserOrgId: adminUser.CurrentOrgId,
  1931. HisPatientId: his.ID,
  1932. OrderId: order.ID,
  1933. ProjectId: project_id,
  1934. Type: types,
  1935. ItemId: item_id,
  1936. }
  1937. service.CreateOrderInfo(info)
  1938. }
  1939. //err := service.UpDateAddtionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1940. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  1941. err = service.UpDatePrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime)
  1942. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  1943. if err == nil {
  1944. c.ServeSuccessJSON(map[string]interface{}{
  1945. "msg": "结算成功",
  1946. })
  1947. }
  1948. }
  1949. }
  1950. //退款
  1951. func (c *HisApiController) Refund() {
  1952. order_id, _ := c.GetInt64("order_id")
  1953. number := c.GetString("number")
  1954. record_time := c.GetString("record_time")
  1955. patient_id, _ := c.GetInt64("patient_id")
  1956. timeLayout := "2006-01-02"
  1957. loc, _ := time.LoadLocation("Local")
  1958. adminUser := c.GetAdminUserInfo()
  1959. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  1960. fmt.Println(err)
  1961. if err != nil {
  1962. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1963. return
  1964. }
  1965. recordDateTime := theTime.Unix()
  1966. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1967. patientPrescription, _ := service.FindPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, recordDateTime)
  1968. order, _ := service.GetHisOrderByID(order_id)
  1969. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  1970. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1971. if config.IsOpen == 1 { //对接了医保,走医保流程
  1972. api := "http://127.0.0.1:9532/" + "gdyb/nine?psn_no=" + his.PsnNo +
  1973. "&mdtrt_id=" + his.Number + "&doctor=" + patientPrescription.Doctor + "&setl_id=" + order.SetlId + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1974. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1975. resp, requestErr := http.Get(api)
  1976. if requestErr != nil {
  1977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1978. return
  1979. }
  1980. body, ioErr := ioutil.ReadAll(resp.Body)
  1981. if ioErr != nil {
  1982. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  1983. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1984. return
  1985. }
  1986. var respJSON map[string]interface{}
  1987. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  1988. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  1989. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1990. return
  1991. }
  1992. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  1993. userJSONBytes, _ := json.Marshal(respJSON)
  1994. fmt.Println(respJSON)
  1995. fmt.Println(userJSONBytes)
  1996. api2 := "http://127.0.0.1:9532/" + "gdyb/six?psn_no=" + his.PsnNo +
  1997. "&mdtrt_id=" + his.Number + "&chrg_bchno=" + order.Number + "&doctor=" + patientPrescription.Doctor + "&org_name=" + miConfig.OrgName + "&fixmedins_code=" + miConfig.Code +
  1998. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs + "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs + "&secret_key=" + miConfig.SecretKey
  1999. resp2, requestErr2 := http.Get(api2)
  2000. if requestErr2 != nil {
  2001. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2002. return
  2003. }
  2004. body2, ioErr2 := ioutil.ReadAll(resp2.Body)
  2005. if ioErr2 != nil {
  2006. utils.ErrorLog("接口返回数据读取失败: %v", ioErr2)
  2007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2008. return
  2009. }
  2010. var respJSON2 map[string]interface{}
  2011. if err := json.Unmarshal([]byte(string(body2)), &respJSON2); err != nil {
  2012. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2014. return
  2015. }
  2016. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2017. if err == nil {
  2018. c.ServeSuccessJSON(map[string]interface{}{
  2019. "msg": "退费成功",
  2020. })
  2021. } else {
  2022. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2023. return
  2024. }
  2025. } else {
  2026. err := service.UpdataOrderStatus(order_id, number, adminUser.CurrentOrgId)
  2027. if err == nil {
  2028. c.ServeSuccessJSON(map[string]interface{}{
  2029. "msg": "退费成功",
  2030. })
  2031. } else {
  2032. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2033. return
  2034. }
  2035. }
  2036. }
  2037. //对账
  2038. func (c *HisApiController) GetCheckAccount() {
  2039. start_time := c.GetString("start_time")
  2040. end_time := c.GetString("end_time")
  2041. insutype := c.GetString("insutype")
  2042. clr_type := c.GetString("clr_type")
  2043. adminUser := c.GetAdminUserInfo()
  2044. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2045. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2046. timeLayout := "2006-01-02"
  2047. loc, _ := time.LoadLocation("Local")
  2048. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2049. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2050. orders, _ := service.GetOrderByTime(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId, insutype, clr_type)
  2051. decimal.DivisionPrecision = 2
  2052. var medfee_sumamt float64
  2053. var acct_pay float64
  2054. var fund_pay_sumamt float64
  2055. fixmedins_setl_cnt := int64(len(orders))
  2056. for _, item := range orders {
  2057. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  2058. acct_pay, _ = decimal.NewFromFloat(acct_pay).Add(decimal.NewFromFloat(item.AcctPay)).Float64()
  2059. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  2060. }
  2061. var user_name string
  2062. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2063. if role.ID == 0 {
  2064. user_name = "xxx"
  2065. } else {
  2066. user_name = role.UserName
  2067. }
  2068. if config.IsOpen == 1 {
  2069. api := "http://127.0.0.1:9532/" + "gdyb/ten?" +
  2070. "insutype=" + insutype +
  2071. "&clr_type=" + clr_type +
  2072. "&setl_optins=" + miConfig.OrgName +
  2073. "&stmt_begndate=" + start_time +
  2074. "&stm_enddate=" + end_time +
  2075. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2076. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2077. "&acct_pay=" + fmt.Sprintf("%.2f", acct_pay) +
  2078. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2079. "&fixmedins_code=" + miConfig.Code +
  2080. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2081. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2082. "&secret_key=" + miConfig.SecretKey +
  2083. "&org_name=" + miConfig.OrgName +
  2084. "&doctor=" + user_name
  2085. fmt.Println(api)
  2086. resp, requestErr := http.Get(api)
  2087. if requestErr != nil {
  2088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2089. return
  2090. }
  2091. body, ioErr := ioutil.ReadAll(resp.Body)
  2092. fmt.Println(body)
  2093. if ioErr != nil {
  2094. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2095. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2096. return
  2097. }
  2098. var respJSON map[string]interface{}
  2099. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2100. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2101. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2102. return
  2103. }
  2104. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2105. userJSONBytes, _ := json.Marshal(respJSON)
  2106. var res ResultEight
  2107. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2108. utils.ErrorLog("解析失败:%v", err)
  2109. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2110. return
  2111. }
  2112. if res.Infcode == 0 {
  2113. c.ServeSuccessJSON(map[string]interface{}{
  2114. "stmt_rslt": res.Output.Stmtinfo.StmtRslt,
  2115. "stmt_rslt_dscr": res.Output.Stmtinfo.StmtRsltDscr,
  2116. })
  2117. } else {
  2118. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2119. }
  2120. }
  2121. }
  2122. //对账明细
  2123. func (c *HisApiController) GetCheckDetailAccount() {
  2124. start_time := c.GetString("start_time")
  2125. end_time := c.GetString("end_time")
  2126. adminUser := c.GetAdminUserInfo()
  2127. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2128. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2129. timeLayout := "2006-01-02"
  2130. loc, _ := time.LoadLocation("Local")
  2131. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2132. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2133. orders, _ := service.GetOrderByTimeTwo(startime.Unix(), endtime.Unix(), adminUser.CurrentOrgId)
  2134. Mkdir(miConfig.OrgName)
  2135. file := strconv.FormatInt(adminUser.CurrentOrgId, 10) + strconv.FormatInt(time.Now().Unix(), 10)
  2136. file_name := file + ".txt"
  2137. zip_name := file + ".zip"
  2138. zip_path := miConfig.OrgName + "/" + zip_name
  2139. file_path := miConfig.OrgName + "/" + file_name
  2140. decimal.DivisionPrecision = 2
  2141. var medfee_sumamt float64
  2142. var psn_cash_pay float64
  2143. var fund_pay_sumamt float64
  2144. fixmedins_setl_cnt := int64(len(orders))
  2145. for _, item := range orders {
  2146. medfee_sumamt, _ = decimal.NewFromFloat(medfee_sumamt).Add(decimal.NewFromFloat(item.MedfeeSumamt)).Float64()
  2147. psn_cash_pay, _ = decimal.NewFromFloat(psn_cash_pay).Add(decimal.NewFromFloat(item.PsnCashPay)).Float64()
  2148. fund_pay_sumamt, _ = decimal.NewFromFloat(fund_pay_sumamt).Add(decimal.NewFromFloat(item.FundPaySumamt)).Float64()
  2149. }
  2150. f, err := os.Create(miConfig.OrgName + "/" + file_name)
  2151. defer f.Close()
  2152. if err != nil {
  2153. fmt.Println(err.Error())
  2154. } else {
  2155. for _, item := range orders {
  2156. var refd_setl_flag string
  2157. if item.OrderStatus == 2 {
  2158. refd_setl_flag = "0"
  2159. }
  2160. if item.OrderStatus == 3 {
  2161. refd_setl_flag = "1"
  2162. }
  2163. var str string
  2164. str = item.SetlId + " " +
  2165. item.MdtrtId + " " +
  2166. item.PsnNo + " " +
  2167. fmt.Sprintf("%.2f", item.MedfeeSumamt) + " " +
  2168. fmt.Sprintf("%.2f", item.FundPaySumamt) + " " +
  2169. fmt.Sprintf("%.2f", item.AcctPay) + " " + refd_setl_flag + "\n"
  2170. _, err = f.Write([]byte(str))
  2171. }
  2172. }
  2173. Zip(file_path, zip_path)
  2174. fmt.Println(ReadFile(zip_path))
  2175. fmt.Println(string(ReadFile(zip_path)))
  2176. if config.IsOpen == 1 {
  2177. var user_name string
  2178. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2179. if role.ID == 0 {
  2180. user_name = "xxx"
  2181. } else {
  2182. user_name = role.UserName
  2183. }
  2184. baseParams := models.BaseParams{
  2185. SecretKey: miConfig.SecretKey,
  2186. FixmedinsCode: miConfig.Code,
  2187. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2188. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2189. OrgName: miConfig.OrgName,
  2190. Doctor: user_name,
  2191. }
  2192. result := service.Gdyb9101(baseParams, zip_name, ReadFile(zip_path))
  2193. var dat map[string]interface{}
  2194. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2195. fmt.Println(dat)
  2196. } else {
  2197. fmt.Println(err)
  2198. }
  2199. userJSONBytes, _ := json.Marshal(dat)
  2200. var res ResultNine
  2201. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2202. utils.ErrorLog("解析失败:%v", err)
  2203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2204. return
  2205. }
  2206. if res.Infcode == 0 {
  2207. api := "http://127.0.0.1:9532/" + "gdyb/twelve?" +
  2208. "file_qury_no=" + res.Output.FileQuryNo +
  2209. "&setl_optins=" + miConfig.OrgName +
  2210. "&stmt_begndate=" + start_time +
  2211. "&stm_enddate=" + end_time +
  2212. "&medfee_sumamt=" + fmt.Sprintf("%.2f", medfee_sumamt) +
  2213. "&fund_pay_sumamt=" + fmt.Sprintf("%.2f", fund_pay_sumamt) +
  2214. "&cash_payamt=" + fmt.Sprintf("%.2f", psn_cash_pay) +
  2215. "&fixmedins_setl_cnt=" + strconv.FormatInt(fixmedins_setl_cnt, 10) +
  2216. "&fixmedins_code=" + miConfig.Code +
  2217. "&insuplc_admdvs=" + miConfig.InsuplcAdmdvs +
  2218. "&mdtrtarea_admvs=" + miConfig.MdtrtareaAdmvs +
  2219. "&secret_key=" + miConfig.SecretKey +
  2220. "&org_name=" + miConfig.OrgName +
  2221. "&doctor=" + user_name
  2222. resp, requestErr := http.Get(api)
  2223. if requestErr != nil {
  2224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2225. return
  2226. }
  2227. body, ioErr := ioutil.ReadAll(resp.Body)
  2228. if ioErr != nil {
  2229. utils.ErrorLog("接口返回数据读取失败: %v", ioErr)
  2230. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2231. return
  2232. }
  2233. var respJSON map[string]interface{}
  2234. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  2235. utils.ErrorLog("接口返回数据解析JSON失败: %v", err)
  2236. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2237. return
  2238. }
  2239. respJSON = respJSON["data"].(map[string]interface{})["pre"].(map[string]interface{})
  2240. userJSONBytes, _ := json.Marshal(respJSON)
  2241. var res ResultTen
  2242. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2243. utils.ErrorLog("解析失败:%v", err)
  2244. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2245. return
  2246. }
  2247. if res.Infcode == 0 {
  2248. service.Gdyb9102(baseParams, zip_name, res.Output.FileQuryNo)
  2249. c.ServeSuccessJSON(map[string]interface{}{
  2250. "msg": "明细对账成功",
  2251. })
  2252. }
  2253. } else {
  2254. }
  2255. }
  2256. }
  2257. func (c *HisApiController) GetSettleAccounts() {
  2258. //id, _ := c.GetInt64("id")
  2259. //record_time := c.GetString("record_time")
  2260. order_id, _ := c.GetInt64("order_id")
  2261. //timeLayout := "2006-01-02"
  2262. //loc, _ := time.LoadLocation("Local")
  2263. //
  2264. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2265. //if err != nil {
  2266. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2267. // return
  2268. //}
  2269. //recordDateTime := theTime.Unix()
  2270. adminUser := c.GetAdminUserInfo()
  2271. //his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, id, recordDateTime)
  2272. order, _ := service.GetHisOrderByID(order_id)
  2273. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  2274. var bedCostTotal float64 = 0 //床位总费
  2275. var bedCostSelfTotal float64 = 0 //床位自费
  2276. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  2277. var operationCostTotal float64 = 0 //手术费
  2278. var operationCostSelfTotal float64 = 0 //手术费
  2279. var operationCostPartSelfTotal float64 = 0 //手术费
  2280. var otherCostTotal float64 = 0 //其他费用
  2281. var otherCostSelfTotal float64 = 0 //其他费用
  2282. var otherCostPartSelfTotal float64 = 0 //其他费用
  2283. var materialCostTotal float64 = 0 //材料费
  2284. var materialCostSelfTotal float64 = 0 //材料费
  2285. var materialCostPartSelfTotal float64 = 0 //材料费
  2286. var westernMedicineCostTotal float64 = 0 //西药费
  2287. var westernMedicineCostSelfTotal float64 = 0 //西药费
  2288. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  2289. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  2290. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  2291. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  2292. var checkCostTotal float64 = 0 //检查费
  2293. var checkCostSelfTotal float64 = 0 //检查费
  2294. var checkCostPartSelfTotal float64 = 0 //检查费
  2295. var laboratoryCostTotal float64 = 0 //化验费
  2296. var laboratoryCostSelfTotal float64 = 0 //化验费
  2297. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  2298. var treatCostTotal float64 = 0 //治疗费用
  2299. var treatCostSelfTotal float64 = 0 //治疗费用
  2300. var treatCostPartSelfTotal float64 = 0 //治疗费用
  2301. decimal.DivisionPrecision = 2
  2302. for _, item := range orderInfos {
  2303. if item.MedChrgitmType == "01" { //床位费
  2304. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2305. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2306. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2307. }
  2308. if item.MedChrgitmType == "03" { //检查费
  2309. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2310. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2311. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2312. }
  2313. if item.MedChrgitmType == "04" { //化验费
  2314. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2315. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2316. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2317. }
  2318. if item.MedChrgitmType == "05" { //治疗费
  2319. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2320. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2321. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2322. }
  2323. if item.MedChrgitmType == "06" { //手术费
  2324. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2325. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2326. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2327. }
  2328. if item.MedChrgitmType == "08" { //材料费
  2329. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2330. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2331. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2332. }
  2333. if item.MedChrgitmType == "09" { //西药费
  2334. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2335. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2336. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2337. }
  2338. if item.MedChrgitmType == "11" { //中成费
  2339. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2340. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2341. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2342. }
  2343. if item.MedChrgitmType == "14" { //其他费
  2344. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  2345. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2346. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  2347. }
  2348. }
  2349. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  2350. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2351. var user_name string
  2352. role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  2353. if role.ID == 0 {
  2354. user_name = "xxx"
  2355. } else {
  2356. user_name = role.UserName
  2357. }
  2358. baseParams := models.BaseParams{
  2359. SecretKey: miConfig.SecretKey,
  2360. FixmedinsCode: miConfig.Code,
  2361. InsuplcAdmdvs: miConfig.InsuplcAdmdvs,
  2362. MdtrtareaAdmvs: miConfig.MdtrtareaAdmvs,
  2363. OrgName: miConfig.OrgName,
  2364. Doctor: user_name,
  2365. }
  2366. businessParams := models.BusinessParams{
  2367. PsnNo: order.PsnNo,
  2368. MdtrtId: order.MdtrtId,
  2369. SetlId: order.SetlId,
  2370. }
  2371. if config.IsOpen == 1 {
  2372. result := service.Gdyb5203(baseParams, businessParams)
  2373. var dat map[string]interface{}
  2374. if err := json.Unmarshal([]byte(result), &dat); err == nil {
  2375. fmt.Println(dat)
  2376. } else {
  2377. fmt.Println(err)
  2378. }
  2379. userJSONBytes, _ := json.Marshal(dat)
  2380. var res ResultEleven
  2381. if err := json.Unmarshal(userJSONBytes, &res); err != nil {
  2382. utils.ErrorLog("解析失败:%v", err)
  2383. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2384. return
  2385. }
  2386. if res.Infcode == 0 {
  2387. c.ServeSuccessJSON(map[string]interface{}{
  2388. "info": res.Output.Setlinfo,
  2389. "bedCostTotal": bedCostTotal,
  2390. "bedCostSelfTotal": bedCostSelfTotal,
  2391. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  2392. "operationCostTotal": operationCostTotal,
  2393. "operationCostSelfTotal": operationCostSelfTotal,
  2394. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  2395. "otherCostTotal": otherCostTotal,
  2396. "otherCostSelfTotal": otherCostSelfTotal,
  2397. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  2398. "materialCostTotal": materialCostTotal,
  2399. "materialCostSelfTotal": materialCostSelfTotal,
  2400. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  2401. "westernMedicineCostTotal": westernMedicineCostTotal,
  2402. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  2403. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  2404. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  2405. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  2406. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  2407. "checkCostTotal": checkCostTotal,
  2408. "checkCostSelfTotal": checkCostSelfTotal,
  2409. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  2410. "laboratoryCostTotal": laboratoryCostTotal,
  2411. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  2412. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  2413. "treatCostTotal": treatCostTotal,
  2414. "treatCostSelfTotal": treatCostSelfTotal,
  2415. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  2416. })
  2417. }
  2418. }
  2419. }
  2420. func (this *HisApiController) AdditionalCharge() {
  2421. dataBody := make(map[string]interface{}, 0)
  2422. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2423. fmt.Println(err)
  2424. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  2425. patient_id := int64(dataBody["patient_id"].(float64))
  2426. medicineData, _ := dataBody["medicineData"].([]interface{})
  2427. adminUserInfo := this.GetAdminUserInfo()
  2428. orgId := adminUserInfo.CurrentOrgId
  2429. admin_user_id := adminUserInfo.AdminUser.Id
  2430. timeStr := time.Now().Format("2006-01-02")
  2431. timeLayout := "2006-01-02 15:04:05"
  2432. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2433. timenow := timeStringToTime.Unix()
  2434. var additionalCharges []*models.HisAdditionalCharge
  2435. for _, item := range medicineData {
  2436. var randNum int
  2437. randNum = rand.Intn(10000) + 1000
  2438. timestamp := time.Now().Unix()
  2439. tempTime := time.Unix(timestamp, 0)
  2440. timeFormat := tempTime.Format("20060102150405")
  2441. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2442. items := item.(map[string]interface{})
  2443. money := items["price"].(string)
  2444. item_id_str := items["item_id"].(string)
  2445. name := items["name"].(string)
  2446. id_str := items["id"].(string)
  2447. moneys, _ := strconv.ParseInt(money, 10, 64)
  2448. monStr := strconv.FormatInt(moneys, 10)
  2449. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  2450. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  2451. id, _ := strconv.ParseInt(id_str, 10, 64)
  2452. additionalCharge := &models.HisAdditionalCharge{
  2453. ID: id,
  2454. HisPatientId: his_patient_id,
  2455. UserOrgId: orgId,
  2456. PatientId: patient_id,
  2457. RecordDate: timenow,
  2458. Price: monneyStr,
  2459. Status: 1,
  2460. ItemName: name,
  2461. ItemId: item_id,
  2462. AdminUserId: admin_user_id,
  2463. CreatedTime: time.Now().Unix(),
  2464. OrderStatus: 0,
  2465. PrescriptionNumber: "",
  2466. BatchNumber: "",
  2467. FeedetlSn: p_number,
  2468. }
  2469. service.CreateAdditionalCharge(additionalCharge)
  2470. additionalCharges = append(additionalCharges, additionalCharge)
  2471. }
  2472. this.ServeSuccessJSON(map[string]interface{}{
  2473. "msg": "添加成功",
  2474. "additional_charges": additionalCharges,
  2475. })
  2476. }
  2477. func (this *HisApiController) DeleteAddition() {
  2478. id, _ := this.GetInt64("id")
  2479. //TODO 需要判断是否已经结算
  2480. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  2481. if err == nil {
  2482. this.ServeSuccessJSON(map[string]interface{}{
  2483. "msg": "删除成功",
  2484. })
  2485. return
  2486. } else {
  2487. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2488. return
  2489. }
  2490. }
  2491. func (this *HisApiController) GetAdminUsers() {
  2492. adminUser := this.GetAdminUserInfo()
  2493. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  2494. this.ServeSuccessJSON(map[string]interface{}{
  2495. "doctors": doctors,
  2496. })
  2497. }
  2498. func (this *DialysisApiController) GetLastOrNextHisPrescription() {
  2499. change_type, _ := this.GetInt64("type", 0)
  2500. record_date := this.GetString("record_time")
  2501. patient_id, _ := this.GetInt64("patient_id", 0)
  2502. timeLayout := "2006-01-02"
  2503. loc, _ := time.LoadLocation("Local")
  2504. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2505. record_time := theAdviceRecordTime.Unix()
  2506. adminUserInfo := this.GetAdminUserInfo()
  2507. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id)
  2508. if err == nil {
  2509. if len(prescriptions) == 0 {
  2510. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2511. return
  2512. } else {
  2513. this.ServeSuccessJSON(map[string]interface{}{
  2514. "prescriptions": prescriptions,
  2515. })
  2516. return
  2517. }
  2518. } else {
  2519. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2520. return
  2521. }
  2522. }
  2523. func (this *DialysisApiController) GetCallHisPrescription() {
  2524. patient_id, _ := this.GetInt64("patient_id", 0)
  2525. timeLayout := "2006-01-02"
  2526. loc, _ := time.LoadLocation("Local")
  2527. start_time := this.GetString("start_time")
  2528. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2529. end_time := this.GetString("end_time")
  2530. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2531. adminUserInfo := this.GetAdminUserInfo()
  2532. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id)
  2533. if err == nil {
  2534. this.ServeSuccessJSON(map[string]interface{}{
  2535. "prescriptions": prescriptions,
  2536. })
  2537. return
  2538. } else {
  2539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2540. return
  2541. }
  2542. }
  2543. func PathExists(path string) (bool, error) {
  2544. _, err := os.Stat(path)
  2545. if err == nil {
  2546. return true, nil
  2547. }
  2548. if os.IsNotExist(err) {
  2549. return false, nil
  2550. }
  2551. return false, err
  2552. }
  2553. //创建文件夹
  2554. func Mkdir(dir string) {
  2555. // 创建文件夹
  2556. exist, err := PathExists(dir)
  2557. if err != nil {
  2558. fmt.Println(err.Error())
  2559. } else {
  2560. if exist {
  2561. fmt.Println(dir + "文件夹已存在!")
  2562. } else {
  2563. // 文件夹名称,权限
  2564. err := os.Mkdir(dir, os.ModePerm)
  2565. if err != nil {
  2566. fmt.Println(dir+"文件夹创建失败:", err.Error())
  2567. } else {
  2568. fmt.Println(dir + "文件夹创建成功!")
  2569. }
  2570. }
  2571. }
  2572. }
  2573. //压缩文件
  2574. func Zip(srcFile string, destZip string) error {
  2575. zipfile, err := os.Create(destZip)
  2576. if err != nil {
  2577. return err
  2578. }
  2579. defer zipfile.Close()
  2580. archive := zip.NewWriter(zipfile)
  2581. defer archive.Close()
  2582. filepath.Walk(srcFile, func(path string, info os.FileInfo, err error) error {
  2583. if err != nil {
  2584. return err
  2585. }
  2586. header, err := zip.FileInfoHeader(info)
  2587. if err != nil {
  2588. return err
  2589. }
  2590. header.Name = strings.TrimPrefix(path, filepath.Dir(srcFile)+"/")
  2591. // header.Name = path
  2592. if info.IsDir() {
  2593. header.Name += "/"
  2594. } else {
  2595. header.Method = zip.Deflate
  2596. }
  2597. writer, err := archive.CreateHeader(header)
  2598. if err != nil {
  2599. return err
  2600. }
  2601. if !info.IsDir() {
  2602. file, err := os.Open(path)
  2603. if err != nil {
  2604. return err
  2605. }
  2606. defer file.Close()
  2607. _, err = io.Copy(writer, file)
  2608. }
  2609. return err
  2610. })
  2611. return err
  2612. }
  2613. func ReadFile(filePath string) []byte {
  2614. f, err := os.Open(filePath)
  2615. if err != nil {
  2616. fmt.Println("read file fail", err)
  2617. return nil
  2618. }
  2619. defer f.Close()
  2620. fd, err := ioutil.ReadAll(f)
  2621. if err != nil {
  2622. fmt.Println("read to fd fail", err)
  2623. return nil
  2624. }
  2625. return fd
  2626. }