his_api_controller.go 95KB

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