his_api_controller.go 109KB

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