his_api_controller.go 103KB

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