his_api_controller.go 128KB

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