his_api_controller.go 96KB

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