his_api_controller.go 147KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180
  1. package controllers
  2. import "C"
  3. import (
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. "XT_New/utils"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "github.com/shopspring/decimal"
  13. "math/rand"
  14. "reflect"
  15. "strconv"
  16. "strings"
  17. "syscall"
  18. "time"
  19. "unsafe"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. //beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  27. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  28. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  29. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  30. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  31. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  32. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  33. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  34. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  35. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  36. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  37. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  38. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  41. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  42. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  43. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  44. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  45. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. }
  70. func (c *HisApiController) Sscard() {
  71. //r := CardInit()
  72. //if r == 0 {
  73. // GetBaseInfo()
  74. //}
  75. //c.ServeSuccessJSON(map[string]interface{}{
  76. // "list": "11",
  77. //})
  78. }
  79. func GetBaseInfo() error {
  80. //handle := syscall.MustLoadDLL("SSCard.dll")
  81. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  82. //
  83. //str := make([]byte, 256)
  84. //str1 := make([]byte, 256)
  85. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  86. //if ferr != nil {
  87. // fmt.Println("ReadCardBas 报错", ferr.Error())
  88. // return ferr
  89. //}
  90. //
  91. //fmt.Println(string(str))
  92. //
  93. //fmt.Println(r)
  94. return nil
  95. }
  96. func CardInit() int {
  97. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  98. //add := DllTestDef.MustFindProc("Init")
  99. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  100. //if err != nil {
  101. // fmt.Println("SSCard的运算结果为:", ret)
  102. //}
  103. //result := int(ret)
  104. return 0
  105. }
  106. func IntPtr(n int) uintptr {
  107. return uintptr(n)
  108. }
  109. func StrPtr(s string) uintptr {
  110. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  111. }
  112. func (c *HisApiController) GetHisPatientList() {
  113. //types, _ := c.GetInt64("type", 0)
  114. record_date := c.GetString("record_date")
  115. sch_type, _ := c.GetInt64("sch_type")
  116. timeLayout := "2006-01-02"
  117. loc, _ := time.LoadLocation("Local")
  118. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  119. if err != nil {
  120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  121. return
  122. }
  123. recordDateTime := theTime.Unix()
  124. adminInfo := c.GetAdminUserInfo()
  125. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  126. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  127. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  128. //获取当前用户的信息
  129. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  130. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  131. //获取所有科室信息
  132. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  133. c.ServeSuccessJSON(map[string]interface{}{
  134. "list": patients,
  135. "list_two": patients_two,
  136. "info": adminUserInfo,
  137. "doctors": doctors,
  138. "department": department,
  139. })
  140. }
  141. func (c *HisApiController) GetHisPatientInfo() {
  142. patient_id, _ := c.GetInt64("patient_id")
  143. his_patient_id, _ := c.GetInt64("his_patient_id")
  144. record_date := c.GetString("record_date")
  145. number := c.GetString("number")
  146. start_time := c.GetString("start_time")
  147. end_time := c.GetString("end_time")
  148. p_type, _ := c.GetInt64("p_type")
  149. timeLayout := "2006-01-02"
  150. loc, _ := time.LoadLocation("Local")
  151. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  152. if err != nil {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  154. return
  155. }
  156. recordDateTime := theTime.Unix()
  157. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  158. if err != nil {
  159. }
  160. startRecordDateTime := startTime.Unix()
  161. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  162. if err != nil {
  163. }
  164. endRecordDateTime := endTime.Unix()
  165. admin := c.GetAdminUserInfo()
  166. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  167. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  168. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  169. var prescriptions []*models.HisPrescription
  170. var last_prescriptions []*models.HisPrescription
  171. var sch_prescriptions []*models.HisPrescriptionInfoTemplate
  172. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  173. if p_type == 1 { //住院
  174. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  175. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  176. } else { //门诊
  177. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  178. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  179. }
  180. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  181. if sch.ID > 0 {
  182. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  183. sch_prescriptions, _ = service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  184. }
  185. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  186. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  187. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  188. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  189. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  190. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  191. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  192. //获取所有科室信息
  193. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  194. c.ServeSuccessJSON(map[string]interface{}{
  195. "his_info": his_patient_info,
  196. "xt_info": xt_patient_info,
  197. "prescription": prescriptions,
  198. "case_history": case_history,
  199. "info": patientPrescriptionInfo,
  200. "month_prescriptions": monthPrescriptions,
  201. "order": order,
  202. "doctors": doctors,
  203. "department": department,
  204. "sch_prescriptions": sch_prescriptions,
  205. "last_prescriptions": last_prescriptions,
  206. "schedule": sch,
  207. "count": count,
  208. "drugStockConfig": drugStockConfig,
  209. })
  210. return
  211. }
  212. func (c *HisApiController) GetHisPrescriptionConfig() {
  213. adminInfo := c.GetAdminUserInfo()
  214. //获取医嘱模版
  215. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  216. //获取所有基础药
  217. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  218. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  219. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  220. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  221. //获取所有科室信息
  222. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  223. //获取诊断信息
  224. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  225. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  226. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  227. c.ServeSuccessJSON(map[string]interface{}{
  228. "drugs": drugs,
  229. "advices_template": advices,
  230. "drugways": drugways,
  231. "efs": efs,
  232. "doctors": doctors,
  233. "department": department,
  234. "sick": sick,
  235. "additions": additions,
  236. "diagnose": diagnose,
  237. })
  238. }
  239. func (c *HisApiController) CreateHisPrescription() {
  240. record_date := c.GetString("record_date")
  241. patient_id, _ := c.GetInt64("patient_id")
  242. reg_type, _ := c.GetInt64("reg_type")
  243. diagnose, _ := c.GetInt64("diagnose")
  244. sick_type, _ := c.GetInt64("sick_type")
  245. sick_history := c.GetString("sick_history")
  246. doctor_id, _ := c.GetInt64("doctor", 0)
  247. department, _ := c.GetInt64("department", 0)
  248. his_patient_id, _ := c.GetInt64("his_patient_id")
  249. p_type, _ := c.GetInt64("p_type")
  250. dataBody := make(map[string]interface{}, 0)
  251. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  252. if err != nil {
  253. utils.ErrorLog(err.Error())
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. return
  256. }
  257. timeLayout := "2006-01-02"
  258. loc, _ := time.LoadLocation("Local")
  259. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  260. if err != nil {
  261. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  262. return
  263. }
  264. adminInfo := c.GetAdminUserInfo()
  265. recordDateTime := theTime.Unix()
  266. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  267. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  268. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  269. if len(lists) == 1 {
  270. his_patient_id = lists[0].ID
  271. }
  272. }
  273. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  274. if drugStockConfig.IsOpen == 1 {
  275. //校验库存总量
  276. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  277. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  278. if len(prescriptions) > 0 {
  279. for _, item := range prescriptions {
  280. items := item.(map[string]interface{})
  281. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  282. advices := items["advices"].([]interface{})
  283. if len(advices) > 0 {
  284. for _, advice := range advices {
  285. var drug_id int64
  286. var prescribing_number float64
  287. var prescribingNumberUnit string
  288. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  289. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  290. }
  291. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  292. //prescribing_number = advice.(map[string]interface{})["prescribing_number"].(string)
  293. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  294. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  295. }
  296. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  297. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  298. }
  299. drug, _ := service.FindBaseDrugLibRecord(adminInfo.CurrentOrgId, drug_id)
  300. if drug.ID == 0 {
  301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  302. return
  303. }
  304. if prescribingNumberUnit == drug.MinUnit {
  305. if prescribing_number > drug.Total {
  306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  307. return
  308. }
  309. } else {
  310. if prescribingNumberUnit == drug.MaxUnit {
  311. num := prescribing_number * float64(drug.MinNumber)
  312. if num > drug.Total {
  313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOutOfStockParamWrong)
  314. return
  315. }
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. }
  324. }
  325. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  326. var hpInfo models.HisPrescriptionInfo
  327. if info.ID == 0 {
  328. var randNum int
  329. randNum = rand.Intn(10000) + 1000
  330. timestamp := time.Now().Unix()
  331. tempTime := time.Unix(timestamp, 0)
  332. timeFormat := tempTime.Format("20060102150405")
  333. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  334. hpInfo = models.HisPrescriptionInfo{
  335. HisPatientId: his_patient_id,
  336. UserOrgId: adminInfo.CurrentOrgId,
  337. RecordDate: theTime.Unix(),
  338. PatientId: patient_id,
  339. Status: 1,
  340. Ctime: time.Now().Unix(),
  341. Mtime: time.Now().Unix(),
  342. Creator: adminInfo.AdminUser.Id,
  343. Modifier: adminInfo.AdminUser.Id,
  344. Diagnosis: diagnose,
  345. SickHistory: sick_history,
  346. Departments: department,
  347. RegisterType: reg_type,
  348. PrescriptionNumber: p_number,
  349. PrescriptionStatus: 1,
  350. Doctor: role.UserName,
  351. DoctorId: doctor_id,
  352. SickType: sick_type,
  353. PType: p_type,
  354. }
  355. service.SavePatientPrescriptionInfo(hpInfo)
  356. } else {
  357. hpInfo = models.HisPrescriptionInfo{
  358. ID: info.ID,
  359. UserOrgId: adminInfo.CurrentOrgId,
  360. RecordDate: info.RecordDate,
  361. PatientId: info.PatientId,
  362. Status: 1,
  363. Ctime: info.Ctime,
  364. Mtime: time.Now().Unix(),
  365. Creator: info.Creator,
  366. Modifier: adminInfo.AdminUser.Id,
  367. Diagnosis: diagnose,
  368. SickHistory: sick_history,
  369. Departments: department,
  370. RegisterType: reg_type,
  371. PrescriptionNumber: info.PrescriptionNumber,
  372. Doctor: role.UserName,
  373. PrescriptionStatus: info.PrescriptionStatus,
  374. DoctorId: doctor_id,
  375. SickType: sick_type,
  376. PType: info.PType,
  377. HisPatientId: info.HisPatientId,
  378. }
  379. service.SavePatientPrescriptionInfo(hpInfo)
  380. }
  381. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  382. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  383. var tempPrescription *models.HisPrescription
  384. if len(prescriptions) > 0 {
  385. for _, item := range prescriptions {
  386. items := item.(map[string]interface{})
  387. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  388. utils.ErrorLog("id")
  389. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  390. return
  391. }
  392. id := int64(items["id"].(float64))
  393. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  394. tempPrescription = &new_prescription
  395. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  396. utils.ErrorLog("type")
  397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  398. return
  399. }
  400. types := int64(items["type"].(float64))
  401. if items["order_status"] == nil || reflect.TypeOf(items["order_status"]).String() != "float64" {
  402. utils.ErrorLog("order_status")
  403. }
  404. order_status := int64(items["order_status"].(float64))
  405. if order_status == 0 {
  406. order_status = 1
  407. }
  408. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  409. utils.ErrorLog("pre_time")
  410. }
  411. preTime, _ := items["pre_time"].(string)
  412. timeLayout := "2006-01-02"
  413. loc, _ := time.LoadLocation("Local")
  414. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  415. if err != nil {
  416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  417. return
  418. }
  419. pTime := theTime2.Unix()
  420. ctime := time.Now().Unix()
  421. if tempPrescription.ID == 0 {
  422. prescription := &models.HisPrescription{
  423. ID: 0,
  424. PatientId: patient_id,
  425. UserOrgId: adminInfo.CurrentOrgId,
  426. RecordDate: recordDateTime,
  427. Ctime: ctime,
  428. Mtime: ctime,
  429. Type: types,
  430. Modifier: adminInfo.AdminUser.Id,
  431. Creator: adminInfo.AdminUser.Id,
  432. Status: 1,
  433. Doctor: role.UserName,
  434. HisPatientId: his_patient_id,
  435. OrderStatus: order_status,
  436. BatchNumber: "",
  437. PrescriptionNumber: hpInfo.PrescriptionNumber,
  438. PreTime: pTime,
  439. PType: p_type,
  440. }
  441. tempPrescription = prescription
  442. service.SaveHisPrescription(tempPrescription)
  443. } else {
  444. tempPrescription.ID = id
  445. tempPrescription.Type = types
  446. tempPrescription.Modifier = adminInfo.AdminUser.Id
  447. tempPrescription.Mtime = time.Now().Unix()
  448. tempPrescription.Doctor = role.UserName
  449. tempPrescription.OrderStatus = order_status
  450. tempPrescription.PreTime = pTime
  451. service.SaveHisPrescription(tempPrescription)
  452. }
  453. //service.SaveHisPrescription(prescription)
  454. //更改患者挂号状态
  455. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  456. fmt.Println("更改失败", err2)
  457. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  458. advices := items["advices"].([]interface{})
  459. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  460. groupNo := int64(0)
  461. ctime := time.Now().Unix()
  462. mtime := ctime
  463. if len(advices) > 0 {
  464. for _, advice := range advices {
  465. var s models.HisDoctorAdviceInfo
  466. s.PrescriptionId = tempPrescription.ID
  467. s.AdviceType = 2
  468. s.AdviceDoctor = doctor_id
  469. s.StopState = 2
  470. s.ExecutionState = 2
  471. s.AdviceDate = recordDateTime
  472. s.Status = 1
  473. s.UserOrgId = adminInfo.CurrentOrgId
  474. s.RecordDate = recordDateTime
  475. s.StartTime = tempPrescription.PreTime
  476. s.Groupno = groupNo
  477. s.CreatedTime = ctime
  478. s.UpdatedTime = mtime
  479. s.PatientId = patient_id
  480. s.HisPatientId = his_patient_id
  481. s.StartTime = pTime
  482. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  483. if errcode > 0 {
  484. c.ServeFailJSONWithSGJErrorCode(errcode)
  485. return
  486. }
  487. s.StartTime = pTime
  488. service.CreateHisDoctorAdvice(&s)
  489. var randNum int
  490. randNum = rand.Intn(10000) + 1000
  491. timestamp := time.Now().Unix()
  492. tempTime := time.Unix(timestamp, 0)
  493. timeFormat := tempTime.Format("20060102150405")
  494. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  495. service.CreateHisDoctorAdvice(&s)
  496. }
  497. }
  498. }
  499. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  500. projects := items["project"].([]interface{})
  501. if len(projects) > 0 {
  502. for _, project := range projects {
  503. var p models.HisPrescriptionProject
  504. p.PrescriptionId = tempPrescription.ID
  505. p.Ctime = time.Now().Unix()
  506. p.Mtime = time.Now().Unix()
  507. p.PatientId = patient_id
  508. p.RecordDate = recordDateTime
  509. p.Doctor = doctor_id
  510. p.UserOrgId = adminInfo.CurrentOrgId
  511. p.HisPatientId = his_patient_id
  512. p.Status = 1
  513. p.StartTime = pTime
  514. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  515. if errcode > 0 {
  516. c.ServeFailJSONWithSGJErrorCode(errcode)
  517. return
  518. }
  519. service.CreateHisProjectTwo(&p)
  520. var randNum int
  521. randNum = rand.Intn(10000) + 1000
  522. timestamp := time.Now().Unix()
  523. tempTime := time.Unix(timestamp, 0)
  524. timeFormat := tempTime.Format("20060102150405")
  525. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  526. service.SaveHisProjectTwo(&p)
  527. if p.Type == 3 { //处理透前准备耗材数量数据
  528. consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  529. if consumables.ID > 0 {
  530. consumables.Count = p.Count
  531. service.UpdateConsumables(&consumables)
  532. }
  533. }
  534. }
  535. }
  536. }
  537. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  538. addition := items["addition"].([]interface{})
  539. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  540. ctime := time.Now().Unix()
  541. mtime := ctime
  542. if len(addition) > 0 {
  543. for _, item := range addition {
  544. var s models.HisAdditionalCharge
  545. s.PrescriptionId = tempPrescription.ID
  546. s.Status = 1
  547. s.UserOrgId = adminInfo.CurrentOrgId
  548. s.RecordDate = recordDateTime
  549. s.CreatedTime = ctime
  550. s.UpdatedTime = mtime
  551. s.PatientId = patient_id
  552. s.HisPatientId = his_patient_id
  553. errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  554. if errcode > 0 {
  555. c.ServeFailJSONWithSGJErrorCode(errcode)
  556. return
  557. }
  558. service.CreateAdditionalCharge(&s)
  559. var randNum int
  560. randNum = rand.Intn(10000) + 1000
  561. timestamp := time.Now().Unix()
  562. tempTime := time.Unix(timestamp, 0)
  563. timeFormat := tempTime.Format("20060102150405")
  564. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  565. service.CreateAdditionalCharge(&s)
  566. }
  567. }
  568. }
  569. }
  570. }
  571. }
  572. if err == nil {
  573. c.ServeSuccessJSON(map[string]interface{}{
  574. "msg": "保存成功",
  575. })
  576. return
  577. } else {
  578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  579. return
  580. }
  581. }
  582. func (c *HisApiController) EditHisPrescription() {
  583. record_date := c.GetString("record_date")
  584. patient_id, _ := c.GetInt64("patient_id")
  585. reg_type, _ := c.GetInt64("reg_type")
  586. diagnose, _ := c.GetInt64("diagnose")
  587. sick_type, _ := c.GetInt64("sick_type")
  588. sick_history := c.GetString("sick_history")
  589. doctor_id, _ := c.GetInt64("doctor", 0)
  590. department, _ := c.GetInt64("department", 0)
  591. his_patient_id, _ := c.GetInt64("his_patient_id")
  592. p_type, _ := c.GetInt64("p_type")
  593. dataBody := make(map[string]interface{}, 0)
  594. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  595. if err != nil {
  596. utils.ErrorLog(err.Error())
  597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  598. return
  599. }
  600. timeLayout := "2006-01-02"
  601. loc, _ := time.LoadLocation("Local")
  602. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  603. if err != nil {
  604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  605. return
  606. }
  607. adminInfo := c.GetAdminUserInfo()
  608. recordDateTime := theTime.Unix()
  609. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  610. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type)
  611. var hpInfo models.HisPrescriptionInfo
  612. if info.ID == 0 {
  613. var randNum int
  614. randNum = rand.Intn(10000) + 1000
  615. timestamp := time.Now().Unix()
  616. tempTime := time.Unix(timestamp, 0)
  617. timeFormat := tempTime.Format("20060102150405")
  618. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  619. hpInfo = models.HisPrescriptionInfo{
  620. UserOrgId: adminInfo.CurrentOrgId,
  621. RecordDate: theTime.Unix(),
  622. PatientId: patient_id,
  623. Status: 1,
  624. Ctime: time.Now().Unix(),
  625. Mtime: time.Now().Unix(),
  626. Creator: adminInfo.AdminUser.Id,
  627. Modifier: adminInfo.AdminUser.Id,
  628. Diagnosis: diagnose,
  629. SickHistory: sick_history,
  630. Departments: department,
  631. RegisterType: reg_type,
  632. PrescriptionNumber: p_number,
  633. PrescriptionStatus: 1,
  634. Doctor: role.UserName,
  635. DoctorId: doctor_id,
  636. SickType: sick_type,
  637. PType: p_type,
  638. }
  639. service.SavePatientPrescriptionInfo(hpInfo)
  640. } else {
  641. hpInfo = models.HisPrescriptionInfo{
  642. ID: info.ID,
  643. UserOrgId: adminInfo.CurrentOrgId,
  644. RecordDate: info.RecordDate,
  645. PatientId: info.PatientId,
  646. Status: 1,
  647. Ctime: info.Ctime,
  648. Mtime: time.Now().Unix(),
  649. Creator: info.Creator,
  650. Modifier: adminInfo.AdminUser.Id,
  651. Diagnosis: diagnose,
  652. SickHistory: sick_history,
  653. Departments: department,
  654. RegisterType: reg_type,
  655. PrescriptionNumber: info.PrescriptionNumber,
  656. Doctor: role.UserName,
  657. PrescriptionStatus: info.PrescriptionStatus,
  658. DoctorId: doctor_id,
  659. SickType: sick_type,
  660. PType: info.PType,
  661. }
  662. service.SavePatientPrescriptionInfo(hpInfo)
  663. }
  664. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  665. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  666. if len(prescriptions) > 0 {
  667. for _, item := range prescriptions {
  668. items := item.(map[string]interface{})
  669. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  670. utils.ErrorLog("id")
  671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  672. return
  673. }
  674. id := int64(items["id"].(float64))
  675. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  676. utils.ErrorLog("type")
  677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  678. return
  679. }
  680. types := int64(items["type"].(float64))
  681. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  682. ctime := time.Now().Unix()
  683. prescription := &models.HisPrescription{
  684. ID: id,
  685. PatientId: patient_id,
  686. UserOrgId: adminInfo.CurrentOrgId,
  687. RecordDate: recordDateTime,
  688. Ctime: ctime,
  689. Mtime: ctime,
  690. Type: types,
  691. Modifier: adminInfo.AdminUser.Id,
  692. Creator: adminInfo.AdminUser.Id,
  693. Status: 1,
  694. Doctor: role.UserName,
  695. HisPatientId: his_patient_id,
  696. OrderStatus: 1,
  697. BatchNumber: "",
  698. PrescriptionNumber: hpInfo.PrescriptionNumber,
  699. PType: hpInfo.PType,
  700. }
  701. if historyPrescription.ID > 0 {
  702. prescription.PreTime = historyPrescription.PreTime
  703. }
  704. service.SaveHisPrescription(prescription)
  705. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  706. advices := items["advices"].([]interface{})
  707. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  708. groupNo := int64(0)
  709. ctime := time.Now().Unix()
  710. mtime := ctime
  711. if len(advices) > 0 {
  712. for _, advice := range advices {
  713. var s models.HisDoctorAdviceInfo
  714. s.PrescriptionId = prescription.ID
  715. s.AdviceType = 2
  716. s.AdviceDoctor = adminInfo.AdminUser.Id
  717. s.StopState = 2
  718. s.ExecutionState = 2
  719. s.AdviceDate = recordDateTime
  720. s.Status = 1
  721. s.UserOrgId = adminInfo.CurrentOrgId
  722. s.RecordDate = recordDateTime
  723. s.StartTime = prescription.PreTime
  724. s.Groupno = groupNo
  725. s.CreatedTime = ctime
  726. s.UpdatedTime = mtime
  727. s.PatientId = patient_id
  728. s.HisPatientId = his_patient_id
  729. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  730. if errcode > 0 {
  731. c.ServeFailJSONWithSGJErrorCode(errcode)
  732. return
  733. }
  734. service.CreateHisDoctorAdvice(&s)
  735. }
  736. }
  737. }
  738. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  739. projects := items["project"].([]interface{})
  740. if len(projects) > 0 {
  741. for _, project := range projects {
  742. var p models.HisPrescriptionProject
  743. p.PrescriptionId = prescription.ID
  744. p.Ctime = time.Now().Unix()
  745. p.Mtime = time.Now().Unix()
  746. p.PatientId = patient_id
  747. p.RecordDate = recordDateTime
  748. p.UserOrgId = adminInfo.CurrentOrgId
  749. p.HisPatientId = his_patient_id
  750. p.Status = 1
  751. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  752. if errcode > 0 {
  753. c.ServeFailJSONWithSGJErrorCode(errcode)
  754. return
  755. }
  756. service.CreateHisProjectTwo(&p)
  757. }
  758. }
  759. }
  760. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  761. addition := items["addition"].([]interface{})
  762. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  763. ctime := time.Now().Unix()
  764. mtime := ctime
  765. if len(addition) > 0 {
  766. for _, item := range addition {
  767. var s models.HisAdditionalCharge
  768. s.PrescriptionId = prescription.ID
  769. s.Status = 1
  770. s.UserOrgId = adminInfo.CurrentOrgId
  771. s.RecordDate = recordDateTime
  772. s.CreatedTime = ctime
  773. s.UpdatedTime = mtime
  774. s.PatientId = patient_id
  775. s.HisPatientId = his_patient_id
  776. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  777. if errcode > 0 {
  778. c.ServeFailJSONWithSGJErrorCode(errcode)
  779. return
  780. }
  781. service.CreateAdditionalCharge(&s)
  782. }
  783. }
  784. }
  785. }
  786. }
  787. }
  788. if err == nil {
  789. c.ServeSuccessJSON(map[string]interface{}{
  790. "msg": "保存成功",
  791. })
  792. return
  793. } else {
  794. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  795. return
  796. }
  797. }
  798. func (c *HisApiController) DeletePrescription() {
  799. prescription_id, _ := c.GetInt64("id")
  800. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  801. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  802. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  803. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  804. if err == nil {
  805. if len(projects) > 0 {
  806. for _, item := range projects {
  807. if item.Type == 3 { //处理透前准备耗材数量数据
  808. consumables, _ := service.FindHisConsumablesByID(item.UserOrgId, item.PatientId, item.RecordDate, item.ProjectId)
  809. if consumables.ID > 0 {
  810. consumables.Count = 0
  811. service.UpdateConsumables(&consumables)
  812. }
  813. }
  814. }
  815. }
  816. if drugStockConfig.IsOpen == 1 {
  817. if len(advices) > 0 {
  818. for _, item := range advices {
  819. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  820. if item.PrescribingNumberUnit == drug.MinUnit {
  821. drug.Total = drug.Total + item.PrescribingNumber
  822. service.UpdateBaseDrugLib(&drug)
  823. } else {
  824. if item.PrescribingNumberUnit == drug.MaxUnit {
  825. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  826. drug.Total = drug.Total + item.PrescribingNumber
  827. service.UpdateBaseDrugLib(&drug)
  828. }
  829. }
  830. }
  831. }
  832. }
  833. c.ServeSuccessJSON(map[string]interface{}{
  834. "msg": "删除成功",
  835. })
  836. return
  837. } else {
  838. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  839. return
  840. }
  841. }
  842. func (c *HisApiController) DeleteDoctorAdvice() {
  843. id, _ := c.GetInt64("id")
  844. advice, _ := service.GetHisDoctorAdvicesById(id)
  845. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  846. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  847. if err == nil {
  848. if drugStockConfig.IsOpen == 1 {
  849. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  850. if advice.PrescribingNumberUnit == drug.MinUnit {
  851. drug.Total = drug.Total + advice.PrescribingNumber
  852. service.UpdateBaseDrugLib(&drug)
  853. } else {
  854. if advice.PrescribingNumberUnit == drug.MaxUnit {
  855. advice.PrescribingNumber = advice.PrescribingNumber * float64(drug.MinNumber)
  856. drug.Total = drug.Total + advice.PrescribingNumber
  857. service.UpdateBaseDrugLib(&drug)
  858. }
  859. }
  860. }
  861. c.ServeSuccessJSON(map[string]interface{}{
  862. "msg": "删除成功",
  863. })
  864. return
  865. } else {
  866. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  867. return
  868. }
  869. }
  870. func (c *HisApiController) DeleteProject() {
  871. id, _ := c.GetInt64("id")
  872. adminInfo := c.GetAdminUserInfo()
  873. project, _ := service.GetHisProjectByID(id)
  874. var consumable models.DialysisBeforePrepare
  875. if project.ID > 0 && project.Type == 3 {
  876. consumable, _ = service.FindHisConsumablesByID(adminInfo.CurrentOrgId, project.PatientId, project.RecordDate, project.ProjectId)
  877. }
  878. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  879. if err == nil {
  880. if consumable.ID > 0 {
  881. consumable.Count = 0
  882. service.UpdateConsumables(&consumable)
  883. }
  884. c.ServeSuccessJSON(map[string]interface{}{
  885. "msg": "删除成功",
  886. })
  887. return
  888. } else {
  889. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  890. return
  891. }
  892. }
  893. func (c *HisApiController) CreateHisAdditionalCharge() {
  894. his_patient_id, _ := c.GetInt64("his_patient_id")
  895. patient_id, _ := c.GetInt64("patient_id")
  896. record_date := c.GetString("record_date")
  897. timeLayout := "2006-01-02"
  898. loc, _ := time.LoadLocation("Local")
  899. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  900. if err != nil {
  901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  902. return
  903. }
  904. adminInfo := c.GetAdminUserInfo()
  905. recordDateTime := theTime.Unix()
  906. dataBody := make(map[string]interface{}, 0)
  907. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  908. if err != nil {
  909. utils.ErrorLog(err.Error())
  910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  911. return
  912. }
  913. var additions []*models.HisAdditionalCharge
  914. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  915. additions, _ := dataBody["addition"].([]interface{})
  916. if len(additions) > 0 {
  917. for _, item := range additions {
  918. items := item.(map[string]interface{})
  919. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  920. utils.ErrorLog("item_id")
  921. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  922. return
  923. }
  924. item_id := int64(items["item_id"].(float64))
  925. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  926. utils.ErrorLog("item_name")
  927. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  928. return
  929. }
  930. item_name := items["item_name"].(string)
  931. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  932. utils.ErrorLog("price")
  933. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  934. return
  935. }
  936. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  937. ctime := time.Now().Unix()
  938. additional := &models.HisAdditionalCharge{
  939. PatientId: patient_id,
  940. HisPatientId: his_patient_id,
  941. UserOrgId: adminInfo.CurrentOrgId,
  942. RecordDate: recordDateTime,
  943. CreatedTime: ctime,
  944. UpdatedTime: ctime,
  945. Modifier: adminInfo.AdminUser.Id,
  946. Creator: adminInfo.AdminUser.Id,
  947. Price: price,
  948. ItemName: item_name,
  949. ItemId: item_id,
  950. Status: 1,
  951. }
  952. additions = append(additions, additional)
  953. }
  954. }
  955. }
  956. for _, item := range additions {
  957. service.CreateAddtionalCharge(item)
  958. }
  959. c.ServeSuccessJSON(map[string]interface{}{
  960. "msg": "创建成功",
  961. })
  962. }
  963. func (c *HisApiController) CreateHisPatientCaseHistory() {
  964. blood_fat := c.GetString("blood_fat")
  965. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  966. blood_sugar := c.GetString("blood_sugar")
  967. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  968. fmt.Println(bloodsugarfloat)
  969. chief_conplaint := c.GetString("chief_conplaint")
  970. dbp := c.GetString("dbp")
  971. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  972. delivery_way, _ := c.GetInt64("delivery_way")
  973. diagnostic := c.GetString("diagnostic")
  974. family_history := c.GetString("family_history")
  975. height := c.GetString("height")
  976. history_of_present_illness := c.GetString("history_of_present_illness")
  977. is_infect, _ := c.GetInt64("is_infect")
  978. fmt.Println("is", is_infect)
  979. past_history := c.GetString("past_history")
  980. patient_id, _ := c.GetInt64("patient_id")
  981. his_patient_id, _ := c.GetInt64("his_patient_id")
  982. fmt.Println("patient_id", patient_id)
  983. personal_history := c.GetString("personal_history")
  984. pulse := c.GetString("pulse")
  985. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  986. sbp := c.GetString("sbp")
  987. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  988. heightfloat, _ := strconv.ParseFloat(height, 64)
  989. sicktype := c.GetString("sick_type")
  990. fmt.Println("sicketype", sicktype)
  991. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  992. symptom := c.GetString("symptom")
  993. sick_date := c.GetString("sick_date")
  994. temperatures := c.GetString("temperature")
  995. fmt.Println("temperatures", temperatures)
  996. temperature, _ := strconv.ParseFloat(temperatures, 64)
  997. record_date := c.GetString("record_date")
  998. breathing := c.GetString("breathing")
  999. doctor_advice := c.GetString("doctor_advice")
  1000. remark := c.GetString("remark")
  1001. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  1002. sick, _ := c.GetInt64("sick")
  1003. diagnose, _ := c.GetInt64("diagnose")
  1004. id, _ := c.GetInt64("id")
  1005. timeLayout := "2006-01-02"
  1006. loc, _ := time.LoadLocation("Local")
  1007. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1008. allergic_history := c.GetString("allergic_history")
  1009. if err != nil {
  1010. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1011. return
  1012. }
  1013. recordDateTime := theTime.Unix()
  1014. fmt.Println("recordDataTime", recordDateTime)
  1015. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  1016. if err != nil {
  1017. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1018. return
  1019. }
  1020. sickTimes := sickTime.Unix()
  1021. ctime := time.Now().Unix()
  1022. caseHistory := models.HisPatientCaseHistory{
  1023. HisPatientId: his_patient_id,
  1024. PatientId: patient_id,
  1025. Temperature: temperature,
  1026. BloodSugar: bloodsugarfloat,
  1027. Pulse: pulsefloat,
  1028. Sbp: sbpfloat,
  1029. Dbp: dbpfloat,
  1030. Height: heightfloat,
  1031. BloodFat: bloodfatfloat,
  1032. SickType: sick_type,
  1033. Symptom: symptom,
  1034. SickDate: sickTimes,
  1035. IsInfect: is_infect,
  1036. HistoryOfPresentIllness: history_of_present_illness,
  1037. PastHistory: past_history,
  1038. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  1039. ChiefConplaint: chief_conplaint,
  1040. PersonalHistory: personal_history,
  1041. FamilyHistory: family_history,
  1042. Diagnostic: diagnostic,
  1043. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1044. Status: 1,
  1045. Ctime: ctime,
  1046. Mtime: ctime,
  1047. RecordDate: recordDateTime,
  1048. DeliveryWay: delivery_way,
  1049. Breathing: breathingfloat,
  1050. DoctorAdvice: doctor_advice,
  1051. Remark: remark,
  1052. Sick: sick,
  1053. Diagnose: diagnose,
  1054. AllergicHistory: allergic_history,
  1055. }
  1056. //查询该患者是否有病历
  1057. _, errcodes := service.GetHisPatientCaseHistoryById(id)
  1058. if errcodes == gorm.ErrRecordNotFound {
  1059. err = service.SaveHisPatientCaseHistory(&caseHistory)
  1060. if err != nil {
  1061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1062. return
  1063. }
  1064. c.ServeSuccessJSON(map[string]interface{}{
  1065. "caseHistory": caseHistory,
  1066. })
  1067. return
  1068. } else if errcodes == nil {
  1069. err := service.UpdatePatientCaseHistory(id, &caseHistory)
  1070. if err != nil {
  1071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1072. return
  1073. }
  1074. c.ServeSuccessJSON(map[string]interface{}{
  1075. "caseHistory": caseHistory,
  1076. })
  1077. }
  1078. //查询该患者是否有病历
  1079. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  1080. //if errcode == gorm.ErrRecordNotFound {
  1081. // err = service.SaveHisPatientCaseHistory(caseHistory)
  1082. // if err != nil {
  1083. // c.ServeSuccessJSON(map[string]interface{}{
  1084. // "msg": "保存成功",
  1085. // })
  1086. // }
  1087. //} else if errcode == nil {
  1088. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  1089. // return
  1090. //}
  1091. }
  1092. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  1093. patient_id, _ := c.GetInt64("patient_id", 0)
  1094. adminUser := c.GetAdminUserInfo()
  1095. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  1096. c.ServeSuccessJSON(map[string]interface{}{
  1097. "list": caseHistorys,
  1098. })
  1099. }
  1100. func (c *HisApiController) GetHisPatientCaseHistory() {
  1101. record_date, _ := c.GetInt64("record_date", 0)
  1102. patient_id, _ := c.GetInt64("patient_id", 0)
  1103. admin := c.GetAdminUserInfo()
  1104. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  1105. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  1106. c.ServeSuccessJSON(map[string]interface{}{
  1107. "info": info,
  1108. "case_history": case_history,
  1109. })
  1110. }
  1111. func (c *HisApiController) CreateCaseHistoryTemplate() {
  1112. template_name := c.GetString("template_name")
  1113. template_remark := c.GetString("template_remark")
  1114. doctor := c.GetAdminUserInfo().AdminUser.Id
  1115. diagnostic := c.GetString("diagnostic")
  1116. chief_conplaint := c.GetString("chief_conplain")
  1117. history_of_present_illness := c.GetString("history_of_present_illness")
  1118. past_history := c.GetString("past_history")
  1119. personal_history := c.GetString("personal_history")
  1120. family_history := c.GetString("family_history")
  1121. user_name := c.GetString("user_name")
  1122. doctor_advice := c.GetString("doctor_advice")
  1123. remark := c.GetString("remark")
  1124. //record_date := c.GetString("record_date")
  1125. //fmt.Println("record_date--------",record_date)
  1126. //timeLayout := "2006-01-02"
  1127. //loc, _ := time.LoadLocation("Local")
  1128. //
  1129. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1130. //if err != nil {
  1131. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1132. // return
  1133. //}
  1134. //recordDateTime := theTime.Unix()
  1135. ctime := time.Now().Unix()
  1136. template := models.HisCaseHistoryTemplate{
  1137. HistoryOfPresentIllness: history_of_present_illness,
  1138. PastHistory: past_history,
  1139. ChiefConplaint: chief_conplaint,
  1140. PersonalHistory: personal_history,
  1141. FamilyHistory: family_history,
  1142. Diagnostic: diagnostic,
  1143. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1144. Status: 1,
  1145. Ctime: ctime,
  1146. Mtime: ctime,
  1147. RecordDate: time.Now().Unix(),
  1148. TemplateName: template_name,
  1149. TemplateRemark: template_remark,
  1150. Creator: doctor,
  1151. Modifier: doctor,
  1152. UserName: user_name,
  1153. DoctorAdvice: doctor_advice,
  1154. Remark: remark,
  1155. }
  1156. err := service.SaveHisPatientCaseHistoryTemplate(template)
  1157. if err == nil {
  1158. c.ServeSuccessJSON(map[string]interface{}{
  1159. "msg": "保存成功",
  1160. })
  1161. } else {
  1162. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1163. return
  1164. }
  1165. }
  1166. func (c *HisApiController) GetCaseHistoryTemplate() {
  1167. timeLayout := "2006-01-02"
  1168. loc, _ := time.LoadLocation("Local")
  1169. keyword := c.GetString("keyword")
  1170. start_time := c.GetString("start_time")
  1171. end_time := c.GetString("end_time")
  1172. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1173. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1174. admin := c.GetAdminUserInfo()
  1175. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  1176. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  1177. c.ServeSuccessJSON(map[string]interface{}{
  1178. "template": template,
  1179. //"history": history,
  1180. })
  1181. }
  1182. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  1183. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1184. utils.ErrorLog("drug_name")
  1185. return enums.ErrorCodeParamWrong
  1186. }
  1187. adviceName, _ := json["drug_name"].(string)
  1188. if len(adviceName) == 0 {
  1189. utils.ErrorLog("len(advice_name) == 0")
  1190. return enums.ErrorCodeParamWrong
  1191. }
  1192. advice.AdviceName = adviceName
  1193. adviceDesc, _ := json["advice_desc"].(string)
  1194. advice.AdviceDesc = adviceDesc
  1195. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1196. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1197. advice.DrugSpec = drugSpec
  1198. }
  1199. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1200. remark, _ := json["remark"].(string)
  1201. advice.Remark = remark
  1202. }
  1203. if json["id"] == nil {
  1204. advice.DrugId = 0
  1205. } else {
  1206. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1207. drug_id := int64(json["id"].(float64))
  1208. advice.DrugId = drug_id
  1209. }
  1210. }
  1211. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  1212. advice_id := int64(json["advice_id"].(float64))
  1213. advice.ID = advice_id
  1214. if advice.ID > 0 {
  1215. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  1216. if err == nil {
  1217. if hisAdvice.ID > 0 {
  1218. advice.ExecutionTime = hisAdvice.ExecutionTime
  1219. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  1220. advice.ExecutionState = hisAdvice.ExecutionState
  1221. advice.CheckTime = hisAdvice.CheckTime
  1222. advice.Checker = hisAdvice.Checker
  1223. advice.CheckState = hisAdvice.CheckState
  1224. advice.StartTime = hisAdvice.StartTime
  1225. advice.FeedetlSn = hisAdvice.FeedetlSn
  1226. }
  1227. }
  1228. }
  1229. }
  1230. //
  1231. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  1232. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  1233. // advice.ExecutionTime = execution_time
  1234. //}
  1235. //
  1236. //
  1237. //
  1238. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  1239. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  1240. // advice.ExecutionStaff = execution_staff
  1241. //}
  1242. //
  1243. //
  1244. //
  1245. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  1246. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  1247. // advice.ExecutionState = execution_state
  1248. //}
  1249. //
  1250. //
  1251. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  1252. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  1253. // advice.CheckTime = check_time
  1254. //}
  1255. //
  1256. //
  1257. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  1258. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  1259. // advice.CheckState = check_state
  1260. //}
  1261. //
  1262. //
  1263. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  1264. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  1265. // advice.Checker = checker
  1266. //}
  1267. //
  1268. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  1269. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  1270. // advice.StartTime = start_time
  1271. //}
  1272. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  1273. drugSpecUnit, _ := json["min_unit"].(string)
  1274. advice.DrugSpecUnit = drugSpecUnit
  1275. }
  1276. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1277. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  1278. advice.SingleDose = singleDose
  1279. }
  1280. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  1281. singleDoseUnit, _ := json["single_dose_unit"].(string)
  1282. advice.SingleDoseUnit = singleDoseUnit
  1283. }
  1284. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1285. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1286. advice.PrescribingNumber = prescribingNumber
  1287. }
  1288. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1289. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1290. advice.PrescribingNumberUnit = prescribingNumberUnit
  1291. }
  1292. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1293. deliveryWay, _ := json["delivery_way"].(string)
  1294. advice.DeliveryWay = deliveryWay
  1295. }
  1296. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1297. executionFrequency, _ := json["execution_frequency"].(string)
  1298. advice.ExecutionFrequency = executionFrequency
  1299. }
  1300. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  1301. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  1302. advice.Price = price
  1303. }
  1304. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  1305. med_list_codg, _ := json["medical_insurance_number"].(string)
  1306. advice.MedListCodg = med_list_codg
  1307. }
  1308. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  1309. day := int64(json["day"].(float64))
  1310. advice.Day = day
  1311. }
  1312. return 0
  1313. }
  1314. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  1315. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1316. id := int64(json["id"].(float64))
  1317. project.ID = id
  1318. historyProject, _ := service.GetHisProjectByID(id)
  1319. project.FeedetlSn = historyProject.FeedetlSn
  1320. }
  1321. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  1322. project_id := int64(json["project_id"].(float64))
  1323. project.ProjectId = project_id
  1324. }
  1325. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1326. // price := int64(json["price"].(float64))
  1327. // formatInt_price := strconv.FormatInt(price, 10)
  1328. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1329. // project.Price = float_price
  1330. // }
  1331. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1332. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1333. project.Price = price
  1334. }
  1335. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  1336. total, _ := json["total"].(string)
  1337. totals, _ := strconv.ParseInt(total, 10, 64)
  1338. project.Count = totals
  1339. }
  1340. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  1341. medical_code, _ := json["medical_code"].(string)
  1342. project.MedListCodg = medical_code
  1343. }
  1344. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1345. single_dose, _ := json["single_dose"].(string)
  1346. project.SingleDose = single_dose
  1347. }
  1348. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1349. delivery_way, _ := json["delivery_way"].(string)
  1350. project.DeliveryWay = delivery_way
  1351. }
  1352. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1353. execution_frequency, _ := json["execution_frequency"].(string)
  1354. project.ExecutionFrequency = execution_frequency
  1355. }
  1356. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1357. remark, _ := json["remark"].(string)
  1358. project.Remark = remark
  1359. }
  1360. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  1361. day, _ := json["number_days"].(string)
  1362. project.Day = day
  1363. }
  1364. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  1365. unit, _ := json["unit"].(string)
  1366. project.Unit = unit
  1367. }
  1368. return 0
  1369. }
  1370. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  1371. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1372. id := int64(json["id"].(float64))
  1373. historyAddtions, _ := service.GetHisAdditionByID(id)
  1374. additionalCharge.ID = id
  1375. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  1376. }
  1377. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  1378. item_id := int64(json["item_id"].(float64))
  1379. additionalCharge.ItemId = item_id
  1380. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  1381. if config.ID > 0 {
  1382. if len(config.Code) > 0 {
  1383. additionalCharge.MedListCodg = config.Code
  1384. }
  1385. }
  1386. }
  1387. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1388. // price := int64(json["price"].(float64))
  1389. // formatInt_price := strconv.FormatInt(price, 10)
  1390. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1391. // additionalCharge.Price = float_price
  1392. // }
  1393. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1394. // price := int64(json["price"].(float64))
  1395. // formatInt_price := strconv.FormatInt(price, 10)
  1396. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1397. // additionalCharge.Price = float_price
  1398. //}
  1399. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1400. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1401. additionalCharge.Price = price
  1402. }
  1403. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  1404. count, _ := json["count"].(string)
  1405. counts, _ := strconv.ParseInt(count, 10, 64)
  1406. additionalCharge.Count = counts
  1407. }
  1408. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  1409. item_name, _ := json["item_name"].(string)
  1410. additionalCharge.ItemName = item_name
  1411. }
  1412. return 0
  1413. }
  1414. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  1415. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1416. utils.ErrorLog("drug_name")
  1417. return enums.ErrorCodeParamWrong
  1418. }
  1419. adviceName, _ := json["drug_name"].(string)
  1420. if len(adviceName) == 0 {
  1421. utils.ErrorLog("len(advice_name) == 0")
  1422. return enums.ErrorCodeParamWrong
  1423. }
  1424. advice.AdviceName = adviceName
  1425. adviceDesc, _ := json["advice_desc"].(string)
  1426. advice.AdviceDesc = adviceDesc
  1427. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1428. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1429. advice.DrugSpec = drugSpec
  1430. }
  1431. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1432. remark, _ := json["remark"].(string)
  1433. advice.Remark = remark
  1434. }
  1435. if json["id"] == nil {
  1436. advice.DrugId = 0
  1437. } else {
  1438. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1439. drug_id := int64(json["id"].(float64))
  1440. advice.DrugId = drug_id
  1441. }
  1442. }
  1443. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1444. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1445. advice.PrescribingNumber = prescribingNumber
  1446. }
  1447. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1448. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1449. advice.PrescribingNumberUnit = prescribingNumberUnit
  1450. }
  1451. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  1452. advice_id := int64(json["advice_id"].(float64))
  1453. advice.ID = advice_id
  1454. if advice.ID > 0 {
  1455. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  1456. if err == nil {
  1457. if hisAdvice.ID > 0 {
  1458. advice.ExecutionTime = hisAdvice.ExecutionTime
  1459. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  1460. advice.ExecutionState = hisAdvice.ExecutionState
  1461. advice.CheckTime = hisAdvice.CheckTime
  1462. advice.Checker = hisAdvice.Checker
  1463. advice.CheckState = hisAdvice.CheckState
  1464. advice.StartTime = hisAdvice.StartTime
  1465. }
  1466. }
  1467. }
  1468. }
  1469. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  1470. if drugStockConfig.IsOpen == 1 {
  1471. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  1472. if advice.ID == 0 { //医嘱不存在
  1473. if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  1474. drug.Total = drug.Total - advice.PrescribingNumber
  1475. service.UpdateBaseDrugLib(&drug)
  1476. } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  1477. num := advice.PrescribingNumber * float64(drug.MinNumber)
  1478. drug.Total = drug.Total - num
  1479. service.UpdateBaseDrugLib(&drug)
  1480. }
  1481. } else if advice.ID > 0 { //医嘱存在
  1482. hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  1483. var num float64
  1484. if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  1485. if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  1486. if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  1487. num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  1488. drug.Total = drug.Total + num
  1489. service.UpdateBaseDrugLib(&drug)
  1490. } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  1491. num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  1492. drug.Total = drug.Total - num
  1493. service.UpdateBaseDrugLib(&drug)
  1494. }
  1495. } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  1496. num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  1497. if num2 > advice.PrescribingNumber {
  1498. num = num2 - advice.PrescribingNumber
  1499. drug.Total = drug.Total + num
  1500. service.UpdateBaseDrugLib(&drug)
  1501. } else if num2 < advice.PrescribingNumber {
  1502. num = advice.PrescribingNumber - num2
  1503. drug.Total = drug.Total - num
  1504. service.UpdateBaseDrugLib(&drug)
  1505. }
  1506. }
  1507. } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  1508. if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  1509. num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  1510. num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  1511. if num1 > num2 {
  1512. num = num1 - num2
  1513. drug.Total = drug.Total + num
  1514. service.UpdateBaseDrugLib(&drug)
  1515. } else if num1 < num2 {
  1516. num = num2 - num1
  1517. drug.Total = drug.Total - num
  1518. service.UpdateBaseDrugLib(&drug)
  1519. }
  1520. } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  1521. num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  1522. //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  1523. if hisAdvice.PrescribingNumber > num2 {
  1524. num = hisAdvice.PrescribingNumber - num2
  1525. drug.Total = drug.Total + num
  1526. service.UpdateBaseDrugLib(&drug)
  1527. } else if num2 < advice.PrescribingNumber {
  1528. num = num2 - hisAdvice.PrescribingNumber
  1529. drug.Total = drug.Total - num
  1530. service.UpdateBaseDrugLib(&drug)
  1531. }
  1532. }
  1533. }
  1534. }
  1535. }
  1536. //
  1537. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  1538. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  1539. // advice.ExecutionTime = execution_time
  1540. //}
  1541. //
  1542. //
  1543. //
  1544. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  1545. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  1546. // advice.ExecutionStaff = execution_staff
  1547. //}
  1548. //
  1549. //
  1550. //
  1551. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  1552. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  1553. // advice.ExecutionState = execution_state
  1554. //}
  1555. //
  1556. //
  1557. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  1558. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  1559. // advice.CheckTime = check_time
  1560. //}
  1561. //
  1562. //
  1563. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  1564. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  1565. // advice.CheckState = check_state
  1566. //}
  1567. //
  1568. //
  1569. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  1570. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  1571. // advice.Checker = checker
  1572. //}
  1573. //
  1574. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  1575. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  1576. // advice.StartTime = start_time
  1577. //}
  1578. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  1579. drugSpecUnit, _ := json["min_unit"].(string)
  1580. advice.DrugSpecUnit = drugSpecUnit
  1581. }
  1582. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1583. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  1584. advice.SingleDose = singleDose
  1585. }
  1586. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  1587. singleDoseUnit, _ := json["single_dose_unit"].(string)
  1588. advice.SingleDoseUnit = singleDoseUnit
  1589. }
  1590. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1591. deliveryWay, _ := json["delivery_way"].(string)
  1592. advice.DeliveryWay = deliveryWay
  1593. }
  1594. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1595. executionFrequency, _ := json["execution_frequency"].(string)
  1596. advice.ExecutionFrequency = executionFrequency
  1597. }
  1598. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  1599. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  1600. advice.Price = price
  1601. }
  1602. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  1603. med_list_codg, _ := json["medical_insurance_number"].(string)
  1604. advice.MedListCodg = med_list_codg
  1605. }
  1606. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  1607. day := int64(json["day"].(float64))
  1608. advice.Day = day
  1609. }
  1610. return 0
  1611. }
  1612. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  1613. project.ExecutionStaff = 0
  1614. project.ExecutionState = 2
  1615. project.ExecutionTime = 0
  1616. project.Checker = 0
  1617. project.CheckState = 2
  1618. project.CheckTime = 0
  1619. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1620. id := int64(json["id"].(float64))
  1621. project.ID = id
  1622. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  1623. project.ExecutionStaff = temp_project.ExecutionStaff
  1624. project.ExecutionState = temp_project.ExecutionState
  1625. project.ExecutionTime = temp_project.ExecutionTime
  1626. project.Checker = temp_project.Checker
  1627. project.CheckState = temp_project.CheckState
  1628. project.CheckTime = temp_project.CheckTime
  1629. }
  1630. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  1631. types := int64(json["type"].(float64))
  1632. project.Type = types
  1633. }
  1634. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  1635. project_id := int64(json["project_id"].(float64))
  1636. project.ProjectId = project_id
  1637. fmt.Println(project_id)
  1638. fmt.Println(project.ProjectId)
  1639. }
  1640. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1641. // price := int64(json["price"].(float64))
  1642. // formatInt_price := strconv.FormatInt(price, 10)
  1643. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1644. // project.Price = float_price
  1645. // }
  1646. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1647. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1648. project.Price = price
  1649. }
  1650. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  1651. total, _ := json["total"].(string)
  1652. totals, _ := strconv.ParseInt(total, 10, 64)
  1653. project.Count = totals
  1654. }
  1655. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  1656. medical_code, _ := json["medical_code"].(string)
  1657. project.MedListCodg = medical_code
  1658. }
  1659. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1660. single_dose, _ := json["single_dose"].(string)
  1661. project.SingleDose = single_dose
  1662. }
  1663. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1664. delivery_way, _ := json["delivery_way"].(string)
  1665. project.DeliveryWay = delivery_way
  1666. }
  1667. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1668. execution_frequency, _ := json["execution_frequency"].(string)
  1669. project.ExecutionFrequency = execution_frequency
  1670. }
  1671. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1672. remark, _ := json["remark"].(string)
  1673. project.Remark = remark
  1674. }
  1675. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  1676. day, _ := json["number_days"].(string)
  1677. project.Day = day
  1678. }
  1679. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  1680. unit, _ := json["unit"].(string)
  1681. project.Unit = unit
  1682. }
  1683. return 0
  1684. }
  1685. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  1686. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1687. id := int64(json["id"].(float64))
  1688. additionalCharge.ID = id
  1689. }
  1690. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  1691. item_id := int64(json["item_id"].(float64))
  1692. additionalCharge.ItemId = item_id
  1693. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  1694. if config.ID > 0 {
  1695. if len(config.Code) > 0 {
  1696. additionalCharge.MedListCodg = config.Code
  1697. }
  1698. }
  1699. }
  1700. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1701. // price := int64(json["price"].(float64))
  1702. // formatInt_price := strconv.FormatInt(price, 10)
  1703. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1704. // additionalCharge.Price = float_price
  1705. // }
  1706. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  1707. // price := int64(json["price"].(float64))
  1708. // formatInt_price := strconv.FormatInt(price, 10)
  1709. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  1710. // additionalCharge.Price = float_price
  1711. //}
  1712. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1713. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1714. additionalCharge.Price = price
  1715. }
  1716. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  1717. count, _ := json["count"].(string)
  1718. counts, _ := strconv.ParseInt(count, 10, 64)
  1719. additionalCharge.Count = counts
  1720. }
  1721. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  1722. item_name, _ := json["item_name"].(string)
  1723. additionalCharge.ItemName = item_name
  1724. }
  1725. return 0
  1726. }
  1727. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  1728. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  1729. utils.ErrorLog("drug_name")
  1730. return enums.ErrorCodeParamWrong
  1731. }
  1732. adviceName, _ := json["drug_name"].(string)
  1733. if len(adviceName) == 0 {
  1734. utils.ErrorLog("len(advice_name) == 0")
  1735. return enums.ErrorCodeParamWrong
  1736. }
  1737. advice.AdviceName = adviceName
  1738. adviceDesc, _ := json["advice_desc"].(string)
  1739. advice.AdviceDesc = adviceDesc
  1740. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  1741. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  1742. advice.DrugSpec = drugSpec
  1743. }
  1744. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1745. remark, _ := json["remark"].(string)
  1746. advice.Remark = remark
  1747. }
  1748. if json["id"] == nil {
  1749. advice.DrugId = 0
  1750. } else {
  1751. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  1752. drug_id := int64(json["id"].(float64))
  1753. advice.DrugId = drug_id
  1754. }
  1755. }
  1756. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  1757. drugSpecUnit, _ := json["min_unit"].(string)
  1758. advice.DrugSpecUnit = drugSpecUnit
  1759. }
  1760. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1761. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  1762. advice.SingleDose = singleDose
  1763. }
  1764. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  1765. singleDoseUnit, _ := json["single_dose_unit"].(string)
  1766. advice.SingleDoseUnit = singleDoseUnit
  1767. }
  1768. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  1769. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  1770. advice.PrescribingNumber = prescribingNumber
  1771. }
  1772. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  1773. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  1774. advice.PrescribingNumberUnit = prescribingNumberUnit
  1775. }
  1776. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1777. deliveryWay, _ := json["delivery_way"].(string)
  1778. advice.DeliveryWay = deliveryWay
  1779. }
  1780. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1781. executionFrequency, _ := json["execution_frequency"].(string)
  1782. advice.ExecutionFrequency = executionFrequency
  1783. }
  1784. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  1785. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  1786. advice.Price = price
  1787. }
  1788. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  1789. med_list_codg, _ := json["medical_insurance_number"].(string)
  1790. advice.MedListCodg = med_list_codg
  1791. }
  1792. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  1793. day := int64(json["day"].(float64))
  1794. advice.Day = day
  1795. }
  1796. return 0
  1797. }
  1798. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  1799. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  1800. types := int64(json["type"].(float64))
  1801. project.Type = types
  1802. }
  1803. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  1804. project_id := int64(json["project_id"].(float64))
  1805. project.ProjectId = project_id
  1806. }
  1807. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  1808. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  1809. project.Price = price
  1810. }
  1811. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  1812. total, _ := json["total"].(string)
  1813. totals, _ := strconv.ParseInt(total, 10, 64)
  1814. project.Count = totals
  1815. }
  1816. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  1817. medical_code, _ := json["medical_code"].(string)
  1818. project.MedListCodg = medical_code
  1819. }
  1820. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  1821. single_dose, _ := json["single_dose"].(string)
  1822. project.SingleDose = single_dose
  1823. }
  1824. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  1825. delivery_way, _ := json["delivery_way"].(string)
  1826. project.DeliveryWay = delivery_way
  1827. }
  1828. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  1829. execution_frequency, _ := json["execution_frequency"].(string)
  1830. project.ExecutionFrequency = execution_frequency
  1831. }
  1832. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  1833. remark, _ := json["remark"].(string)
  1834. project.Remark = remark
  1835. }
  1836. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  1837. day, _ := json["number_days"].(string)
  1838. project.Day = day
  1839. }
  1840. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  1841. unit, _ := json["unit"].(string)
  1842. project.Unit = unit
  1843. }
  1844. return 0
  1845. }
  1846. func (c *HisApiController) GetHisOrderList() {
  1847. page, _ := c.GetInt64("page", -1)
  1848. limit, _ := c.GetInt64("limit", -1)
  1849. start_time := c.GetString("start_time")
  1850. end_time := c.GetString("end_time")
  1851. types, _ := c.GetInt64("type", 0)
  1852. keywords := c.GetString("keywords")
  1853. p_type, _ := c.GetInt64("p_type", 0)
  1854. timeLayout := "2006-01-02"
  1855. loc, _ := time.LoadLocation("Local")
  1856. var startTime int64
  1857. if len(start_time) > 0 {
  1858. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1859. if err != nil {
  1860. fmt.Println(err)
  1861. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1862. return
  1863. }
  1864. startTime = theTime.Unix()
  1865. }
  1866. var endTime int64
  1867. if len(end_time) > 0 {
  1868. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1869. if err != nil {
  1870. utils.ErrorLog(err.Error())
  1871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1872. return
  1873. }
  1874. endTime = theTime.Unix()
  1875. }
  1876. adminUser := c.GetAdminUserInfo()
  1877. org_id := adminUser.CurrentOrgId
  1878. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type)
  1879. for _, item := range order {
  1880. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  1881. item.DoctorName = info.Doctor
  1882. item.DepartmentName = info.XtHisDepartment.Name
  1883. }
  1884. if err == nil {
  1885. c.ServeSuccessJSON(map[string]interface{}{
  1886. "order": order,
  1887. "total": total,
  1888. })
  1889. } else {
  1890. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1891. return
  1892. }
  1893. }
  1894. func (c *HisApiController) GetHisOrder() {
  1895. patient_id, _ := c.GetInt64("patient_id", 0)
  1896. number := c.GetString("number")
  1897. adminInfo := c.GetAdminUserInfo()
  1898. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  1899. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  1900. if err == nil {
  1901. c.ServeSuccessJSON(map[string]interface{}{
  1902. "order": order,
  1903. "prescription": prescriptions,
  1904. })
  1905. } else {
  1906. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1907. return
  1908. }
  1909. }
  1910. func (c *HisApiController) GetHisPrescriptionList() {
  1911. record_date := c.GetString("record_date")
  1912. keywords := c.GetString("keywords")
  1913. page, _ := c.GetInt64("page")
  1914. limit, _ := c.GetInt64("limit")
  1915. timeLayout := "2006-01-02"
  1916. loc, _ := time.LoadLocation("Local")
  1917. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1918. if err != nil {
  1919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1920. return
  1921. }
  1922. recordDateTime := theTime.Unix()
  1923. adminInfo := c.GetAdminUserInfo()
  1924. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  1925. //adminInfo := c.GetAdminUserInfo()
  1926. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  1927. //fmt.Println(prescriptionOrder)
  1928. if err == nil {
  1929. c.ServeSuccessJSON(map[string]interface{}{
  1930. "order": prescriptionOrder,
  1931. "total": total,
  1932. })
  1933. } else {
  1934. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1935. return
  1936. }
  1937. }
  1938. func (c *HisApiController) GetHisPrescriptionInfo() {
  1939. id, _ := c.GetInt64("id")
  1940. adminInfo := c.GetAdminUserInfo()
  1941. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  1942. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  1943. if err == nil {
  1944. c.ServeSuccessJSON(map[string]interface{}{
  1945. "order": prescriptionOrder,
  1946. "prescription": prescription,
  1947. })
  1948. } else {
  1949. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  1950. return
  1951. }
  1952. }
  1953. func (c *HisApiController) GetMedicalInsuranceConfig() {
  1954. adminUser := c.GetAdminUserInfo()
  1955. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  1956. c.ServeSuccessJSON(map[string]interface{}{
  1957. "config": config,
  1958. })
  1959. }
  1960. type ResultTwo struct {
  1961. ErrMsg interface{} `json:"err_msg"`
  1962. InfRefmsgid string `json:"inf_refmsgid"`
  1963. Infcode int64 `json:"infcode"`
  1964. Output struct {
  1965. Baseinfo struct {
  1966. Age float64 `json:"age"`
  1967. Brdy string `json:"brdy"`
  1968. Certno string `json:"certno"`
  1969. Gend string `json:"gend"`
  1970. Naty string `json:"naty"`
  1971. PsnCertType string `json:"psn_cert_type"`
  1972. PsnName string `json:"psn_name"`
  1973. PsnNo string `json:"psn_no"`
  1974. } `json:"baseinfo"`
  1975. Idetinfo []interface{} `json:"idetinfo"`
  1976. Iinfo []struct {
  1977. Balc float64 `json:"balc"`
  1978. CvlservFlag string `json:"cvlserv_flag"`
  1979. EmpName string `json:"emp_name"`
  1980. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  1981. Insutype string `json:"insutype"`
  1982. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  1983. PausInsuDate interface{} `json:"paus_insu_date"`
  1984. PsnInsuDate string `json:"psn_insu_date"`
  1985. PsnInsuStas string `json:"psn_insu_stas"`
  1986. PsnType string `json:"psn_type"`
  1987. } `json:"insuinfo"`
  1988. } `json:"output"`
  1989. RefmsgTime string `json:"refmsg_time"`
  1990. RespondTime string `json:"respond_time"`
  1991. Signtype interface{} `json:"signtype"`
  1992. WarnInfo interface{} `json:"warn_info"`
  1993. }
  1994. type ResultThree struct {
  1995. Cainfo interface{} `json:"cainfo"`
  1996. ErrMsg interface{} `json:"err_msg"`
  1997. InfRefmsgid string `json:"inf_refmsgid"`
  1998. Infcode int64 `json:"infcode"`
  1999. Output struct {
  2000. Data struct {
  2001. IptOtpNo string `json:"ipt_otp_no"`
  2002. MdtrtID string `json:"mdtrt_id"`
  2003. PsnNo string `json:"psn_no"`
  2004. } `json:"data"`
  2005. } `json:"output"`
  2006. RefmsgTime string `json:"refmsg_time"`
  2007. RespondTime string `json:"respond_time"`
  2008. Signtype interface{} `json:"signtype"`
  2009. WarnMsg interface{} `json:"warn_msg"`
  2010. }
  2011. type ResultFour struct {
  2012. Cainfo string `json:"cainfo"`
  2013. ErrMsg string `json:"err_msg"`
  2014. InfRefmsgid string `json:"inf_refmsgid"`
  2015. Infcode int64 `json:"infcode"`
  2016. Output struct {
  2017. Result []struct {
  2018. BasMednFlag string `json:"bas_medn_flag"`
  2019. ChldMedcFlag string `json:"chld_medc_flag"`
  2020. ChrgitmLv string `json:"chrgitm_lv"`
  2021. Cnt float64 `json:"cnt"`
  2022. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  2023. DrtReimFlag string `json:"drt_reim_flag"`
  2024. FeedetlSn string `json:"feedetl_sn"`
  2025. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2026. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  2027. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2028. ListSpItemFlag string `json:"list_sp_item_flag"`
  2029. LmtUsedFlag string `json:"lmt_used_flag"`
  2030. MedChrgitmType string `json:"med_chrgitm_type"`
  2031. Memo string `json:"memo"`
  2032. OverlmtAmt float64 `json:"overlmt_amt"`
  2033. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2034. Pric float64 `json:"pric"`
  2035. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  2036. SelfpayProp float64 `json:"selfpay_prop"`
  2037. } `json:"result"`
  2038. } `json:"output"`
  2039. RefmsgTime string `json:"refmsg_time"`
  2040. RespondTime string `json:"respond_time"`
  2041. Signtype string `json:"signtype"`
  2042. WarnMsg string `json:"warn_msg"`
  2043. }
  2044. type ResultFive struct {
  2045. Insutype string `json:"insutype"`
  2046. }
  2047. type ResultSix struct {
  2048. Cainfo interface{} `json:"cainfo"`
  2049. ErrMsg interface{} `json:"err_msg"`
  2050. InfRefmsgid string `json:"inf_refmsgid"`
  2051. Infcode int64 `json:"infcode"`
  2052. Output struct {
  2053. } `json:"output"`
  2054. RefmsgTime string `json:"refmsg_time"`
  2055. RespondTime string `json:"respond_time"`
  2056. Signtype interface{} `json:"signtype"`
  2057. WarnMsg interface{} `json:"warn_msg"`
  2058. }
  2059. type ResultSeven struct {
  2060. Cainfo string `json:"cainfo"`
  2061. ErrMsg string `json:"err_msg"`
  2062. InfRefmsgid string `json:"inf_refmsgid"`
  2063. Infcode int64 `json:"infcode"`
  2064. Output struct {
  2065. Setldetail []interface{} `json:"setldetail"`
  2066. Setlinfo struct {
  2067. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  2068. AcctPay float64 `json:"acct_pay"`
  2069. ActPayDedc float64 `json:"act_pay_dedc"`
  2070. Age float64 `json:"age"`
  2071. Balc float64 `json:"balc"`
  2072. Brdy string `json:"brdy"`
  2073. Certno string `json:"certno"`
  2074. ClrOptins string `json:"clr_optins"`
  2075. ClrType string `json:"clr_type"`
  2076. ClrWay string `json:"clr_way"`
  2077. CvlservFlag string `json:"cvlserv_flag"`
  2078. CvlservPay float64 `json:"cvlserv_pay"`
  2079. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2080. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  2081. Gend string `json:"gend"`
  2082. HifesPay float64 `json:"hifes_pay"`
  2083. HifmiPay float64 `json:"hifmi_pay"`
  2084. HifobPay float64 `json:"hifob_pay"`
  2085. HifpPay float64 `json:"hifp_pay"`
  2086. HospPartAmt float64 `json:"hosp_part_amt"`
  2087. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2088. Insutype string `json:"insutype"`
  2089. MafPay float64 `json:"maf_pay"`
  2090. MdtrtCertType string `json:"mdtrt_cert_type"`
  2091. MdtrtID string `json:"mdtrt_id"`
  2092. MedType string `json:"med_type"`
  2093. MedfeeSumamt float64 `json:"medfee_sumamt"`
  2094. MedinsSetlID string `json:"medins_setl_id"`
  2095. Naty string `json:"naty"`
  2096. OthPay float64 `json:"oth_pay"`
  2097. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  2098. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  2099. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2100. PsnCashPay float64 `json:"psn_cash_pay"`
  2101. PsnCertType string `json:"psn_cert_type"`
  2102. PsnName string `json:"psn_name"`
  2103. PsnNo string `json:"psn_no"`
  2104. PsnPartAmt float64 `json:"psn_part_amt"`
  2105. PsnType string `json:"psn_type"`
  2106. SetlID string `json:"setl_id"`
  2107. SetlTime string `json:"setl_time"`
  2108. } `json:"setlinfo"`
  2109. } `json:"output"`
  2110. RefmsgTime string `json:"refmsg_time"`
  2111. RespondTime string `json:"respond_time"`
  2112. Signtype interface{} `json:"signtype"`
  2113. WarnMsg interface{} `json:"warn_msg"`
  2114. }
  2115. type ResultEight struct {
  2116. Cainfo string `json:"cainfo"`
  2117. ErrMsg string `json:"err_msg"`
  2118. InfRefmsgid string `json:"inf_refmsgid"`
  2119. Infcode int64 `json:"infcode"`
  2120. Output struct {
  2121. Stmtinfo struct {
  2122. SetlOptins string `json:"setl_optins"`
  2123. StmtRslt string `json:"stmt_rslt"`
  2124. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  2125. } `json:"stmtinfo"`
  2126. } `json:"output"`
  2127. RefmsgTime string `json:"refmsg_time"`
  2128. RespondTime string `json:"respond_time"`
  2129. Signtype interface{} `json:"signtype"`
  2130. WarnMsg interface{} `json:"warn_msg"`
  2131. }
  2132. type ResultNine struct {
  2133. Cainfo string `json:"cainfo"`
  2134. ErrMsg string `json:"err_msg"`
  2135. InfRefmsgid string `json:"inf_refmsgid"`
  2136. Infcode int64 `json:"infcode"`
  2137. Output struct {
  2138. FileQuryNo string `json:"file_qury_no"`
  2139. } `json:"output"`
  2140. RefmsgTime string `json:"refmsg_time"`
  2141. RespondTime string `json:"respond_time"`
  2142. Signtype interface{} `json:"signtype"`
  2143. WarnMsg interface{} `json:"warn_msg"`
  2144. }
  2145. type ResultTen struct {
  2146. Cainfo string `json:"cainfo"`
  2147. ErrMsg string `json:"err_msg"`
  2148. InfRefmsgid string `json:"inf_refmsgid"`
  2149. Infcode int64 `json:"infcode"`
  2150. Output struct {
  2151. DldEndtime string `json:"dld_endtime"`
  2152. FileQuryNo string `json:"file_qury_no"`
  2153. Filename string `json:"filename"`
  2154. } `json:"output"`
  2155. RefmsgTime string `json:"refmsg_time"`
  2156. RespondTime string `json:"respond_time"`
  2157. Signtype interface{} `json:"signtype"`
  2158. WarnMsg interface{} `json:"warn_msg"`
  2159. }
  2160. type ResultEleven struct {
  2161. Cainfo string `json:"cainfo"`
  2162. ErrMsg string `json:"err_msg"`
  2163. InfRefmsgid string `json:"inf_refmsgid"`
  2164. Infcode int64 `json:"infcode"`
  2165. Output struct {
  2166. Setlinfo struct {
  2167. FixmedinsName string `json:"fixmedins_name"`
  2168. FixmedinsCode string `json:"fixmedins_code"`
  2169. PsnNo string `json:"psn_no"`
  2170. PsnName string `json:"psn_name"`
  2171. HifobPay float64 `json:"hifob_pay"`
  2172. Gend string `json:"gend"`
  2173. Brdy string `json:"brdy"`
  2174. PsnCertType string `json:"psn_cert_type"`
  2175. PsnType string `json:"psn_type"`
  2176. EmpName string `json:"emp_name"`
  2177. Certno string `json:"certno"`
  2178. Insutype string `json:"insutype"`
  2179. MedfeeSumamt float64 `json:"medfee_sumamt"`
  2180. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  2181. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  2182. PreselfpayAmt float64 `json:"preselfpay_amt"`
  2183. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2184. ActPayDedc float64 `json:"act_pay_dedc"`
  2185. HifpPay float64 `json:"hifp_pay"`
  2186. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  2187. CvlservPay float64 `json:"cvlserv_pay"`
  2188. HifesPay float64 `json:"hifes_pay"`
  2189. HifmiPay float64 `json:"hifmi_pay"`
  2190. MafPay float64 `json:"maf_pay"`
  2191. OthPay float64 `json:"oth_pay"`
  2192. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  2193. PsnPay float64 `json:"psn_pay"`
  2194. AcctPay float64 `json:"acct_pay"`
  2195. CashPayamt float64 `json:"cash_payamt"`
  2196. Balc float64 `json:"balc"`
  2197. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  2198. MedinsSetlId string `json:"medins_setl_id"`
  2199. RefdSetlFlag string `json:"refd_setl_flag"`
  2200. SetlTime string `json:"setl_time"`
  2201. MedType string `json:"med_type"`
  2202. } `json:"setlinfo"`
  2203. } `json:"output"`
  2204. RefmsgTime string `json:"refmsg_time"`
  2205. RespondTime string `json:"respond_time"`
  2206. Signtype interface{} `json:"signtype"`
  2207. WarnMsg interface{} `json:"warn_msg"`
  2208. }
  2209. type Custom struct {
  2210. DetItemFeeSumamt string
  2211. Cut string
  2212. FeedetlSn string
  2213. Price string
  2214. MedListCodg string
  2215. Type int64
  2216. AdviceId int64
  2217. ProjectId int64
  2218. ItemId int64
  2219. }
  2220. //获取个人信息----挂号-----上传就诊信息
  2221. func (c *HisApiController) GetRegisterInfo() {
  2222. id, _ := c.GetInt64("id")
  2223. record_time := c.GetString("record_time")
  2224. settlementValue, _ := c.GetInt64("settlement_value")
  2225. medical_insurance_card := c.GetString("medical_insurance_card")
  2226. name := c.GetString("name")
  2227. id_card_type, _ := c.GetInt64("id_card_type")
  2228. certificates, _ := c.GetInt64("certificates")
  2229. medical_care, _ := c.GetInt64("medical_care")
  2230. birthday := c.GetString("birthday")
  2231. age, _ := c.GetInt64("age")
  2232. id_card := c.GetString("id_card")
  2233. register_type, _ := c.GetInt64("register")
  2234. doctor, _ := c.GetInt64("doctor")
  2235. department, _ := c.GetInt64("department")
  2236. gender, _ := c.GetInt64("sex")
  2237. phone := c.GetString("phone")
  2238. registration_fee, _ := c.GetFloat("registration_fee")
  2239. medical_expenses, _ := c.GetFloat("medical_expenses")
  2240. social_type, _ := c.GetInt64("social_type")
  2241. diagnosis_id, _ := c.GetInt64("diagnosis")
  2242. sick_type, _ := c.GetInt64("sick_type")
  2243. reg_type := c.GetString("p_type")
  2244. timeLayout := "2006-01-02"
  2245. loc, _ := time.LoadLocation("Local")
  2246. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  2247. birthUnix := birthdays.Unix()
  2248. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2249. if err != nil {
  2250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2251. return
  2252. }
  2253. recordDateTime := theTime.Unix()
  2254. adminInfo := c.GetAdminUserInfo()
  2255. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  2256. if tempPatient.ID == 0 {
  2257. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  2258. return
  2259. }
  2260. var patient service.Patients
  2261. if id == 0 {
  2262. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  2263. } else {
  2264. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  2265. }
  2266. if patient.ID == 0 {
  2267. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  2268. return
  2269. }
  2270. if len(patient.IdCardNo) == 0 {
  2271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  2272. return
  2273. }
  2274. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  2275. if len(his) >= 1 {
  2276. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  2277. if len(his) >= 1 && order.ID == 0 {
  2278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  2279. return
  2280. }
  2281. }
  2282. timeStr := time.Now().Format("2006-01-02 15:04:05")
  2283. fmt.Println(timeStr)
  2284. timeArr := strings.Split(timeStr, " ")
  2285. fmt.Println(timeArr)
  2286. timeArrTwo := strings.Split(timeArr[0], "-")
  2287. timeArrThree := strings.Split(timeArr[1], ":")
  2288. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  2289. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  2290. if len(lists) == 0 {
  2291. var hisPatient models.XtHisPatient
  2292. hisPatient = models.XtHisPatient{
  2293. Name: name,
  2294. Age: age,
  2295. Gender: gender,
  2296. Birthday: birthUnix,
  2297. Phone: phone,
  2298. MedicalTreatmentType: medical_care,
  2299. IdType: certificates,
  2300. IdCardNo: id_card,
  2301. BalanceAccountsType: settlementValue,
  2302. SocialType: social_type,
  2303. MedicalInsuranceNumber: medical_insurance_card,
  2304. RegisterType: register_type,
  2305. RegisterCost: registration_fee,
  2306. TreatmentCost: medical_expenses,
  2307. AdminUserId: adminInfo.AdminUser.Id,
  2308. UserOrgId: adminInfo.CurrentOrgId,
  2309. Status: 1,
  2310. RecordDate: recordDateTime,
  2311. IsReturn: 1,
  2312. PatientId: patient.ID,
  2313. Ctime: time.Now().Unix(),
  2314. Mtime: time.Now().Unix(),
  2315. Number: str,
  2316. IdCardType: id_card_type,
  2317. Departments: department,
  2318. Doctor: doctor,
  2319. PType: reg_type,
  2320. Diagnosis: diagnosis_id,
  2321. SickType: sick_type,
  2322. }
  2323. service.CreateHisPatient(&hisPatient)
  2324. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  2325. c.ServeSuccessJSON(map[string]interface{}{
  2326. "his_info": hisPatient,
  2327. })
  2328. } else {
  2329. //chrgBchno := rand.Intn(1000000) + 10000
  2330. var hisPatient models.XtHisPatient
  2331. hisPatient = models.XtHisPatient{
  2332. Name: name,
  2333. Age: age,
  2334. Gender: gender,
  2335. Birthday: birthUnix,
  2336. Phone: phone,
  2337. MedicalTreatmentType: medical_care,
  2338. IdType: certificates,
  2339. IdCardNo: id_card,
  2340. BalanceAccountsType: settlementValue,
  2341. SocialType: social_type,
  2342. MedicalInsuranceNumber: medical_insurance_card,
  2343. RegisterType: register_type,
  2344. RegisterCost: registration_fee,
  2345. TreatmentCost: medical_expenses,
  2346. AdminUserId: adminInfo.AdminUser.Id,
  2347. UserOrgId: adminInfo.CurrentOrgId,
  2348. Status: 1,
  2349. RecordDate: recordDateTime,
  2350. IsReturn: 1,
  2351. PatientId: patient.ID,
  2352. Ctime: time.Now().Unix(),
  2353. Mtime: time.Now().Unix(),
  2354. Number: str,
  2355. IdCardType: id_card_type,
  2356. Departments: department,
  2357. Doctor: doctor,
  2358. PType: reg_type,
  2359. Diagnosis: diagnosis_id,
  2360. SickType: sick_type,
  2361. }
  2362. service.CreateHisPatient(&hisPatient)
  2363. c.ServeSuccessJSON(map[string]interface{}{
  2364. "his_info": hisPatient,
  2365. })
  2366. }
  2367. //timeStr := time.Now().Format("2006-01-02")
  2368. //timeArr := strings.Split(timeStr, "-")
  2369. //var str = timeArr[0] + timeArr[1] + timeArr[2] + strconv.FormatInt(patient.ID, 10)+ ""
  2370. }
  2371. //上传明细----结算
  2372. func (c *HisApiController) GetUploadInfo() {
  2373. id, _ := c.GetInt64("id")
  2374. record_time := c.GetString("record_time")
  2375. his_patient_id, _ := c.GetInt64("his_patient_id")
  2376. pay_way, _ := c.GetInt64("pay_way")
  2377. pay_price, _ := c.GetFloat("pay_price")
  2378. pay_card_no := c.GetString("pay_card_no")
  2379. discount_price, _ := c.GetFloat("discount_price")
  2380. preferential_price, _ := c.GetFloat("preferential_price")
  2381. reality_price, _ := c.GetFloat("reality_price")
  2382. found_price, _ := c.GetFloat("found_price")
  2383. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  2384. private_price, _ := c.GetFloat("private_price")
  2385. timeLayout := "2006-01-02"
  2386. loc, _ := time.LoadLocation("Local")
  2387. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  2388. fapiao_code := c.GetString("fapiao_code")
  2389. fapiao_number := c.GetString("fapiao_number")
  2390. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  2391. if err != nil {
  2392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2393. return
  2394. }
  2395. recordDateTime := theTime.Unix()
  2396. adminUser := c.GetAdminUserInfo()
  2397. var prescriptions []*models.HisPrescription
  2398. var start_time int64
  2399. var end_time int64
  2400. if settle_accounts_type == 1 { //日结
  2401. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime)
  2402. } else { //月结
  2403. start_time_str := c.GetString("start_time")
  2404. end_time_str := c.GetString("end_time")
  2405. timeLayout := "2006-01-02"
  2406. loc, _ := time.LoadLocation("Local")
  2407. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  2408. if err != nil {
  2409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2410. return
  2411. }
  2412. recordStartTime := theStartTime.Unix()
  2413. start_time = recordStartTime
  2414. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  2415. if err != nil {
  2416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2417. return
  2418. }
  2419. recordEndTime := theEndTime.Unix()
  2420. end_time = recordEndTime
  2421. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime)
  2422. }
  2423. his, _ := service.GetVMHisPatientInfo(adminUser.CurrentOrgId, his_patient_id, recordDateTime)
  2424. fmt.Println("~~~~~~~~~")
  2425. fmt.Println(his.Number)
  2426. fmt.Println("~~~~~~~~~")
  2427. timestamp := time.Now().Unix()
  2428. tempTime := time.Unix(timestamp, 0)
  2429. timeFormat := tempTime.Format("20060102150405")
  2430. chrgBchno := rand.Intn(100000) + 10000
  2431. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  2432. strconv.FormatInt(his.PatientId, 10)
  2433. var ids []int64
  2434. for _, item := range prescriptions {
  2435. ids = append(ids, item.ID)
  2436. }
  2437. var total float64
  2438. for _, item := range prescriptions {
  2439. if item.Type == 1 { //药品
  2440. for _, subItem := range item.HisDoctorAdviceInfo {
  2441. total = total + (subItem.Price * subItem.PrescribingNumber)
  2442. }
  2443. }
  2444. if item.Type == 2 { //项目
  2445. for _, subItem := range item.HisPrescriptionProject {
  2446. total = total + (subItem.Price * float64(subItem.Count))
  2447. }
  2448. }
  2449. for _, subItem := range item.HisAdditionalCharge {
  2450. total = total + (subItem.Price * float64(subItem.Count))
  2451. }
  2452. }
  2453. allTotal := fmt.Sprintf("%.2f", total)
  2454. totals, _ := strconv.ParseFloat(allTotal, 64)
  2455. order := &models.HisOrder{
  2456. UserOrgId: adminUser.CurrentOrgId,
  2457. HisPatientId: his.ID,
  2458. PatientId: id,
  2459. SettleAccountsDate: recordDateTime,
  2460. Ctime: time.Now().Unix(),
  2461. Mtime: time.Now().Unix(),
  2462. Status: 1,
  2463. OrderStatus: 2,
  2464. MdtrtId: his.Number,
  2465. Number: chrg_bchno,
  2466. MedfeeSumamt: totals,
  2467. PayWay: pay_way,
  2468. PayPrice: pay_price,
  2469. PayCardNo: pay_card_no,
  2470. DiscountPrice: discount_price,
  2471. PreferentialPrice: preferential_price,
  2472. RealityPrice: reality_price,
  2473. FoundPrice: found_price,
  2474. MedicalInsurancePrice: medical_insurance_price,
  2475. PrivatePrice: private_price,
  2476. SettleEndTime: end_time,
  2477. SettleStartTime: start_time,
  2478. SettleType: settle_accounts_type,
  2479. FaPiaoCode: fapiao_code,
  2480. FaPiaoNumber: fapiao_number,
  2481. PType: 2,
  2482. }
  2483. err = service.CreateOrder(order)
  2484. if err != nil {
  2485. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  2486. return
  2487. }
  2488. var customs []*Custom
  2489. for _, item := range prescriptions {
  2490. if item.Type == 1 { //药品
  2491. for _, subItem := range item.HisDoctorAdviceInfo {
  2492. cus := &Custom{
  2493. AdviceId: subItem.ID,
  2494. ProjectId: 0,
  2495. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  2496. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  2497. FeedetlSn: subItem.FeedetlSn,
  2498. Price: fmt.Sprintf("%.2f", subItem.Price),
  2499. MedListCodg: subItem.MedListCodg,
  2500. Type: 1,
  2501. }
  2502. customs = append(customs, cus)
  2503. }
  2504. }
  2505. if item.Type == 2 { //项目
  2506. for _, subItem := range item.HisPrescriptionProject {
  2507. cus := &Custom{
  2508. AdviceId: 0,
  2509. ProjectId: subItem.ID,
  2510. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*float64(subItem.Count)),
  2511. Cut: fmt.Sprintf("%.2f", float64(subItem.Count)),
  2512. FeedetlSn: subItem.FeedetlSn,
  2513. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  2514. MedListCodg: subItem.MedListCodg,
  2515. Type: 2,
  2516. }
  2517. customs = append(customs, cus)
  2518. }
  2519. }
  2520. for _, item := range item.HisAdditionalCharge {
  2521. cus := &Custom{
  2522. ItemId: item.ID,
  2523. AdviceId: 0,
  2524. ProjectId: 0,
  2525. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  2526. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  2527. FeedetlSn: item.FeedetlSn,
  2528. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  2529. MedListCodg: item.XtHisAddtionConfig.Code,
  2530. Type: 3,
  2531. }
  2532. customs = append(customs, cus)
  2533. }
  2534. }
  2535. for _, item := range customs {
  2536. var advice_id int64 = 0
  2537. var project_id int64 = 0
  2538. var item_id int64 = 0
  2539. var types int64 = 0
  2540. if item.Type == 1 {
  2541. advice_id = item.AdviceId
  2542. project_id = 0
  2543. item_id = 0
  2544. } else if item.Type == 2 {
  2545. advice_id = 0
  2546. item_id = 0
  2547. project_id = item.ProjectId
  2548. } else if item.Type == 3 {
  2549. advice_id = 0
  2550. item_id = item.ItemId
  2551. project_id = 0
  2552. }
  2553. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  2554. cut, _ := strconv.ParseFloat(item.Cut, 32)
  2555. pric, _ := strconv.ParseFloat(item.Price, 32)
  2556. info := &models.HisOrderInfo{
  2557. OrderNumber: order.Number,
  2558. UploadDate: time.Now().Unix(),
  2559. AdviceId: advice_id,
  2560. DetItemFeeSumamt: detItemFeeSumamt,
  2561. Cnt: cut,
  2562. Pric: pric,
  2563. PatientId: id,
  2564. Status: 1,
  2565. Mtime: time.Now().Unix(),
  2566. Ctime: time.Now().Unix(),
  2567. UserOrgId: adminUser.CurrentOrgId,
  2568. HisPatientId: his.ID,
  2569. OrderId: order.ID,
  2570. ProjectId: project_id,
  2571. Type: types,
  2572. ItemId: item_id,
  2573. }
  2574. service.CreateOrderInfo(info)
  2575. }
  2576. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  2577. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  2578. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  2579. if err == nil {
  2580. c.ServeSuccessJSON(map[string]interface{}{
  2581. "msg": "结算成功",
  2582. })
  2583. }
  2584. }
  2585. //退款
  2586. func (c *HisApiController) Refund() {
  2587. order_id, _ := c.GetInt64("order_id")
  2588. //number := c.GetString("number")
  2589. order, _ := service.GetHisOrderByID(order_id)
  2590. adminUser := c.GetAdminUserInfo()
  2591. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  2592. if config.IsOpen == 1 { //对接了医保,走医保流程
  2593. } else {
  2594. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  2595. if err == nil {
  2596. c.ServeSuccessJSON(map[string]interface{}{
  2597. "msg": "退费成功",
  2598. })
  2599. } else {
  2600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2601. return
  2602. }
  2603. }
  2604. }
  2605. func (this *HisApiController) AdditionalCharge() {
  2606. dataBody := make(map[string]interface{}, 0)
  2607. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  2608. fmt.Println(err)
  2609. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  2610. patient_id := int64(dataBody["patient_id"].(float64))
  2611. medicineData, _ := dataBody["medicineData"].([]interface{})
  2612. adminUserInfo := this.GetAdminUserInfo()
  2613. orgId := adminUserInfo.CurrentOrgId
  2614. admin_user_id := adminUserInfo.AdminUser.Id
  2615. timeStr := time.Now().Format("2006-01-02")
  2616. timeLayout := "2006-01-02 15:04:05"
  2617. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  2618. timenow := timeStringToTime.Unix()
  2619. var additionalCharges []*models.HisAdditionalCharge
  2620. for _, item := range medicineData {
  2621. var randNum int
  2622. randNum = rand.Intn(10000) + 1000
  2623. timestamp := time.Now().Unix()
  2624. tempTime := time.Unix(timestamp, 0)
  2625. timeFormat := tempTime.Format("20060102150405")
  2626. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2627. items := item.(map[string]interface{})
  2628. money := items["price"].(string)
  2629. item_id_str := items["item_id"].(string)
  2630. name := items["name"].(string)
  2631. id_str := items["id"].(string)
  2632. moneys, _ := strconv.ParseInt(money, 10, 64)
  2633. monStr := strconv.FormatInt(moneys, 10)
  2634. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  2635. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  2636. id, _ := strconv.ParseInt(id_str, 10, 64)
  2637. additionalCharge := &models.HisAdditionalCharge{
  2638. ID: id,
  2639. HisPatientId: his_patient_id,
  2640. UserOrgId: orgId,
  2641. PatientId: patient_id,
  2642. RecordDate: timenow,
  2643. Price: monneyStr,
  2644. Status: 1,
  2645. ItemName: name,
  2646. ItemId: item_id,
  2647. AdminUserId: admin_user_id,
  2648. CreatedTime: time.Now().Unix(),
  2649. OrderStatus: 0,
  2650. PrescriptionNumber: "",
  2651. BatchNumber: "",
  2652. FeedetlSn: p_number,
  2653. }
  2654. service.CreateAdditionalCharge(additionalCharge)
  2655. additionalCharges = append(additionalCharges, additionalCharge)
  2656. }
  2657. this.ServeSuccessJSON(map[string]interface{}{
  2658. "msg": "添加成功",
  2659. "additional_charges": additionalCharges,
  2660. })
  2661. }
  2662. func (this *HisApiController) DeleteAddition() {
  2663. id, _ := this.GetInt64("id")
  2664. //TODO 需要判断是否已经结算
  2665. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  2666. if err == nil {
  2667. this.ServeSuccessJSON(map[string]interface{}{
  2668. "msg": "删除成功",
  2669. })
  2670. return
  2671. } else {
  2672. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2673. return
  2674. }
  2675. }
  2676. func (this *HisApiController) GetAdminUsers() {
  2677. adminUser := this.GetAdminUserInfo()
  2678. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  2679. this.ServeSuccessJSON(map[string]interface{}{
  2680. "doctors": doctors,
  2681. })
  2682. }
  2683. func (this *HisApiController) GetLastOrNextHisPrescription() {
  2684. change_type, _ := this.GetInt64("type", 0)
  2685. record_date := this.GetString("record_time")
  2686. patient_id, _ := this.GetInt64("patient_id", 0)
  2687. p_type, _ := this.GetInt64("p_type", 0)
  2688. timeLayout := "2006-01-02"
  2689. loc, _ := time.LoadLocation("Local")
  2690. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  2691. record_time := theAdviceRecordTime.Unix()
  2692. adminUserInfo := this.GetAdminUserInfo()
  2693. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  2694. if err == nil {
  2695. if len(prescriptions) == 0 {
  2696. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  2697. return
  2698. } else {
  2699. this.ServeSuccessJSON(map[string]interface{}{
  2700. "prescriptions": prescriptions,
  2701. })
  2702. return
  2703. }
  2704. } else {
  2705. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2706. return
  2707. }
  2708. }
  2709. func (this *HisApiController) GetCallHisPrescription() {
  2710. patient_id, _ := this.GetInt64("patient_id", 0)
  2711. timeLayout := "2006-01-02"
  2712. loc, _ := time.LoadLocation("Local")
  2713. start_time := this.GetString("start_time")
  2714. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2715. end_time := this.GetString("end_time")
  2716. p_type, _ := this.GetInt64("p_type")
  2717. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2718. adminUserInfo := this.GetAdminUserInfo()
  2719. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  2720. if err == nil {
  2721. this.ServeSuccessJSON(map[string]interface{}{
  2722. "prescriptions": prescriptions,
  2723. })
  2724. return
  2725. } else {
  2726. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2727. return
  2728. }
  2729. }
  2730. func (this *HisApiController) GetHisDayPrescription() {
  2731. timeLayout := "2006-01-02"
  2732. loc, _ := time.LoadLocation("Local")
  2733. start_time := this.GetString("start_time")
  2734. patient_id, _ := this.GetInt64("patient_id", 0)
  2735. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2736. end_time := this.GetString("end_time")
  2737. p_type, _ := this.GetInt64("p_type")
  2738. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2739. adminUserInfo := this.GetAdminUserInfo()
  2740. dayHisPrescription, err := service.GetMonthHisPrescriptionThree(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  2741. if err == nil {
  2742. this.ServeSuccessJSON(map[string]interface{}{
  2743. "day_prescription": dayHisPrescription,
  2744. })
  2745. return
  2746. } else {
  2747. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2748. return
  2749. }
  2750. }
  2751. func (c *HisApiController) GetHisChargePatientList() {
  2752. record_date := c.GetString("record_date")
  2753. timeLayout := "2006-01-02"
  2754. loc, _ := time.LoadLocation("Local")
  2755. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2756. if err != nil {
  2757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2758. return
  2759. }
  2760. recordDateTime := theTime.Unix()
  2761. adminInfo := c.GetAdminUserInfo()
  2762. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  2763. tempPatients, _ := service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  2764. var patients []*service.NewTempPatients
  2765. var patients_two []*service.NewTempPatients
  2766. for _, item := range tempPatients {
  2767. //过滤掉没挂号的和没开处方的
  2768. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  2769. patients = append(patients, item)
  2770. }
  2771. //过滤掉没挂号的
  2772. if len(item.HisPatient) > 0 {
  2773. patients_two = append(patients_two, item)
  2774. }
  2775. }
  2776. c.ServeSuccessJSON(map[string]interface{}{
  2777. "list": patients,
  2778. "list_two": patients_two,
  2779. })
  2780. }
  2781. func (c *HisApiController) GetHisUnRegisterPatientList() {
  2782. record_date := c.GetString("record_date")
  2783. timeLayout := "2006-01-02"
  2784. loc, _ := time.LoadLocation("Local")
  2785. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2786. if err != nil {
  2787. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2788. return
  2789. }
  2790. recordDateTime := theTime.Unix()
  2791. adminUser := c.GetAdminUserInfo()
  2792. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  2793. var patients []*service.Patients
  2794. for _, item := range tempPatients {
  2795. if item.HisPatient.ID == 0 {
  2796. patients = append(patients, item)
  2797. }
  2798. }
  2799. c.ServeSuccessJSON(map[string]interface{}{
  2800. "list": patients,
  2801. //"list_two": patients_two,
  2802. })
  2803. }
  2804. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  2805. newArr = make([]*service.Patients, 0)
  2806. for i := 0; i < len(patient); i++ {
  2807. repeat := false
  2808. for j := i + 1; j < len(patient); j++ {
  2809. if patient[i].ID == patient[j].ID {
  2810. repeat = true
  2811. break
  2812. }
  2813. }
  2814. if !repeat {
  2815. newArr = append(newArr, patient[i])
  2816. }
  2817. }
  2818. return
  2819. }
  2820. func (c *HisApiController) GetHisChargePatientInfo() {
  2821. patient_id, _ := c.GetInt64("patient_id")
  2822. his_patient_id, _ := c.GetInt64("his_patient_id")
  2823. record_date := c.GetString("record_date")
  2824. start_time := c.GetString("start_time")
  2825. end_time := c.GetString("end_time")
  2826. order_status, _ := c.GetInt64("type", 0)
  2827. p_type, _ := c.GetInt64("p_type", 0)
  2828. timeLayout := "2006-01-02"
  2829. loc, _ := time.LoadLocation("Local")
  2830. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2831. if err != nil {
  2832. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2833. return
  2834. }
  2835. recordDateTime := theTime.Unix()
  2836. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2837. if err != nil {
  2838. }
  2839. startRecordDateTime := startTime.Unix()
  2840. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2841. if err != nil {
  2842. }
  2843. endRecordDateTime := endTime.Unix()
  2844. admin := c.GetAdminUserInfo()
  2845. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  2846. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  2847. var prescriptions []*models.HisPrescription
  2848. if order_status == 1 || order_status == 0 {
  2849. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  2850. } else if order_status == 2 {
  2851. prescriptions, _ = service.GetChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  2852. }
  2853. var monthPrescriptions []*models.HisPrescription
  2854. if order_status == 1 || order_status == 0 {
  2855. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  2856. } else if order_status == 2 {
  2857. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFour(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  2858. }
  2859. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  2860. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  2861. order, _ := service.GetNewHisOrder(admin.CurrentOrgId, his_patient_info.Number, patient_id)
  2862. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  2863. //获取所有科室信息
  2864. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  2865. c.ServeSuccessJSON(map[string]interface{}{
  2866. "his_info": his_patient_info,
  2867. "xt_info": xt_patient_info,
  2868. "prescription": prescriptions,
  2869. "case_history": case_history,
  2870. "info": patientPrescriptionInfo,
  2871. "month_prescriptions": monthPrescriptions,
  2872. "order": order,
  2873. "doctors": doctors,
  2874. "department": department,
  2875. })
  2876. return
  2877. }
  2878. func (c *HisApiController) GetAllOrderDetail() {
  2879. order_id, _ := c.GetInt64("id", 0)
  2880. order, _ := service.GetHisOrderByID(order_id)
  2881. if order.ID == 0 {
  2882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  2883. return
  2884. }
  2885. org_id := c.GetAdminUserInfo().CurrentOrgId
  2886. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  2887. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  2888. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  2889. c.ServeSuccessJSON(map[string]interface{}{
  2890. "order": order,
  2891. "order_info": order_info,
  2892. "patient": patient,
  2893. "admin_info": adminInfo,
  2894. })
  2895. return
  2896. }
  2897. func (c *HisApiController) GetAllOrderDetailCollect() {
  2898. order_id, _ := c.GetInt64("id", 0)
  2899. order, _ := service.GetHisOrderByID(order_id)
  2900. if order.ID == 0 {
  2901. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  2902. return
  2903. }
  2904. org_id := c.GetAdminUserInfo().CurrentOrgId
  2905. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  2906. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  2907. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  2908. c.ServeSuccessJSON(map[string]interface{}{
  2909. "order": order,
  2910. "order_info": order_info,
  2911. "patient": patient,
  2912. "admin_info": adminInfo,
  2913. })
  2914. return
  2915. }
  2916. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  2917. page, _ := c.GetInt64("page")
  2918. limit, _ := c.GetInt64("limit")
  2919. keywords := c.GetString("keywords")
  2920. start_time := c.GetString("start_time")
  2921. end_time := c.GetString("end_time")
  2922. //clr_type := c.GetString("clr_type")
  2923. insutype := c.GetString("insutype")
  2924. timeLayout := "2006-01-02"
  2925. loc, _ := time.LoadLocation("Local")
  2926. var theStartTIme int64
  2927. if len(start_time) > 0 {
  2928. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2929. theStartTIme = theTime.Unix()
  2930. }
  2931. var theEndtTIme int64
  2932. if len(end_time) > 0 {
  2933. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2934. theEndtTIme = theTime.Unix()
  2935. }
  2936. if page <= 0 {
  2937. page = 1
  2938. }
  2939. if limit <= 0 {
  2940. limit = 10
  2941. }
  2942. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  2943. c.ServeSuccessJSON(map[string]interface{}{
  2944. "total": total,
  2945. "list": list,
  2946. })
  2947. return
  2948. }
  2949. func (c *HisApiController) GetPutOnRecordList() {
  2950. page, _ := c.GetInt64("page")
  2951. limit, _ := c.GetInt64("limit")
  2952. keywords := c.GetString("keywords")
  2953. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  2954. if page <= 0 {
  2955. page = 1
  2956. }
  2957. if limit <= 0 {
  2958. limit = 10
  2959. }
  2960. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  2961. c.ServeSuccessJSON(map[string]interface{}{
  2962. "total": total,
  2963. "list": list,
  2964. })
  2965. return
  2966. }
  2967. func (c *HisApiController) GetCompareData() {
  2968. start_time := c.GetString("start_time")
  2969. end_time := c.GetString("end_time")
  2970. insutype := c.GetString("insutype")
  2971. timeLayout := "2006-01-02"
  2972. loc, _ := time.LoadLocation("Local")
  2973. var theStartTIme int64
  2974. if len(start_time) > 0 {
  2975. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2976. if err != nil {
  2977. theStartTIme = 0
  2978. }
  2979. theStartTIme = theTime.Unix()
  2980. }
  2981. var theEndtTIme int64
  2982. if len(end_time) > 0 {
  2983. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2984. if err != nil {
  2985. theEndtTIme = 0
  2986. }
  2987. theEndtTIme = theTime.Unix()
  2988. }
  2989. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype)
  2990. if err == nil {
  2991. c.ServeSuccessJSON(map[string]interface{}{
  2992. "list": formData,
  2993. })
  2994. } else {
  2995. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  2996. return
  2997. }
  2998. }
  2999. func (c *HisApiController) GetFaPiaoData() {
  3000. order_id, _ := c.GetInt64("order_id")
  3001. patient_id, _ := c.GetInt64("patient_id")
  3002. adminUser := c.GetAdminUserInfo()
  3003. order, _ := service.GetHisOrderByID(order_id)
  3004. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  3005. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  3006. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  3007. his, _ := service.GetHisPatientInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  3008. var bedCostTotal float64 = 0 //床位总费
  3009. var bedCostSelfTotal float64 = 0 //床位自费
  3010. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  3011. var operationCostTotal float64 = 0 //手术费
  3012. var operationCostSelfTotal float64 = 0 //手术费
  3013. var operationCostPartSelfTotal float64 = 0 //手术费
  3014. var otherCostTotal float64 = 0 //其他费用
  3015. var otherCostSelfTotal float64 = 0 //其他费用
  3016. var otherCostPartSelfTotal float64 = 0 //其他费用
  3017. var materialCostTotal float64 = 0 //材料费
  3018. var materialCostSelfTotal float64 = 0 //材料费
  3019. var materialCostPartSelfTotal float64 = 0 //材料费
  3020. var westernMedicineCostTotal float64 = 0 //西药费
  3021. var westernMedicineCostSelfTotal float64 = 0 //西药费
  3022. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  3023. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  3024. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  3025. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  3026. var checkCostTotal float64 = 0 //检查费
  3027. var checkCostSelfTotal float64 = 0 //检查费
  3028. var checkCostPartSelfTotal float64 = 0 //检查费
  3029. var laboratoryCostTotal float64 = 0 //化验费
  3030. var laboratoryCostSelfTotal float64 = 0 //化验费
  3031. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  3032. var treatCostTotal float64 = 0 //治疗费用
  3033. var treatCostSelfTotal float64 = 0 //治疗费用
  3034. var treatCostPartSelfTotal float64 = 0 //治疗费用
  3035. decimal.DivisionPrecision = 2
  3036. for _, item := range orderInfos {
  3037. if item.MedChrgitmType == "01" { //床位费
  3038. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3039. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3040. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3041. }
  3042. if item.MedChrgitmType == "03" { //检查费
  3043. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3044. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3045. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3046. }
  3047. if item.MedChrgitmType == "04" { //化验费
  3048. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3049. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3050. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3051. }
  3052. if item.MedChrgitmType == "05" { //治疗费
  3053. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3054. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3055. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3056. }
  3057. if item.MedChrgitmType == "06" { //手术费
  3058. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3059. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3060. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3061. }
  3062. if item.MedChrgitmType == "08" { //材料费
  3063. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3064. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3065. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3066. }
  3067. if item.MedChrgitmType == "09" { //西药费
  3068. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3069. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3070. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3071. }
  3072. if item.MedChrgitmType == "11" { //中成费
  3073. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3074. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3075. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3076. }
  3077. if item.MedChrgitmType == "14" { //其他费
  3078. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  3079. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  3080. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  3081. }
  3082. }
  3083. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  3084. c.ServeSuccessJSON(map[string]interface{}{
  3085. "order_number": order.Number, //业务流水号
  3086. "id_card_no": his.IdCardNo, //社会保障号
  3087. "department_name": department.Name, //科室
  3088. "number": his.Number, //门诊号
  3089. "date": order.SettleAccountsDate, //结算日期
  3090. "name": order.PsnName, //姓名
  3091. "gender": order.Gend, //性别
  3092. "psn_cash_money": order.PsnCashPay, //个人支付
  3093. "pay_way": "门诊", //结算方式
  3094. "medfee_sumamt": order.MedfeeSumamt, //总费用
  3095. "admin_user_name": admin.UserName, //收款员
  3096. "bedCostTotal": bedCostTotal,
  3097. "bedCostSelfTotal": bedCostSelfTotal,
  3098. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  3099. "operationCostTotal": operationCostTotal,
  3100. "operationCostSelfTotal": operationCostSelfTotal,
  3101. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  3102. "otherCostTotal": otherCostTotal,
  3103. "otherCostSelfTotal": otherCostSelfTotal,
  3104. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  3105. "materialCostTotal": materialCostTotal,
  3106. "materialCostSelfTotal": materialCostSelfTotal,
  3107. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  3108. "westernMedicineCostTotal": westernMedicineCostTotal,
  3109. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  3110. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  3111. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  3112. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  3113. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  3114. "checkCostTotal": checkCostTotal,
  3115. "checkCostSelfTotal": checkCostSelfTotal,
  3116. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  3117. "laboratoryCostTotal": laboratoryCostTotal,
  3118. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  3119. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  3120. "treatCostTotal": treatCostTotal,
  3121. "treatCostSelfTotal": treatCostSelfTotal,
  3122. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  3123. })
  3124. }
  3125. func (this *HisApiController) GetIncomeStatisticsData() {
  3126. start_time := this.GetString("start_time")
  3127. end_time := this.GetString("end_time")
  3128. key_words := this.GetString("key_words")
  3129. limit, _ := this.GetInt64("limit")
  3130. page, _ := this.GetInt64("page")
  3131. if page <= 0 {
  3132. page = 1
  3133. }
  3134. if limit <= 0 {
  3135. limit = 10
  3136. }
  3137. statistics_type, _ := this.GetInt64("statistics_type")
  3138. admin := this.GetAdminUserInfo()
  3139. timeLayout := "2006-01-02"
  3140. loc, _ := time.LoadLocation("Local")
  3141. var theStartTIme int64
  3142. if len(start_time) > 0 {
  3143. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3144. if err != nil {
  3145. theStartTIme = 0
  3146. }
  3147. theStartTIme = theTime.Unix()
  3148. }
  3149. var theEndtTIme int64
  3150. if len(end_time) > 0 {
  3151. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3152. if err != nil {
  3153. theEndtTIme = 0
  3154. }
  3155. theEndtTIme = theTime.Unix()
  3156. }
  3157. if statistics_type == 1 {
  3158. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  3159. this.ServeSuccessJSON(map[string]interface{}{
  3160. "list": list,
  3161. "total": total,
  3162. })
  3163. } else {
  3164. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  3165. this.ServeSuccessJSON(map[string]interface{}{
  3166. "list": list,
  3167. "total": total,
  3168. })
  3169. }
  3170. }
  3171. func (c *HisApiController) PostProjectInformation() {
  3172. adminUser := c.GetAdminUserInfo()
  3173. orgId := adminUser.CurrentOrgId
  3174. dataBody := make(map[string]interface{}, 0)
  3175. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3176. if err != nil {
  3177. utils.ErrorLog(err.Error())
  3178. return
  3179. }
  3180. utils.ErrorLog("%v", dataBody)
  3181. var projectList []*models.HisProject
  3182. var total_goods []interface{}
  3183. tempProjects := dataBody["projects"].([]interface{})
  3184. total_goods = tempProjects
  3185. for index, projectMap := range tempProjects {
  3186. projectM := projectMap.(map[string]interface{})
  3187. var project models.HisProject
  3188. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  3189. utils.ErrorLog("project_name")
  3190. return
  3191. }
  3192. project_name, _ := projectM["project_name"].(string)
  3193. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  3194. err_log := models.ExportErrLog{
  3195. LogType: 6,
  3196. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3197. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  3198. Status: 1,
  3199. CreateTime: time.Now().Unix(),
  3200. UpdateTime: time.Now().Unix(),
  3201. ExportTime: time.Now().Unix(),
  3202. }
  3203. service.CreateExportErrLog(&err_log)
  3204. continue
  3205. }
  3206. project.ProjectName = project_name
  3207. prices := projectM["price"].(string)
  3208. price, _ := strconv.ParseFloat(prices, 64)
  3209. if price <= 0 { //名字为空则生成一条导入错误日志
  3210. err_log := models.ExportErrLog{
  3211. LogType: 6,
  3212. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3213. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  3214. Status: 1,
  3215. CreateTime: time.Now().Unix(),
  3216. UpdateTime: time.Now().Unix(),
  3217. ExportTime: time.Now().Unix(),
  3218. }
  3219. service.CreateExportErrLog(&err_log)
  3220. continue
  3221. }
  3222. project.Price = price
  3223. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  3224. utils.ErrorLog("unit_id")
  3225. return
  3226. }
  3227. unit := projectM["unit"].(string)
  3228. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  3229. err_log := models.ExportErrLog{
  3230. LogType: 6,
  3231. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3232. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  3233. Status: 1,
  3234. CreateTime: time.Now().Unix(),
  3235. UpdateTime: time.Now().Unix(),
  3236. ExportTime: time.Now().Unix(),
  3237. }
  3238. service.CreateExportErrLog(&err_log)
  3239. continue
  3240. }
  3241. project.Unit = unit
  3242. cost_classify := projectM["cost_classify"].(string)
  3243. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  3244. err_log := models.ExportErrLog{
  3245. LogType: 6,
  3246. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3247. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  3248. Status: 1,
  3249. CreateTime: time.Now().Unix(),
  3250. UpdateTime: time.Now().Unix(),
  3251. ExportTime: time.Now().Unix(),
  3252. }
  3253. service.CreateExportErrLog(&err_log)
  3254. continue
  3255. }
  3256. var costClassify = "费用类别"
  3257. var cost_classify_id int64
  3258. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  3259. if len(cost_classify) != 0 {
  3260. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  3261. if errcode == gorm.ErrRecordNotFound {
  3262. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  3263. dataconfig := models.DictDataconfig{
  3264. ParentId: costClassifyConfig.ID,
  3265. Module: "system",
  3266. OrgId: orgId,
  3267. Name: cost_classify,
  3268. FieldName: "",
  3269. Value: costConfig.Value + 1,
  3270. CreatedTime: "",
  3271. UpdatedTime: "",
  3272. CreateUserId: adminUser.AdminUser.Id,
  3273. Status: 1,
  3274. Remark: "",
  3275. DeleteIdSystem: 0,
  3276. Title: "",
  3277. Content: "",
  3278. Order: 0,
  3279. Code: "",
  3280. }
  3281. service.CreatedDicConfig(&dataconfig)
  3282. }
  3283. }
  3284. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  3285. for _, it := range costClassList {
  3286. if cost_classify == it.Name {
  3287. cost_classify_id = int64(it.Value)
  3288. }
  3289. }
  3290. project.CostClassify = cost_classify_id
  3291. executive_section := projectM["executive_section"].(string)
  3292. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  3293. err_log := models.ExportErrLog{
  3294. LogType: 6,
  3295. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3296. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  3297. Status: 1,
  3298. CreateTime: time.Now().Unix(),
  3299. UpdateTime: time.Now().Unix(),
  3300. ExportTime: time.Now().Unix(),
  3301. }
  3302. service.CreateExportErrLog(&err_log)
  3303. continue
  3304. }
  3305. if len(executive_section) != 0 {
  3306. //查找科室是否有内容
  3307. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  3308. if errcodedepart == gorm.ErrRecordNotFound {
  3309. department := models.XtHisDepartment{
  3310. Name: executive_section,
  3311. Status: 1,
  3312. UserOrgId: adminUser.CurrentOrgId,
  3313. CreatedTime: time.Now().Unix(),
  3314. }
  3315. service.CreateDePartment(&department)
  3316. }
  3317. }
  3318. var executive_section_id int64
  3319. departMentList, _ := service.GetAllDepartMent(orgId)
  3320. for _, it := range departMentList {
  3321. if executive_section == it.Name {
  3322. executive_section_id = it.ID
  3323. }
  3324. }
  3325. project.ExecutiveSection = executive_section_id
  3326. medical_coverage := projectM["medical_coverage"].(string)
  3327. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  3328. err_log := models.ExportErrLog{
  3329. LogType: 6,
  3330. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3331. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  3332. Status: 1,
  3333. CreateTime: time.Now().Unix(),
  3334. UpdateTime: time.Now().Unix(),
  3335. ExportTime: time.Now().Unix(),
  3336. }
  3337. service.CreateExportErrLog(&err_log)
  3338. continue
  3339. }
  3340. var medicalCoverage = "医保等级"
  3341. var medical_coverage_id int64
  3342. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  3343. if len(medical_coverage) != 0 {
  3344. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  3345. if errormedicalcoverage == gorm.ErrRecordNotFound {
  3346. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  3347. dataconfig := models.DictDataconfig{
  3348. ParentId: medicalCoverageConfig.ID,
  3349. Module: "system",
  3350. OrgId: orgId,
  3351. Name: medical_coverage,
  3352. FieldName: "",
  3353. Value: medicalCoverageConfig.Value + 1,
  3354. CreatedTime: "",
  3355. UpdatedTime: "",
  3356. CreateUserId: adminUser.AdminUser.Id,
  3357. Status: 1,
  3358. Remark: "",
  3359. DeleteIdSystem: 0,
  3360. Title: "",
  3361. Content: "",
  3362. Order: 0,
  3363. Code: "",
  3364. }
  3365. service.CreatedDicConfig(&dataconfig)
  3366. }
  3367. }
  3368. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  3369. for _, it := range medicalCoverageList {
  3370. if medical_coverage == it.Name {
  3371. medical_coverage_id = int64(it.Value)
  3372. }
  3373. }
  3374. project.MedicalCoverage = medical_coverage_id
  3375. pinyin := projectM["pinyin"].(string)
  3376. project.Pinyin = pinyin
  3377. wubi := projectM["wubi"].(string)
  3378. project.Wubi = wubi
  3379. statistical_classification := projectM["statistical_classification"].(string)
  3380. var statisticalClassification = "统计分类"
  3381. var statistical_classification_id int64
  3382. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  3383. if len(statistical_classification) != 0 {
  3384. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  3385. if classificationerrcodes == gorm.ErrRecordNotFound {
  3386. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  3387. dataconfig := models.DictDataconfig{
  3388. ParentId: classiFication.ID,
  3389. Module: "system",
  3390. OrgId: orgId,
  3391. Name: statistical_classification,
  3392. FieldName: "",
  3393. Value: classiFicationConfig.Value + 1,
  3394. CreatedTime: "",
  3395. UpdatedTime: "",
  3396. CreateUserId: adminUser.AdminUser.Id,
  3397. Status: 1,
  3398. Remark: "",
  3399. DeleteIdSystem: 0,
  3400. Title: "",
  3401. Content: "",
  3402. Order: 0,
  3403. Code: "",
  3404. }
  3405. service.CreatedDicConfig(&dataconfig)
  3406. }
  3407. }
  3408. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  3409. for _, it := range classiFicationList {
  3410. if statistical_classification == it.Name {
  3411. statistical_classification_id = int64(it.Value)
  3412. }
  3413. }
  3414. project.StatisticalClassification = statistical_classification_id
  3415. disease_directory := int64(projectM["disease_directory"].(float64))
  3416. project.DiseaseDirectory = disease_directory
  3417. is_record := int64(projectM["is_record"].(float64))
  3418. project.IsRecord = is_record
  3419. medical_code := projectM["medical_code"].(string)
  3420. project.MedicalCode = medical_code
  3421. tube_color := projectM["tube_color"].(string)
  3422. var tubeColor = "试管颜色"
  3423. var tube_color_id int64
  3424. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  3425. if len(tube_color) != 0 {
  3426. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  3427. if errcodetube == gorm.ErrRecordNotFound {
  3428. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  3429. dataconfig := models.DictDataconfig{
  3430. ParentId: tubeColorConfig.ID,
  3431. Module: "system",
  3432. OrgId: orgId,
  3433. Name: tube_color,
  3434. FieldName: "",
  3435. Value: tubeConfig.Value + 1,
  3436. CreatedTime: "",
  3437. UpdatedTime: "",
  3438. CreateUserId: adminUser.AdminUser.Id,
  3439. Status: 1,
  3440. Remark: "",
  3441. DeleteIdSystem: 0,
  3442. Title: "",
  3443. Content: "",
  3444. Order: 0,
  3445. Code: "",
  3446. }
  3447. service.CreatedDicConfig(&dataconfig)
  3448. }
  3449. }
  3450. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  3451. for _, it := range tubeColorList {
  3452. if tube_color == it.Name {
  3453. tube_color_id = int64(it.Value)
  3454. }
  3455. }
  3456. project.TubeColor = tube_color_id
  3457. single_dose := projectM["single_dose"].(string)
  3458. project.SingleDose = single_dose
  3459. execution_frequency := projectM["execution_frequency"].(string)
  3460. project.ExecutionFrequency = execution_frequency
  3461. delivery_way := projectM["delivery_way"].(string)
  3462. project.DeliveryWay = delivery_way
  3463. number_days := projectM["number_days"].(string)
  3464. project.NumberDays = number_days
  3465. total := projectM["total"].(string)
  3466. project.Total = total
  3467. medical_status := int64(projectM["medical_status"].(float64))
  3468. project.MedicalStatus = medical_status
  3469. category := int64(projectM["category"].(float64))
  3470. project.Category = category
  3471. specail_project := int64(projectM["specail_project"].(float64))
  3472. project.SpecailProject = specail_project
  3473. social_security_directory_code := projectM["social_security_directory_code"].(string)
  3474. project.SocialSecurityDirectoryCode = social_security_directory_code
  3475. remark := projectM["remark"].(string)
  3476. project.Remark = remark
  3477. record_date := projectM["record_date"].(string)
  3478. timeLayout := "2006-01-02"
  3479. loc, _ := time.LoadLocation("Local")
  3480. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3481. project.RecordDate = theTime.Unix()
  3482. projectList = append(projectList, &project)
  3483. }
  3484. export_time := time.Now().Unix()
  3485. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  3486. if len(projectList) > 0 {
  3487. for _, item := range projectList {
  3488. project := models.HisProject{
  3489. ProjectName: item.ProjectName,
  3490. Price: item.Price,
  3491. Unit: item.Unit,
  3492. CostClassify: item.CostClassify,
  3493. ExecutiveSection: item.ExecutiveSection,
  3494. MedicalCoverage: item.MedicalCoverage,
  3495. UserOrgId: orgId,
  3496. Status: 1,
  3497. CreatedTime: time.Now().Unix(),
  3498. Pinyin: item.Pinyin,
  3499. Wubi: item.Wubi,
  3500. StatisticalClassification: item.StatisticalClassification,
  3501. DiseaseDirectory: item.DiseaseDirectory,
  3502. IsRecord: item.IsRecord,
  3503. MedicalCode: item.MedicalCode,
  3504. TubeColor: item.TubeColor,
  3505. SingleDose: item.SingleDose,
  3506. DeliveryWay: item.DeliveryWay,
  3507. NumberDays: item.NumberDays,
  3508. Total: item.Total,
  3509. Category: item.Category,
  3510. MedicalStatus: item.MedicalStatus,
  3511. SpecailProject: item.SpecailProject,
  3512. RecordDate: item.RecordDate,
  3513. Remark: item.Remark,
  3514. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  3515. ExecutionFrequency: item.ExecutionFrequency,
  3516. }
  3517. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  3518. if errcodeproject == gorm.ErrRecordNotFound {
  3519. service.CreateProjectInfomation(&project)
  3520. } else if errcodeproject == nil {
  3521. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  3522. }
  3523. log := models.ExportLog{
  3524. LogType: 6,
  3525. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3526. TotalNum: int64(len(total_goods)),
  3527. FailNum: int64(len(errLogs)),
  3528. SuccessNum: int64(len(projectList)),
  3529. CreateTime: time.Now().Unix(),
  3530. UpdateTime: time.Now().Unix(),
  3531. ExportTime: export_time,
  3532. Status: 1,
  3533. }
  3534. service.CreateExportLog(&log)
  3535. c.ServeSuccessJSON(map[string]interface{}{
  3536. "msg": "导入成功",
  3537. "total_num": len(total_goods),
  3538. "success_num": len(projectList),
  3539. "fail_num": int64(len(errLogs)),
  3540. })
  3541. }
  3542. } else {
  3543. log := models.ExportLog{
  3544. LogType: 6,
  3545. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3546. TotalNum: int64(len(total_goods)),
  3547. FailNum: int64(len(errLogs)),
  3548. SuccessNum: int64(len(projectList)),
  3549. CreateTime: time.Now().Unix(),
  3550. UpdateTime: time.Now().Unix(),
  3551. ExportTime: export_time,
  3552. Status: 1,
  3553. }
  3554. service.CreateExportLog(&log)
  3555. c.ServeSuccessJSON(map[string]interface{}{
  3556. "msg": "导入成功",
  3557. "total_num": len(total_goods),
  3558. "success_num": len(projectList),
  3559. "fail_num": int64(len(errLogs)),
  3560. })
  3561. }
  3562. }
  3563. //func (this *HisApiController) EditProjectInformation(){
  3564. //
  3565. // id, _ := this.GetInt64("id")
  3566. // project_team := this.GetString("project_team")
  3567. // price := this.GetString("price")
  3568. // price_float, _ := strconv.ParseFloat(price, 64)
  3569. // pinyin := this.GetString("pinyin")
  3570. // wubi := this.GetString("wubi")
  3571. // tube_color, _ := this.GetInt64("tube_color")
  3572. // team_type, _ := this.GetInt64("team_type")
  3573. // remark := this.GetString("remark")
  3574. // ids := this.GetString("ids")
  3575. // item_id := this.GetString("item_id")
  3576. // projectTeam := models.XtHisProjectTeam{
  3577. // ProjectTeam: project_team,
  3578. // Price: price_float,
  3579. // Pinyin: pinyin,
  3580. // Wubi: wubi,
  3581. // TubeColor: tube_color,
  3582. // TeamType: team_type,
  3583. // Remark: remark,
  3584. // ProjectId: ids,
  3585. // ItemId: item_id,
  3586. // }
  3587. //
  3588. //
  3589. // dataBody := make(map[string]interface{}, 0)
  3590. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  3591. // if err != nil {
  3592. // utils.ErrorLog(err.Error())
  3593. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3594. // return
  3595. // }
  3596. //
  3597. // err = service.UpdatedProjectTeam(id, &projectTeam)
  3598. //
  3599. //
  3600. // if err != nil {
  3601. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3602. // return
  3603. // }
  3604. //
  3605. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  3606. // infos, _ := dataBody["info"].([]interface{})
  3607. // if len(infos) > 0 {
  3608. // var ids []string
  3609. //
  3610. // for _, item := range infos {
  3611. // items := item.(map[string]interface{})
  3612. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3613. // utils.ErrorLog("id")
  3614. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3615. // return
  3616. // }
  3617. // id := int64(items["id"].(float64))
  3618. //
  3619. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3620. // utils.ErrorLog("type")
  3621. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3622. // return
  3623. // }
  3624. // types := int64(items["type"].(float64))
  3625. //
  3626. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  3627. // utils.ErrorLog("number")
  3628. // }
  3629. //
  3630. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  3631. //
  3632. // projectList := models.XtHisProjectList{
  3633. // Number: number,
  3634. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  3635. // ProjectId: id,
  3636. // Status: 1,
  3637. // CreatedTime: time.Now().Unix(),
  3638. // UpdatedTime: time.Now().Unix(),
  3639. // TeamId: projectTeam.ID,
  3640. // Type: types,
  3641. // }
  3642. // list := projectList
  3643. //
  3644. // service.CreateProjectList(&list)
  3645. //
  3646. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  3647. //
  3648. // }
  3649. // ids_str := strings.Join(ids, ",")
  3650. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  3651. // service.SaveProjectTeam(&projectTeam)
  3652. // this.ServeSuccessJSON(map[string]interface{}{
  3653. // "projectTeam": projectTeam,
  3654. // })
  3655. // }
  3656. // }
  3657. //}
  3658. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  3659. name := c.GetString("name")
  3660. mode_id, _ := c.GetInt64("mode", 0)
  3661. types, _ := c.GetInt64("type", 0)
  3662. patient_id, _ := c.GetInt64("patient_id", 0)
  3663. types = 1
  3664. adminInfo := c.GetAdminUserInfo()
  3665. template := &models.HisPrescriptionTemplate{
  3666. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3667. PatientId: patient_id,
  3668. Type: types,
  3669. Status: 1,
  3670. Ctime: time.Now().Unix(),
  3671. Mtime: time.Now().Unix(),
  3672. Name: name,
  3673. Mode: mode_id,
  3674. }
  3675. dataBody := make(map[string]interface{}, 0)
  3676. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3677. if err != nil {
  3678. utils.ErrorLog(err.Error())
  3679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3680. return
  3681. }
  3682. err = service.CreateHisPrescriptionTemplate(template)
  3683. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3684. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3685. if len(prescriptions) > 0 {
  3686. for _, item := range prescriptions {
  3687. items := item.(map[string]interface{})
  3688. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3689. utils.ErrorLog("type")
  3690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3691. return
  3692. }
  3693. types := int64(items["type"].(float64))
  3694. ctime := time.Now().Unix()
  3695. prescription := &models.HisPrescriptionInfoTemplate{
  3696. PatientId: patient_id,
  3697. UserOrgId: adminInfo.CurrentOrgId,
  3698. Ctime: ctime,
  3699. Mtime: ctime,
  3700. Type: types,
  3701. Modifier: adminInfo.AdminUser.Id,
  3702. Creator: adminInfo.AdminUser.Id,
  3703. Status: 1,
  3704. PTemplateId: template.ID,
  3705. }
  3706. service.CreateHisPrescriptionInfoTemplate(prescription)
  3707. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3708. advices := items["advices"].([]interface{})
  3709. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3710. groupNo := int64(0)
  3711. ctime := time.Now().Unix()
  3712. mtime := ctime
  3713. if len(advices) > 0 {
  3714. for _, advice := range advices {
  3715. var s models.HisPrescriptionAdviceTemplate
  3716. s.PrescriptionId = prescription.ID
  3717. s.AdviceType = 2
  3718. s.StopState = 2
  3719. s.ExecutionState = 2
  3720. s.Status = 1
  3721. s.UserOrgId = adminInfo.CurrentOrgId
  3722. s.Groupno = groupNo
  3723. s.CreatedTime = ctime
  3724. s.UpdatedTime = mtime
  3725. s.PatientId = patient_id
  3726. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  3727. if errcode > 0 {
  3728. c.ServeFailJSONWithSGJErrorCode(errcode)
  3729. return
  3730. }
  3731. service.CreateHisPrescriptionAdviceTemplate(&s)
  3732. }
  3733. }
  3734. }
  3735. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3736. projects := items["project"].([]interface{})
  3737. if len(projects) > 0 {
  3738. for _, project := range projects {
  3739. var p models.HisPrescriptionProjectTemplate
  3740. p.PrescriptionId = prescription.ID
  3741. p.Ctime = time.Now().Unix()
  3742. p.Mtime = time.Now().Unix()
  3743. p.PatientId = patient_id
  3744. p.UserOrgId = adminInfo.CurrentOrgId
  3745. p.Status = 1
  3746. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  3747. if errcode > 0 {
  3748. c.ServeFailJSONWithSGJErrorCode(errcode)
  3749. return
  3750. }
  3751. service.CreateHisPrescriptionProjectTemplate(&p)
  3752. }
  3753. }
  3754. }
  3755. }
  3756. c.ServeSuccessJSON(map[string]interface{}{
  3757. "msg": "创建成功",
  3758. })
  3759. }
  3760. }
  3761. }