his_api_controller.go 103KB

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