his_api_controller.go 103KB

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