his_api_controller.go 131KB

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