his_api_controller.go 95KB

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