his_api_controller.go 104KB

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