his_api_controller.go 109KB

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