his_api_controller.go 103KB

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