his_api_controller.go 109KB

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