his_api_controller.go 109KB

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