his_api_controller.go 105KB

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