his_api_controller.go 109KB

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