his_api_controller.go 109KB

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