his_api_controller.go 109KB

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