his_api_controller.go 109KB

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