his_service.go 208KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760
  1. package service
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "XT_New/models"
  8. "github.com/jinzhu/gorm"
  9. )
  10. type VMSchedule struct {
  11. ID int64 `gorm:"column:id" json:"id" form:"id"`
  12. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  13. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  14. Status int64 `gorm:"column:status" json:"status" form:"status"`
  15. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  16. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  17. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  18. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  19. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  20. }
  21. func (VMSchedule) TableName() string {
  22. return "xt_schedule"
  23. }
  24. type HisPatient struct {
  25. ID int64 `gorm:"column:id" json:"id" form:"id"`
  26. Name string `gorm:"column:name" json:"name" form:"name"`
  27. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  28. Total float64 `gorm:"column:total" json:"total" form:"total"`
  29. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  30. Status int64 `gorm:"column:status" json:"status" form:"status"`
  31. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  32. HisPrescription []*HisPrescription `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  33. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  34. Number string `gorm:"column:number" json:"number" form:"number"`
  35. VMHisOrders []*VMHisOrder `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"orders"`
  36. VMHisOrder VMHisOrder `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"order"`
  37. }
  38. func (HisPatient) TableName() string {
  39. return "his_patient"
  40. }
  41. type VMHisPrescriptionInfo struct {
  42. ID int64 `gorm:"column:id" json:"id" form:"id"`
  43. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  44. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  45. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  46. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  47. Status int64 `gorm:"column:status" json:"status" form:"status"`
  48. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  49. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  50. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  51. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  52. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  53. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  54. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  55. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  56. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  57. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  58. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  59. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  60. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  61. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  62. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  63. }
  64. func (VMHisPrescriptionInfo) TableName() string {
  65. return "his_prescription_info"
  66. }
  67. type VMHisOrder struct {
  68. ID int64 `gorm:"column:id" json:"id" form:"id"`
  69. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  70. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  71. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  72. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  73. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  74. Status int64 `gorm:"column:status" json:"status" form:"status"`
  75. Number string `gorm:"column:number" json:"number" form:"number"`
  76. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  77. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  78. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  79. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  80. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  81. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  82. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  83. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  84. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  85. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  86. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  87. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  88. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  89. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  90. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  91. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  92. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  93. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  94. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  95. CardDesc string `gorm:"card_desc" json:"card_desc" form:"card_desc"`
  96. }
  97. func (VMHisOrder) TableName() string {
  98. return "his_order"
  99. }
  100. type Patients struct {
  101. ID int64 `gorm:"column:id" json:"id" form:"id"`
  102. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  103. Name string `gorm:"column:name" json:"name" form:"name"`
  104. Status int64 `gorm:"column:status" json:"status" form:"status"`
  105. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  106. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  107. Phone int64 `gorm:"column:phone" json:"phone" form:"phone"`
  108. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  109. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  110. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  111. HisPatient HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  112. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  113. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  114. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"order"`
  115. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  116. }
  117. func (Patients) TableName() string {
  118. return "xt_patients"
  119. }
  120. type HisPrescription struct {
  121. ID int64 `gorm:"column:id" json:"id" form:"id"`
  122. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  123. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  124. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  125. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  126. Status int64 `gorm:"column:status" json:"status" form:"status"`
  127. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  128. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  129. }
  130. func (HisPrescription) TableName() string {
  131. return "his_prescription"
  132. }
  133. func GetScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64, patient_type int64) (patients []*Patients, err error) {
  134. db := readDb.Model(&Patients{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,xt_patients.first_letter,xt_patients.patient_type,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 and xt_patients.patient_type <> 4", org_id)
  135. if sch_type != 0 {
  136. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_type = ?", record_date, org_id, sch_type)
  137. } else {
  138. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? ", record_date, org_id)
  139. }
  140. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  141. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  142. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Group("xt_patients.id").Find(&patients).Error
  143. return
  144. }
  145. func GetScheduleHisPatientListTwo(org_id int64, record_date int64) (patients []*Patients, err error) {
  146. db := readDb.Model(&Patients{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,xt_patients.first_letter,xt_patients.patient_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 and xt_patients.patient_type = 4", org_id)
  147. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  148. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  149. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Group("xt_patients.id").Find(&patients).Error
  150. return
  151. }
  152. func GetFuTouHisPatientList(org_id int64, record_date int64) (patients []*Patients, err error) {
  153. db := readDb.Model(&Patients{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,xt_patients.first_letter,xt_patients.patient_type").Where("xt_patients.patient_type = 4 and xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  154. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  155. err = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  156. return
  157. }
  158. func GetChargeHisPatientListOne(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  159. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  160. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  161. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  162. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  163. return
  164. }
  165. func GetAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  166. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  167. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  168. db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  169. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  170. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  171. return
  172. }
  173. func GetChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  174. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  175. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  176. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  177. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  178. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  179. return
  180. }
  181. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  182. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  183. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  184. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  185. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  186. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  187. return
  188. }
  189. type PatientTwo struct {
  190. ID int64 `gorm:"column:id" json:"id" form:"id"`
  191. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  192. Name string `gorm:"column:name" json:"name" form:"name"`
  193. Status int64 `gorm:"column:status" json:"status" form:"status"`
  194. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  195. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  196. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  197. HisPatient []*HisPatientTwo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  198. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  199. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  200. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  201. }
  202. func (PatientTwo) TableName() string {
  203. return "xt_patients"
  204. }
  205. type PatientThree struct {
  206. ID int64 `gorm:"column:id" json:"id" form:"id"`
  207. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  208. Name string `gorm:"column:name" json:"name" form:"name"`
  209. Status int64 `gorm:"column:status" json:"status" form:"status"`
  210. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  211. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  212. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  213. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  214. HisPrescription []models.HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  215. }
  216. func (PatientThree) TableName() string {
  217. return "xt_patients"
  218. }
  219. type HisPatientTwo struct {
  220. ID int64 `gorm:"column:id" json:"id" form:"id"`
  221. Name string `gorm:"column:name" json:"name" form:"name"`
  222. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  223. Total float64 `gorm:"column:total" json:"total" form:"total"`
  224. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  225. Status int64 `gorm:"column:status" json:"status" form:"status"`
  226. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  227. HisPrescriptionTwo []*HisPrescriptionTwo `gorm:"ForeignKey:PatientId,HisPatientId;AssociationForeignKey:PatientId,ID" json:"prescription"`
  228. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  229. Number string `gorm:"column:number" json:"number" form:"number"`
  230. }
  231. func (HisPatientTwo) TableName() string {
  232. return "his_patient"
  233. }
  234. type HisPrescriptionTwo struct {
  235. ID int64 `gorm:"column:id" json:"id" form:"id"`
  236. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  237. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  238. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  239. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  240. Status int64 `gorm:"column:status" json:"status" form:"status"`
  241. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  242. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  243. Number string `gorm:"column:number" json:"number" form:"number"`
  244. Type int64 `gorm:"column:type" json:"type" form:"type"`
  245. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  246. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  247. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  248. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  249. PreTime int64 `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
  250. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  251. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  252. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  253. }
  254. func (HisPrescriptionTwo) TableName() string {
  255. return "his_prescription"
  256. }
  257. func GetNewHisPatientList(org_id int64, record_date int64, sch_type int64, patient_type int64) (patients []*PatientTwo, err error) {
  258. db := readDb.Model(&PatientTwo{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 and xt_patients.patient_type <> 4", org_id).
  259. Joins("join his_patient as hp ON hp.patient_id = xt_patients.id AND hp.record_date = ? AND hp.status = 1 AND hp.user_org_id = ?", record_date, org_id)
  260. if sch_type > 0 {
  261. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND schedule_type = ?", record_date, org_id, sch_type)
  262. }
  263. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  264. return db.Preload("HisPrescriptionTwo", "status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Where("user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  265. })
  266. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("id").Find(&patients).Error
  267. return
  268. }
  269. func GetNewHisPatientListTwo(org_id int64, record_date int64, sch_type int64) (patients []*PatientThree, err error) {
  270. db := readDb.Model(&PatientThree{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  271. //if sch_type > 0 {
  272. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ?", record_date, org_id)
  273. //}
  274. err = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? and his_patient_id = 0", org_id, record_date).Group("id").Find(&patients).Error
  275. return
  276. }
  277. func GetNewScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  278. db := readDb.Model(&PatientTwo{}).Select("xt_patients.id,xt_patients.user_org_id,xt_patients.name,xt_patients.status,xt_patients.id_card_no,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  279. if sch_type != 0 {
  280. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_type = ?", record_date, org_id, sch_type)
  281. } else {
  282. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? ", record_date, org_id)
  283. }
  284. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  285. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("xt_patients.id").Order("sch_type").Find(&patients).Error
  286. return
  287. }
  288. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  289. err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&drugs).Error
  290. return
  291. }
  292. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  293. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  294. return
  295. }
  296. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  297. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  298. return
  299. }
  300. func GetHisPatientInfoThree(org_id int64, number string) (info models.HisPatient, err error) {
  301. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND number = ?", org_id, number).First(&info).Error
  302. return
  303. }
  304. func GetHisPatientInfoTen(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  305. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Last(&info).Error
  306. return
  307. }
  308. func GetHisPatientInfoFour(org_id int64, patient_id int64, record_date int64, his_patient_id int64) (info models.HisPatient, err error) {
  309. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND id = ?", org_id, record_date, patient_id, his_patient_id).First(&info).Error
  310. return
  311. }
  312. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  313. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  314. return
  315. }
  316. func GetNewHisPatientInfoTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  317. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  318. return
  319. }
  320. func GetNewHisHosptialRecordTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  321. err = readDb.Model(&models.HisHospitalCheckRecord{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  322. return
  323. }
  324. func GetHisPatientCount(org_id int64, patient_id int64, record_date int64) (total int64, err error) {
  325. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Count(&total).Error
  326. return
  327. }
  328. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  329. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  330. return
  331. }
  332. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  333. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Last(&info).Error
  334. return
  335. }
  336. func GetLastHisPatientCaseHistory(org_id int64, patient_id int64) (models.HisPatientCaseHistory, error) {
  337. patientCaseHistory := models.HisPatientCaseHistory{}
  338. err := readDb.Where("user_org_id =? and status= 1 and patient_id = ?", org_id, patient_id).Last(&patientCaseHistory).Error
  339. return patientCaseHistory, err
  340. }
  341. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  342. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  343. err = db.Find(&caseHistorys).Error
  344. return
  345. }
  346. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  347. likekey := "%" + keyword + "%"
  348. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  349. if startime > 0 {
  350. db = db.Where("record_date>=?", startime)
  351. }
  352. if endtime > 0 {
  353. db = db.Where("record_date<=?", endtime)
  354. }
  355. if len(keyword) > 0 {
  356. db = db.Where("template_name like ? ", likekey)
  357. }
  358. err = db.Find(&caseHistorys).Error
  359. return
  360. }
  361. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  362. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  363. return caseHistory, err
  364. }
  365. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  366. err = writeDb.Create(&template).Error
  367. return
  368. }
  369. func GetHisPatientCaseHistoryById(patient_id int64, record_date int64, user_org_id int64) (*models.HisPatientCaseHistory, error) {
  370. history := models.HisPatientCaseHistory{}
  371. err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1 and user_org_id = ? and record_date = ?", patient_id, user_org_id, record_date).Find(&history).Error
  372. if err != nil {
  373. if err == gorm.ErrRecordNotFound {
  374. return nil, err
  375. } else {
  376. return nil, err
  377. }
  378. }
  379. return &history, nil
  380. }
  381. func GetLastHisPatientCaseHistoryById(patient_id int64) (models.HisPatientCaseHistory, error) {
  382. history := models.HisPatientCaseHistory{}
  383. err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1", patient_id).Last(&history).Error
  384. return history, err
  385. }
  386. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  387. err := writeDb.Create(&caseHistory).Error
  388. return err
  389. }
  390. func UpdatePatientCaseHistory(patient_id int64, record_date int64, user_org_id int64, his *models.HisPatientCaseHistory) error {
  391. err := XTWriteDB().Model(&his).Where("patient_id = ? and record_date = ? and user_org_id = ? and status =1", patient_id, record_date, user_org_id).Updates(map[string]interface{}{"temperature": his.Temperature, "blood_sugar": his.BloodSugar, "pulse": his.Pulse, "allergic_history": his.AllergicHistory, "diagnose": his.AllergicHistory, "sick": his.Sick, "remark": his.Remark, "doctor_advice": his.DoctorAdvice, "breathing": his.Breathing, "delivery_way": his.DeliveryWay, "diagnostic": his.Diagnostic, "family_history": his.FamilyHistory, "personal_history": his.PersonalHistory, "chief_conplaint": his.ChiefConplaint, "doctor": his.Doctor, "past_history": his.PastHistory, "history_of_present_illness": his.HistoryOfPresentIllness, "is_infect": his.IsInfect, "sick_date": his.SickDate, "symptom": his.Symptom, "sick_type": his.SickType, "blood_fat": his.BloodFat, "sbp": his.Sbp, "dbp": his.Dbp, "primary_disease": his.PrimaryDisease, "confirm_failure_date": his.ConfirmFailureDate, "drug_allergy_history": his.DrugAllergyHistory, "physical_examination": his.PhysicalExamination, "special_inspection": his.SpecialInspection, "lab_apparatus": his.LabApparatus}).Error
  392. return err
  393. }
  394. func SaveHisPrescriptionOne(tx *gorm.DB, prescription *models.HisPrescription) (err error) {
  395. err = tx.Model(&models.HisPrescription{}).Save(prescription).Error
  396. if err != nil {
  397. tx.Rollback()
  398. return
  399. }
  400. tx.Commit()
  401. return
  402. }
  403. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  404. err = writeDb.Model(&models.HisPrescription{}).Save(prescription).Error
  405. return err
  406. }
  407. func SaveHisPrescriptionTwo(prescription *models.HisPrescription) (err error) {
  408. err = writeDb.Model(&models.HisPrescription{}).Save(prescription).Error
  409. return
  410. }
  411. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  412. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  413. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  414. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND prescription_id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  415. return
  416. }
  417. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  418. err = writeDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  419. return
  420. }
  421. func DelelteProject(id int64, user_org_id int64) (err error) {
  422. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  423. return
  424. }
  425. func GetHisPrescription(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  426. err = readDb.Model(&models.HisPrescription{}).
  427. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  428. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  429. }).
  430. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  431. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  432. }).
  433. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  434. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  435. }).
  436. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ?", org_id, record_date, patient_id, p_type).
  437. Find(&prescription).Error
  438. return
  439. }
  440. func GetNewHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  441. err = readDb.Model(&models.HisPrescription{}).
  442. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  443. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  444. }).
  445. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  446. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  447. }).
  448. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  449. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  450. }).
  451. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND his_patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, his_patient_id, p_type).
  452. Find(&prescription).Error
  453. return
  454. }
  455. func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  456. err = readDb.Model(&models.HisPrescription{}).
  457. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  458. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  459. }).
  460. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  461. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  462. }).
  463. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  464. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  465. }).
  466. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status = 2 AND his_patient_id = ? AND p_type = ?", org_id, record_date, patient_id, his_patient_id, p_type).
  467. Find(&prescription).Error
  468. return
  469. }
  470. func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  471. err = readDb.Model(&models.HisPrescription{}).
  472. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  473. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  474. }).
  475. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  476. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  477. }).
  478. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  479. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  480. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  481. return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3 AND order_status <> 2 ", org_id)
  482. }).
  483. Where("(user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND p_type = ?) AND (his_patient_id = ? OR his_patient_id = 0)", org_id, record_date, patient_id, p_type, his_patient_id).
  484. Find(&prescription).Error
  485. return
  486. }
  487. func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  488. err = readDb.Model(&models.HisPrescription{}).
  489. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  490. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  491. }).
  492. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  493. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  494. }).
  495. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  496. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  497. }).
  498. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  499. Find(&prescription).Error
  500. return
  501. }
  502. func GetSettleHisPrescriptionTX(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  503. err = tx.Model(&models.HisPrescription{}).
  504. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  505. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  506. }).
  507. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  508. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  509. }).
  510. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  511. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  512. }).
  513. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  514. Find(&prescription).Error
  515. return
  516. }
  517. func GetSettleHisPrescriptionTXOne(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  518. err = tx.Model(&models.HisPrescription{}).
  519. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  520. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  521. }).
  522. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  523. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  524. }).
  525. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  526. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  527. }).
  528. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND his_patient_id = ? AND p_type <> 1 AND med_type = ?", org_id, record_date, patient_id, his_patient_id, med_type).
  529. Find(&prescription).Error
  530. return
  531. }
  532. func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  533. err = readDb.Model(&models.HisPrescription{}).
  534. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  535. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  536. }).
  537. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  538. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  539. }).
  540. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  541. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  542. }).
  543. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
  544. Find(&prescription).Error
  545. return
  546. }
  547. func GetMonthHisPrescriptionTX(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  548. err = tx.Model(&models.HisPrescription{}).
  549. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  550. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  551. }).
  552. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  553. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  554. }).
  555. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  556. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  557. }).
  558. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
  559. Find(&prescription).Error
  560. return
  561. }
  562. func GetMonthHisPrescriptionTXOne(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  563. err = tx.Model(&models.HisPrescription{}).
  564. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  565. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  566. }).
  567. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  568. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  569. }).
  570. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  571. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  572. }).
  573. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, start_date, end_date, patient_id, med_type).
  574. Find(&prescription).Error
  575. return
  576. }
  577. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  578. err = readDb.Model(&models.HisPrescription{}).
  579. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  580. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  581. }).
  582. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  583. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  584. }).
  585. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  586. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  587. }).
  588. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  589. Find(&prescription).Error
  590. return
  591. }
  592. func GetMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  593. err = readDb.Model(&models.HisPrescription{}).
  594. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  595. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  596. }).
  597. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  598. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  599. }).
  600. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  601. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  602. }).
  603. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? ", org_id, start_date, end_date, patient_id, p_type).
  604. Find(&prescription).Error
  605. return
  606. }
  607. // 未收费
  608. func GetUnChargeMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  609. err = readDb.Model(&models.HisPrescription{}).
  610. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  611. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  612. }).
  613. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  614. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  615. }).
  616. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  617. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  618. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  619. return db.Where("status = 1 AND user_org_id = ?", org_id)
  620. }).
  621. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND order_status <> 4 AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  622. Find(&prescription).Error
  623. return
  624. }
  625. // 已收费
  626. func GetChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  627. err = readDb.Model(&models.HisPrescription{}).
  628. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  629. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  630. }).
  631. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  632. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  633. }).
  634. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  635. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  636. }).
  637. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status = 2 AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  638. Find(&prescription).Error
  639. return
  640. }
  641. func GetUnChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
  642. err = readDb.Model(&models.HisPrescription{}).
  643. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  644. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  645. }).
  646. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  647. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  648. }).
  649. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  650. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  651. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  652. return db.Where("status = 1 AND user_org_id = ?", org_id)
  653. }).
  654. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND order_status <> 3 AND order_status <> 4", org_id, start_date, end_date, patient_id).
  655. Find(&prescription).Error
  656. return
  657. }
  658. type OtherDrugWarehouseInfo struct {
  659. ID int64 `gorm:"column:id" json:"id" form:"id"`
  660. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  661. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  662. Status int64 `gorm:"column:status" json:"status" form:"status"`
  663. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  664. StockMaxNumber int64 `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
  665. StockMinNumber int64 `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
  666. Price float64 `gorm:"column:price" json:"price" form:"price"`
  667. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  668. }
  669. func (OtherDrugWarehouseInfo) TableName() string {
  670. return "xt_drug_warehouse_info"
  671. }
  672. type VMDrugSalesReturnInfo struct {
  673. ID int64 `gorm:"column:id" json:"id" form:"id"`
  674. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  675. Count int64 `gorm:"column:count" json:"count" form:"count"`
  676. Status int64 `gorm:"column:status" json:"status" form:"status"`
  677. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  678. }
  679. func (VMDrugSalesReturnInfo) TableName() string {
  680. return "xt_drug_sales_return_info"
  681. }
  682. type VMDrugWarehouseOutInfo struct {
  683. ID int64 `gorm:"column:id" json:"id" form:"id"`
  684. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  685. Count int64 `gorm:"column:count" json:"count" form:"count"`
  686. Status int64 `gorm:"column:status" json:"status" form:"status"`
  687. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  688. }
  689. func (VMDrugWarehouseOutInfo) TableName() string {
  690. return "xt_drug_warehouse_out_info"
  691. }
  692. type VMDrugCancelStockInfo struct {
  693. ID int64 `gorm:"column:id" json:"id" form:"id"`
  694. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  695. Count int64 `gorm:"column:count" json:"count" form:"count"`
  696. Status int64 `gorm:"column:status" json:"status" form:"status"`
  697. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  698. }
  699. func (VMDrugCancelStockInfo) TableName() string {
  700. return "xt_drug_cancel_stock_info"
  701. }
  702. type BaseDrugLib struct {
  703. ID int64 `gorm:"column:id" json:"id" form:"id"`
  704. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  705. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  706. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  707. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  708. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  709. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  710. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  711. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  712. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  713. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  714. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  715. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  716. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  717. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  718. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  719. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  720. Dose string `gorm:"column:dose" json:"dose" form:"dose"`
  721. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  722. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  723. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  724. MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
  725. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  726. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  727. Number string `gorm:"column:number" json:"number" form:"number"`
  728. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  729. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  730. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  731. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  732. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  733. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  734. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  735. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  736. Code string `gorm:"column:code" json:"code" form:"code"`
  737. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  738. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  739. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  740. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  741. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  742. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  743. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  744. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  745. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  746. Label int64 `gorm:"column:label" json:"label" form:"label"`
  747. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  748. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  749. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  750. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  751. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  752. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  753. Status int64 `gorm:"column:status" json:"status" form:"status"`
  754. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  755. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  756. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  757. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  758. Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
  759. PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
  760. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  761. DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
  762. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  763. DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
  764. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  765. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  766. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  767. //Dosage string `gorm:"column:dosage" json:"dosage" form:"dosage"`
  768. //Unval string `gorm:"column:unval" json:"unval" form:"unval"`
  769. //PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  770. PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
  771. DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
  772. Total float64 `gorm:"column:total" json:"total" form:"total"`
  773. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  774. BatchRetaiPrice float64 `gorm:"column:batch_retai_price" json:"batch_retai_price" form:"batch_retai_price"`
  775. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  776. SumCount int64 `gorm:"column:sum_count" json:"sum_count" form:"sum_count"`
  777. SumInCount int64 `gorm:"column:sum_in_count" json:"sum_in_count" form:"sum_in_count"`
  778. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  779. Bby01 string `gorm:"column:bby01" json:"bby01" form:"bby01"`
  780. IsProject int64 `gorm:"column:is_project" json:"is_project" form:"is_project"`
  781. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  782. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  783. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  784. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  785. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  786. }
  787. func (BaseDrugLib) TableName() string {
  788. return "xt_base_drug"
  789. }
  790. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  791. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  792. return db.Where("(status = 1 and stock_max_number > 0) or (status = 1 AND stock_min_number >0)")
  793. }).Find(&list).Error
  794. //err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Find(&list).Error
  795. return
  796. }
  797. func GetAllDrugLibListSix(org_id int64, storehouse_id int64) (list []*BaseDrugLib, err error) {
  798. if org_id == 10598 {
  799. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  800. return db.Where("(status = 1 and stock_max_number > 0 and storehouse_id = ? ) or (status = 1 AND stock_min_number >0 and storehouse_id = ?)", storehouse_id, storehouse_id)
  801. }).Order("sort asc").Find(&list).Error
  802. return
  803. } else {
  804. if org_id == 10489 {
  805. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0 AND sum_count >0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  806. return db.Where("(status = 1 and stock_max_number > 0 and storehouse_id = ? ) or (status = 1 AND stock_min_number >0 and storehouse_id = ?)", storehouse_id, storehouse_id)
  807. }).Order("sort asc").Find(&list).Error
  808. return
  809. } else {
  810. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  811. return db.Where("(status = 1 and stock_max_number > 0 and storehouse_id = ? ) or (status = 1 AND stock_min_number >0 and storehouse_id = ?)", storehouse_id, storehouse_id)
  812. }).Order("sort asc").Find(&list).Error
  813. return
  814. }
  815. }
  816. }
  817. func GetAllDrugLibListSeven(org_id int64, storehouse_id int64) (list []*BaseDrugLib, err error) {
  818. err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Preload("OtherDrugWarehouseInfo", func(db *gorm.DB) *gorm.DB {
  819. return db.Where("(status = 1 and storehouse_id = ? ) or (status = 1 and storehouse_id = ?)", storehouse_id, storehouse_id)
  820. }).Find(&list).Error
  821. return
  822. }
  823. func GetAllDrugLibs(org_id int64) (drugs []*Drugs, err error) {
  824. db := readDb.Model(&models.BaseDrugLib{}).Preload("Drugs", "status = 1 AND org_id = ? AND find_in_set('停用',drug_status) = 0", org_id).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Group("drug_name")
  825. err = db.Find(&drugs).Error
  826. return
  827. }
  828. func GetAllProjectList(org_id int64, keyword string) (list []*models.HisProject, err error) {
  829. if len(keyword) != 0 {
  830. key := "%" + keyword + "%"
  831. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 AND project_name Like ? ", org_id, key).Find(&list).Error
  832. } else {
  833. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 ", org_id).Find(&list).Error
  834. }
  835. return
  836. }
  837. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  838. err = writeDb.Create(&charge).Error
  839. return
  840. }
  841. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  842. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  843. return db.Select("id,advice_name,advice_desc,single_dose,single_dose_unit,prescribing_number,prescribing_number_unit,delivery_way,execution_frequency,status,created_time,updated_time,parent_id,template_id,drug_spec,drug_spec_unit,advice_type,day_count,week_days,frequency_type,way,drug_id,drug_name_id, IF(parent_id>0, parent_id, id) as advice_order").Where("status = 1").Order("advice_order desc, id")
  844. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  845. return
  846. }
  847. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  848. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  849. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  850. }).Where("org_id = ? AND status = 1 AND user_type = 2", org_id).Find(&doctors).Error
  851. return
  852. }
  853. func CreateHisDoctorAdviceOne(s *models.HisDoctorAdviceInfo, tx *gorm.DB) (err error) {
  854. err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error
  855. if err != nil {
  856. tx.Rollback()
  857. return
  858. }
  859. return
  860. }
  861. func GetHisToday(patient_id int64, advice_date int64, user_org_id int64, drug_id int64, tx *gorm.DB) (list []*models.HisDoctorAdviceInfo, err error) {
  862. err = tx.Where("patient_id = ? and advice_date = ? and user_org_id = ? and status =1 and drug_id = ?", patient_id, advice_date, user_org_id, drug_id).Find(&list).Error
  863. if err != gorm.ErrRecordNotFound {
  864. if err != nil {
  865. tx.Rollback()
  866. return list, err
  867. }
  868. }
  869. return list, err
  870. }
  871. func GetLastDrugAuto(advice_id int64, drug_id int64, advice_date int64, patient_id int64, user_org_id int64, tx *gorm.DB) (models.DrugAutomaticReduceDetail, error) {
  872. automaticReduceDetail := models.DrugAutomaticReduceDetail{}
  873. err := XTReadDB().Where("advice_id = ? and drug_id = ? and record_time= ? and patient_id =? and status=1 and org_id = ?", advice_id, drug_id, advice_date, patient_id, user_org_id).Find(&automaticReduceDetail).Error
  874. if err != gorm.ErrRecordNotFound {
  875. if err != nil {
  876. tx.Rollback()
  877. return automaticReduceDetail, err
  878. }
  879. }
  880. return automaticReduceDetail, err
  881. }
  882. func UpdateTodayHis(drug_id int64, advice_date int64, patient_id int64, user_org_id int64, min_unit string, count_total int64, id int64, tx *gorm.DB) (models.XtDrugAutomaticReduceDetail, error) {
  883. drugAutomaticReduceDetail := models.XtDrugAutomaticReduceDetail{}
  884. err = tx.Model(&drugAutomaticReduceDetail).Where("drug_id = ? and record_time = ? and patient_id =? and org_id = ? and status=1 and advice_id = ?", drug_id, advice_date, patient_id, user_org_id, id).Updates(map[string]interface{}{"count": count_total, "count_unit": min_unit}).Error
  885. if err != nil {
  886. tx.Rollback()
  887. return drugAutomaticReduceDetail, err
  888. }
  889. return drugAutomaticReduceDetail, err
  890. }
  891. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  892. tx := writeDb.Begin()
  893. if err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error; err != nil {
  894. tx.Rollback()
  895. return
  896. }
  897. tx.Commit()
  898. return
  899. }
  900. func CreateHisDoctorAdviceTwo(s *models.HisDoctorAdviceInfo) (err error) {
  901. tx := writeDb.Begin()
  902. if err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error; err != nil {
  903. tx.Rollback()
  904. return
  905. }
  906. tx.Commit()
  907. return
  908. }
  909. func CreateNewHisProjectTwo(project *models.HisPrescriptionProject, tx *gorm.DB) (err error) {
  910. err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error
  911. if err != nil {
  912. tx.Rollback()
  913. return
  914. }
  915. return
  916. }
  917. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  918. err = writeDb.Model(&models.HisPrescriptionProject{}).Save(project).Error
  919. return
  920. }
  921. func GetLastHisProject(patient_id int64, user_org_id int64, record_date int64, tx *gorm.DB, good_id int64) (models.HisPrescriptionProject, error) {
  922. prescriptionProject := models.HisPrescriptionProject{}
  923. err := tx.Where("patient_id = ? and user_org_id = ? and record_date = ? and status=1 and project_id = ? and type =3", patient_id, user_org_id, record_date, good_id).Find(&prescriptionProject).Error
  924. if err != gorm.ErrRecordNotFound {
  925. if err != nil {
  926. tx.Rollback()
  927. return prescriptionProject, err
  928. }
  929. }
  930. return prescriptionProject, err
  931. }
  932. func GetHisWarehouseOutInfo(patient_id int64, user_org_id int64, sys_record_time int64, tx *gorm.DB, good_id int64) (outinfo []*models.WarehouseOutInfo, err error) {
  933. err = tx.Where("patient_id = ? and user_org_id = ? and sys_record_time = ? and good_id = ? an status=1", patient_id, user_org_id, sys_record_time, good_id).Find(&outinfo).Error
  934. return outinfo, err
  935. }
  936. func CreateHisProjectThree(project *models.HisPrescriptionProject) (err error) {
  937. tx := writeDb.Begin()
  938. if err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error; err != nil {
  939. tx.Rollback()
  940. return
  941. }
  942. return
  943. }
  944. func SaveNewHisProjectTwo(project *models.HisPrescriptionProject, tx *gorm.DB) (err error) {
  945. //err = tx.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", project.UserOrgId, project.ID).Updates(map[string]interface{}{"feedetl_sn": project.FeedetlSn, "mtime": time.Now().Unix()}).Error
  946. if err = tx.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", project.UserOrgId, project.ID).Updates(map[string]interface{}{"feedetl_sn": project.FeedetlSn}).Error; err != nil {
  947. tx.Rollback()
  948. return
  949. }
  950. return
  951. }
  952. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  953. err = writeDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? AND id = ?", project.UserOrgId, project.ID).Updates(map[string]interface{}{"feedetl_sn": project.FeedetlSn}).Error
  954. return
  955. }
  956. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  957. err := writeDb.Create(&patient).Error
  958. return err
  959. }
  960. func GetVMHisPatientInfo(org_id int64, id int64, record_date int64) (info models.VMHisPatient, err error) {
  961. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, id).First(&info).Error
  962. return
  963. }
  964. func CreateOrder(order *models.HisOrder) (err error) {
  965. err = writeDb.Create(&order).Error
  966. return
  967. }
  968. func CreateOrderTX(order *models.HisOrder, tx *gorm.DB) (err error) {
  969. err = tx.Create(&order).Error
  970. return
  971. }
  972. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  973. err = writeDb.Create(&order).Error
  974. return
  975. }
  976. func CreateOrderInfoTX(order *models.HisOrderInfo, tx *gorm.DB) (err error) {
  977. err = tx.Create(&order).Error
  978. return
  979. }
  980. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  981. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? AND his_patient_id = ? ", org_id, record_date, patient_id, p_type, his_patient_id).First(&info).Error
  982. return
  983. }
  984. func FindPatientPrescriptionInfoTen(org_id int64, patient_id int64, start_time int64, end_time int64, p_type int64) (info []models.HisPrescriptionInfo, err error) {
  985. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date >= ? and record_date <= ? AND patient_id = ? AND p_type = ?", org_id, start_time, end_time, patient_id, p_type).Find(&info).Error
  986. return
  987. }
  988. func FindPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  989. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, p_type).First(&info).Error
  990. return
  991. }
  992. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  993. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date < ? AND patient_id = ? AND p_type = ? ", org_id, record_date, patient_id, p_type).Last(&info).Error
  994. return
  995. }
  996. func FindHisPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  997. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ? AND his_patient_id = ? ", org_id, record_date, patient_id, p_type, his_patient_id).First(&info).Error
  998. return
  999. }
  1000. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  1001. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date < ? AND patient_id = ?", org_id, record_date, patient_id).Order("record_date desc").First(&info).Error
  1002. return
  1003. }
  1004. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  1005. err = writeDb.Model(&models.HisPrescription{}).Save(&info).Error
  1006. return err
  1007. }
  1008. func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time_timestamp int64, end_time_timestamp int64, doctor_id int64, keywords string, p_type int64, sort_type int64, start_time string, end_time string, charge_type int64, sch_type int64, zone_type int64, med_type int64, fee_type int64) (order []*models.HisOrder, err error, total int64) {
  1009. offset := (page - 1) * limit
  1010. db := readDb.Model(&models.HisOrder{})
  1011. if doctor_id > 0 {
  1012. db = db.Joins("join his_prescription_info as info on info.patient_id = his_order.patient_id AND info.record_date = his_order.settle_accounts_date AND info.doctor_id = ? AND info.user_org_id = ?", doctor_id, user_org_id)
  1013. }
  1014. if len(keywords) > 0 {
  1015. keywords = "%" + keywords + "%"
  1016. db = db.Joins("join xt_patients as patient on patient.id = his_order.patient_id AND patient.user_org_id = ? AND (patient.name like ? or his_order.mdtrt_id like ?)", user_org_id, keywords, keywords)
  1017. }
  1018. if sch_type > 0 && zone_type > 0 {
  1019. db = db.Joins("join xt_schedule sch on sch.schedule_date = his_order.settle_accounts_date AND sch.patient_id = his_order.patient_id AND sch.schedule_type = ? AND sch.schedule_date >= ? AND sch.schedule_date <= ? AND sch.partition_id = ? AND sch.status = 1", sch_type, start_time_timestamp, end_time_timestamp, zone_type)
  1020. }
  1021. if sch_type > 0 && zone_type == 0 {
  1022. db = db.Joins("join xt_schedule sch on sch.schedule_date = his_order.settle_accounts_date AND sch.patient_id = his_order.patient_id AND sch.schedule_type = ? AND sch.schedule_date >= ? AND sch.schedule_date <= ? AND sch.status = 1", sch_type, start_time_timestamp, end_time_timestamp)
  1023. }
  1024. if sch_type == 0 && zone_type > 0 {
  1025. db = db.Joins("join xt_schedule sch on sch.schedule_date = his_order.settle_accounts_date AND sch.patient_id = his_order.patient_id AND sch.schedule_date >= ? AND sch.schedule_date <= ? AND sch.partition_id = ? AND sch.status = 1", start_time_timestamp, end_time_timestamp, zone_type)
  1026. }
  1027. if med_type > 0 {
  1028. db = db.Where("his_order.med_type = ?", med_type)
  1029. }
  1030. if fee_type > 0 {
  1031. if fee_type == 2 {
  1032. db = db.Where("his_order.is_medicine_insurance <> 1")
  1033. }
  1034. if fee_type == 1 {
  1035. db = db.Where("his_order.is_medicine_insurance = 1")
  1036. }
  1037. }
  1038. //if zone_type > 0 {
  1039. // db = db.Joins("join xt_schedule sch_two on sch_two.schedule_date = his_order.settle_accounts_date AND sch_two.patient_id = his_order.patient_id AND sch_two.partition_id = ?", zone_type)
  1040. //}
  1041. if sort_type == 1 {
  1042. if start_time_timestamp != 0 {
  1043. db = db.Where("his_order.settle_accounts_date>=?", start_time_timestamp)
  1044. }
  1045. if end_time_timestamp != 0 {
  1046. db = db.Where("his_order.settle_accounts_date<=?", end_time_timestamp)
  1047. }
  1048. } else {
  1049. if len(start_time) != 0 {
  1050. db = db.Where("his_order.setl_time>=?", start_time+" 00:00:00")
  1051. }
  1052. if len(end_time) != 0 {
  1053. db = db.Where("his_order.setl_time<=?", end_time+" 23:59:59")
  1054. }
  1055. }
  1056. if p_type > 0 {
  1057. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.p_type = ? AND his_order.order_status = 2", user_org_id, p_type)
  1058. } else {
  1059. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2", user_org_id)
  1060. }
  1061. if charge_type > 0 {
  1062. if charge_type == 2 {
  1063. db = db.Where("his_order.is_medicine_insurance = 0")
  1064. } else {
  1065. db = db.Where("his_order.is_medicine_insurance = ?", charge_type)
  1066. }
  1067. }
  1068. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1069. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  1070. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  1071. Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ?", user_org_id)
  1072. db = db.Preload("HisFundSettleListResult", "status = 1")
  1073. db = db.Count(&total)
  1074. db = db.Limit(limit).Offset(offset)
  1075. if user_org_id == 10215 {
  1076. if sort_type == 1 {
  1077. err = db.Order("settle_accounts_date asc,ctime asc").Group("his_order.id").Find(&order).Error
  1078. }
  1079. if sort_type == 2 {
  1080. err = db.Order("setl_time asc,ctime asc").Group("his_order.id").Find(&order).Error
  1081. }
  1082. } else {
  1083. if sort_type == 1 {
  1084. err = db.Order("settle_accounts_date desc,ctime desc").Group("his_order.id").Find(&order).Error
  1085. }
  1086. if sort_type == 2 {
  1087. err = db.Order("setl_time desc,ctime desc").Group("his_order.id").Find(&order).Error
  1088. }
  1089. }
  1090. return
  1091. }
  1092. func GetNewHisOrderListTwo(user_org_id int64, start_time_timestamp int64, end_time_timestamp int64) (order []*models.HisOrderELE, err error) {
  1093. db := readDb.Model(&models.HisOrderELE{})
  1094. if start_time_timestamp != 0 {
  1095. db = db.Where("his_order.settle_accounts_date>=?", start_time_timestamp)
  1096. }
  1097. if end_time_timestamp != 0 {
  1098. db = db.Where("his_order.settle_accounts_date<=?", end_time_timestamp)
  1099. }
  1100. db = db.Where("user_org_id = ? and order_status = 2 and status = 1", user_org_id)
  1101. err = db.Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).Find(&order).Error
  1102. return
  1103. }
  1104. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  1105. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  1106. return
  1107. }
  1108. func UpDatePrescriptionNumberTX(user_org_id int64, ids []int64, number string, tx *gorm.DB) (err error) {
  1109. err = tx.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  1110. return
  1111. }
  1112. func UpDateAddtionNumber(user_org_id int64, ids []int64, number string) (err error) {
  1113. err = writeDb.Model(&models.HisAdditionalCharge{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  1114. return
  1115. }
  1116. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  1117. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND record_date = ?", user_org_id, id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1118. return
  1119. }
  1120. func UpDateHisPrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64) (err error) {
  1121. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ? AND record_date = ?", user_org_id, his_patient_id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1122. return
  1123. }
  1124. func UpDateHisPrescriptionInfoNumberTX(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64, tx *gorm.DB) (err error) {
  1125. err = tx.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ? AND record_date = ?", user_org_id, his_patient_id, record_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1126. return
  1127. }
  1128. func UpDateHospitalHisPrescriptionInfoNumber(user_org_id int64, number string, start_time int64, end_time int64) (err error) {
  1129. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date <= ? AND record_date >= ? ", user_org_id, end_time, start_time).Updates(map[string]interface{}{"batch_number": number, "prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1130. return
  1131. }
  1132. type HisOrder struct {
  1133. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1134. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1135. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1136. Number string `gorm:"column:number" json:"number" form:"number"`
  1137. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1138. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1139. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1140. Infcode int64 `gorm:"column:infcode" json:"infcode" form:"infcode"`
  1141. WarnMsg string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
  1142. Cainfo string `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
  1143. ErrMsg string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
  1144. RespondTime string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
  1145. InfRefmsgid string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
  1146. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1147. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  1148. SetlId string `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
  1149. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1150. PsnType string `gorm:"column:psn_type" json:"psn_type" form:"psn_type"`
  1151. CvlservFlag string `gorm:"column:cvlserv_flag" json:"cvlserv_flag" form:"cvlserv_flag"`
  1152. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  1153. MdtrtCertType string `gorm:"column:mdtrt_cert_type" json:"mdtrt_cert_type" form:"mdtrt_cert_type"`
  1154. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1155. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1156. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1157. OverlmtSelfPay float64 `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
  1158. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  1159. InscpScpAmt float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
  1160. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  1161. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  1162. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1163. PoolPropSelfpay float64 `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
  1164. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1165. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1166. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1167. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1168. OthPay float64 `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
  1169. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1170. PsnPartAmt float64 `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
  1171. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1172. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1173. HospPartAmt float64 `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
  1174. Balc float64 `gorm:"column:balc" json:"balc" form:"balc"`
  1175. AcctMulaidPay float64 `gorm:"column:acct_mulaid_pay" json:"acct_mulaid_pay" form:"acct_mulaid_pay"`
  1176. MedinsSetlId string `gorm:"column:medins_setl_id" json:"medins_setl_id" form:"medins_setl_id"`
  1177. ClrOptins string `gorm:"column:clr_optins" json:"clr_optins" form:"clr_optins"`
  1178. ClrWay string `gorm:"column:clr_way" json:"clr_way" form:"clr_way"`
  1179. ClrType string `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
  1180. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1181. IsMedicineInsurance int64 `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
  1182. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1183. SettleType int64 `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
  1184. SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
  1185. SettleEndTime int64 `gorm:"column:settle_end_time" json:"settle_end_time" form:"settle_end_time"`
  1186. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1187. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  1188. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1189. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  1190. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  1191. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  1192. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1193. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1194. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1195. }
  1196. func (HisOrder) TableName() string {
  1197. return "his_order"
  1198. }
  1199. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  1200. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  1201. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1202. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  1203. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  1204. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1205. Order("ctime desc").
  1206. Find(&order).Error
  1207. return
  1208. }
  1209. func GetHisPrescriptionThree(org_id int64, patient_id int64, number string) (prescription []*models.HisPrescription, err error) {
  1210. err = readDb.Model(&models.HisPrescription{}).
  1211. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  1212. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1213. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1214. }).
  1215. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1216. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND batch_number=?", org_id, patient_id, number).
  1217. Find(&prescription).Error
  1218. return
  1219. }
  1220. type HisPrescriptionInfo struct {
  1221. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1222. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1223. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1224. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1225. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1226. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1227. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1228. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1229. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1230. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1231. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1232. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  1233. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1234. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1235. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  1236. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1237. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  1238. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  1239. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1240. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1241. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  1242. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1243. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1244. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1245. }
  1246. func (HisPrescriptionInfo) TableName() string {
  1247. return "his_prescription_info"
  1248. }
  1249. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  1250. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  1251. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  1252. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  1253. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  1254. Order("ctime desc").Find(&prescriptionOrder).Error
  1255. return
  1256. }
  1257. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  1258. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, org_id).
  1259. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  1260. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  1261. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  1262. return
  1263. }
  1264. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  1265. err = readDb.Model(&models.HisPrescription{}).
  1266. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  1267. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1268. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  1269. }).
  1270. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  1271. Find(&prescription).Error
  1272. return
  1273. }
  1274. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  1275. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  1276. return
  1277. }
  1278. func UpdataOrderStatus(id int64, number string, user_org_id int64) (err error) {
  1279. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "status": 0}).Error
  1280. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
  1281. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  1282. return
  1283. }
  1284. func UpdataOrderStatusten(id int64, number string, user_org_id int64) (err error) {
  1285. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "status": 0}).Error
  1286. //err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  1287. return
  1288. }
  1289. func UpdataHospitalOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  1290. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix(), "refund_request_log": log, "refund_log": result, "status": 1}).Error
  1291. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 4, "mtime": time.Now().Unix()}).Error
  1292. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 4, "mtime": time.Now().Unix()}).Error
  1293. return
  1294. }
  1295. func UpdataOrderStatusTen(id int64, number string, user_org_id int64) (err error) {
  1296. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 1, "mtime": time.Now().Unix()}).Error
  1297. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 1, "mtime": time.Now().Unix()}).Error
  1298. return
  1299. }
  1300. func UpdataOrderInfoStatus(id int64, number string, user_org_id int64) {
  1301. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  1302. err = writeDb.Model(&models.HisOrderInfo{}).Where("status = 1 AND user_org_id = ? AND order_number = ?", user_org_id, number).Updates(map[string]interface{}{"mtime": time.Now().Unix(), "status": 0}).Error
  1303. return
  1304. }
  1305. func SaveHisPatient(his models.HisPatient) (err error) {
  1306. writeDb.Model(&models.HisPatient{}).Where("status = 1 AND record_date =? AND user_org_id = ? AND id = ?", his.RecordDate, his.UserOrgId, his.ID).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  1307. writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", his.UserOrgId, his.ID).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  1308. writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", his.UserOrgId, his.ID).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  1309. return
  1310. }
  1311. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  1312. writeDb.Model(&models.HisPatient{}).Where("patient_id = ? AND status = 1 AND record_date =? AND user_org_id = ?", patient_id, record_time, org_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  1313. }
  1314. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  1315. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  1316. return
  1317. }
  1318. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  1319. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  1320. First(&order).Error
  1321. return
  1322. }
  1323. func UpDateOrder(order models.HisOrder) (err error) {
  1324. err = writeDb.Save(&order).Error
  1325. return
  1326. }
  1327. func UpDateOrderTX(order models.HisOrder, tx *gorm.DB) (err error) {
  1328. err = writeDb.Save(&order).Error
  1329. return
  1330. }
  1331. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  1332. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 2, "mtime": time.Now().Unix()}).Error
  1333. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1334. return
  1335. }
  1336. func UpdataOrderStatusTwoTX(number string, user_org_id int64, tx *gorm.DB) (err error) {
  1337. err = tx.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 2, "mtime": time.Now().Unix()}).Error
  1338. err = tx.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 3, "mtime": time.Now().Unix()}).Error
  1339. return
  1340. }
  1341. func CreateErrMsgLog(log *models.HisOrderError) {
  1342. writeDb.Model(&models.HisOrderError{}).Create(&log)
  1343. }
  1344. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  1345. err = readDb.Model(&models.VMHisPatient{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Count(&total).Error
  1346. return
  1347. }
  1348. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  1349. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  1350. return
  1351. }
  1352. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  1353. db := readDb.Model(&models.OutpatientServiceSick{})
  1354. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1355. err = db.Order("ctime desc").Find(&list).Error
  1356. return
  1357. }
  1358. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  1359. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  1360. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1361. err = db.Order("ctime desc").Find(&list).Error
  1362. return
  1363. }
  1364. func FindPatientDianose(orgId int64) (list []*models.XtPatientDiagnose, err error) {
  1365. err = readDb.Where("user_org_id =?", orgId).Find(&list).Error
  1366. return list, err
  1367. }
  1368. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  1369. db := readDb.Model(&models.XtHisAddtionConfig{})
  1370. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1371. err = db.Order("ctime desc").Find(&list).Error
  1372. return
  1373. }
  1374. type XtHisOrder struct {
  1375. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1376. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1377. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1378. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1379. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1380. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1381. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1382. Number string `gorm:"column:number" json:"number" form:"number"`
  1383. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1384. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  1385. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1386. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  1387. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  1388. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  1389. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1390. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1391. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1392. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1393. }
  1394. func (XtHisOrder) TableName() string {
  1395. return "his_order"
  1396. }
  1397. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  1398. err = readDb.Model(&models.HisPrescription{}).
  1399. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  1400. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1401. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1402. }).
  1403. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1404. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  1405. Find(&prescription).Error
  1406. return
  1407. }
  1408. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  1409. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date = ?", org_id, patient_id, record_time).Find(&addition).Error
  1410. return
  1411. }
  1412. func DelelteAddition(id int64, user_org_id int64) (err error) {
  1413. err = writeDb.Model(&models.HisAdditionalCharge{}).Where("user_org_id = ? AND id = ?", user_org_id, id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  1414. return
  1415. }
  1416. func GetNewHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64, sch_type int64) (patients []*VMHisHospitalPrescriptionInfo, err error, total int64) {
  1417. offset := (page - 1) * limit
  1418. db := readDb.Model(&VMHisHospitalPrescriptionInfo{}).Where("his_prescription_info.user_org_id = ? AND his_prescription_info.status = 1 AND his_prescription_info.record_date = ? AND his_prescription_info.p_type <> 1 ", org_id, record_date)
  1419. if len(keywords) > 0 {
  1420. keywords = "%" + keywords + "%"
  1421. db = db.Joins("JOIN xt_patients On his_prescription_info.patient_id = xt_patients.id AND xt_patients.name like ?", keywords)
  1422. }
  1423. if sch_type > 0 {
  1424. db = db.Joins("JOIN xt_schedule On xt_schedule.status = 1 AND his_prescription_info.patient_id = xt_schedule.patient_id AND xt_schedule.schedule_date = ? AND xt_schedule.schedule_type = ?", record_date, sch_type)
  1425. }
  1426. db = db.Preload("Patients", "xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1427. db = db.Preload("HisPrescription", "his_prescription.user_org_id = ? AND his_prescription.status = 1 AND his_prescription.p_type <> 1", org_id)
  1428. db = db.Count(&total)
  1429. err = db.Limit(limit).Offset(offset).Group("his_prescription_info.id").Find(&patients).Error
  1430. return
  1431. }
  1432. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMSchedule, err error, total int64) {
  1433. offset := (page - 1) * limit
  1434. db := readDb.Model(&VMSchedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  1435. if len(keywords) > 0 {
  1436. keywords = "%" + keywords + "%"
  1437. db = db.Joins("JOIN xt_patients as p On xt_schedule.patient_id = p.id AND p.user_org_id = ? AND p.name like ?", org_id, keywords)
  1438. db = db.Joins("JOIN his_prescription_info as info On xt_schedule.patient_id = info.patient_id AND info.user_org_id = ? AND info.record_date = ? AND info.prescription_number like ? AND info.p_type <> 1", org_id, record_date, keywords)
  1439. }
  1440. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  1441. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  1442. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id).
  1443. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id)
  1444. db = db.Count(&total)
  1445. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  1446. return
  1447. }
  1448. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  1449. patient := models.VMHisPatient{}
  1450. err := XTWriteDB().Model(&patient).Where("patient_id = ? and record_date = ? and user_org_id = ? and status = 1", patientid, recorddate, orgid).Updates(map[string]interface{}{"is_return": 3}).Error
  1451. return patient, err
  1452. }
  1453. type VMOtherHisPrescriptionInfo struct {
  1454. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1455. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1456. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1457. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1458. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1459. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  1460. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1461. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1462. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  1463. }
  1464. func (VMOtherHisPrescriptionInfo) TableName() string {
  1465. return "his_prescription_info"
  1466. }
  1467. type VMHisPrescription struct {
  1468. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1469. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1470. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1471. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1472. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1473. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1474. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1475. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1476. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1477. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  1478. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1479. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1480. }
  1481. func (VMHisPrescription) TableName() string {
  1482. return "his_prescription"
  1483. }
  1484. func GetHisPrescriptionByType(change_type int64, record_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1485. if change_type == 1 { //根据日期取出上一方数据
  1486. var Id AdviceDate
  1487. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date < ? AND p_type = ?", patient_id, org_id, record_time, p_type).Select("record_date").Group("record_date").Order("record_date asc").Scan(&Id).Error
  1488. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND p_type = ?", patient_id, org_id, Id.RecordDate, p_type).
  1489. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1490. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1491. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1492. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1493. }).
  1494. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1495. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1496. })
  1497. }).Find(&advice).Error
  1498. } else if change_type == 2 {
  1499. var Id AdviceDate
  1500. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date > ? AND p_type = ?", patient_id, org_id, record_time, p_type).Select("record_date").Group("record_date").Order("record_date desc").Scan(&Id).Error
  1501. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date = ? AND p_type = ?", patient_id, org_id, Id.RecordDate, p_type).
  1502. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1503. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1504. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1505. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1506. }).
  1507. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1508. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1509. })
  1510. }).Find(&advice).Error
  1511. }
  1512. return
  1513. }
  1514. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64, p_type int64) (advice []VMOtherHisPrescriptionInfo, err error) {
  1515. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ? AND p_type = ?", patient_id, org_id, start_time, end_time, p_type).
  1516. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1517. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1518. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1519. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1520. }).
  1521. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1522. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1523. })
  1524. }).Order("record_date desc").Find(&advice).Error
  1525. return
  1526. }
  1527. func GetMobileCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1528. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ?", patient_id, org_id, start_time, end_time).
  1529. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1530. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1531. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1532. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1533. }).
  1534. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1535. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1536. })
  1537. }).Find(&advice).Error
  1538. return
  1539. }
  1540. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1541. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1542. return
  1543. }
  1544. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  1545. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1546. return
  1547. }
  1548. func GetHisOrderByIDTX(order_id int64, tx *gorm.DB) (order models.HisOrder, err error) {
  1549. err = tx.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1550. return
  1551. }
  1552. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1553. err = readDb.Model(&models.HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1554. return
  1555. }
  1556. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  1557. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND settle_accounts_date <= ? AND settle_accounts_date >= ? AND insutype = ? AND clr_type = ? ", org_id, end_time, start_time, insutype, clr_type).Find(&orders).Error
  1558. return
  1559. }
  1560. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  1561. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND settle_accounts_date <= ? AND settle_accounts_date >= ? ", org_id, end_time, start_time).Find(&orders).Error
  1562. return
  1563. }
  1564. func GetHisDoctorAdvicesById(id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1565. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND id = ?", id).First(&advice).Error
  1566. return
  1567. }
  1568. func GetAdditionChargeByID(org_id int64, id int64) (addition models.XtHisAddtionConfig, err error) {
  1569. err = readDb.Model(&models.XtHisAddtionConfig{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&addition).Error
  1570. return
  1571. }
  1572. func GetHisPrescriptionByID(org_id int64, id int64) (pre models.HisPrescription, err error) {
  1573. err = readDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&pre).Error
  1574. return
  1575. }
  1576. func GetHisProjectByID(id int64) (project models.HisPrescriptionProject, err error) {
  1577. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id = ?", id).First(&project).Error
  1578. return
  1579. }
  1580. func GetHisAdditionByID(id int64) (addition models.HisAdditionalCharge, err error) {
  1581. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND id = ?", id).First(&addition).Error
  1582. return
  1583. }
  1584. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1585. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  1586. return
  1587. }
  1588. func GetPatientByIDCardAndName(id_card_no string, user_org_id int64, name string) (patient Patients, err error) {
  1589. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ? AND name = ?", id_card_no, user_org_id, name).First(&patient).Error
  1590. return
  1591. }
  1592. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1593. err = readDb.Model(&models.HisOrder{}).Where("patient_id = ? AND user_org_id = ? AND settle_accounts_date = ? AND status = 1", patient_id, user_org_id, record_time).First(&order).Error
  1594. return
  1595. }
  1596. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1597. var patient Patients
  1598. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1599. return patient, err
  1600. }
  1601. func GetPatientByIDTenTwo(orgID int64, patientID int64) (models.PatientTwos, error) {
  1602. var patient models.PatientTwos
  1603. err := readDb.Model(&models.PatientTwos{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1604. return patient, err
  1605. }
  1606. func GetHisPrescriptionByPatientID(patientID int64, orgID int64) (info models.HisPrescriptionInfo, err error) {
  1607. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND patient_id = ? AND status = 1", orgID, patientID).Preload("XtHisDepartment", "status = 1").Last(&info).Error
  1608. return
  1609. }
  1610. type VMHisProjectTeam struct {
  1611. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1612. ProjectTeam string `gorm:"column:project_team" json:"project_team" form:"project_team"`
  1613. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1614. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  1615. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  1616. TubeColor int64 `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
  1617. TeamType int64 `gorm:"column:team_type" json:"team_type" form:"team_type"`
  1618. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1619. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1620. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1621. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1622. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1623. ProjectId string `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1624. VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
  1625. ItemId string `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1626. DrugItemId string `gorm:"column:drug_item_id" json:"drug_item_id" form:"drug_item_id"`
  1627. }
  1628. func (VMHisProjectTeam) TableName() string {
  1629. return "xt_his_project_team"
  1630. }
  1631. type VMHisProject struct {
  1632. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1633. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1634. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1635. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1636. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  1637. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  1638. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1639. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1640. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1641. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1642. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1643. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  1644. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  1645. }
  1646. func (VMHisProject) TableName() string {
  1647. return "xt_his_project"
  1648. }
  1649. type VMItemProjectList struct {
  1650. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1651. Number int64 `gorm:"column:number" json:"number" form:"number"`
  1652. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1653. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1654. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1655. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1656. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1657. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1658. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1659. VMHisProject VMHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1660. GoodInfo GoodInfo `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"good_info"`
  1661. }
  1662. func (VMItemProjectList) TableName() string {
  1663. return "xt_his_project_list"
  1664. }
  1665. type VMHisPrescriptionTwo struct {
  1666. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1667. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1668. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1669. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1670. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1671. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1672. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1673. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1674. }
  1675. func (VMHisPrescriptionTwo) TableName() string {
  1676. return "his_prescription"
  1677. }
  1678. func GetAllProjectTeamList(orgid int64) (project []*VMHisProjectTeam, err error) {
  1679. err = XTReadDB().Model(&VMHisProjectTeam{}).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1680. for _, item := range project {
  1681. var project_item []*VMItemProjectList
  1682. ids := strings.Split(item.ItemId, ",")
  1683. XTReadDB().Model(&VMItemProjectList{}).Where("status = 1 AND id IN (?)", ids).Preload("VMHisProject", "status = 1 AND user_org_id = ?", orgid).Preload("GoodInfo", "status = 1 AND org_id = ?", orgid).Find(&project_item)
  1684. item.VMItemProjectList = append(item.VMItemProjectList, project_item...)
  1685. }
  1686. return
  1687. }
  1688. type HisDoctorAdviceInfo struct {
  1689. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1690. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1691. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1692. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  1693. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  1694. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  1695. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1696. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  1697. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1698. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1699. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1700. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1701. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1702. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1703. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1704. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1705. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  1706. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1707. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1708. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  1709. Drug Drug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
  1710. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1711. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1712. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1713. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  1714. }
  1715. func (HisDoctorAdviceInfo) TableName() string {
  1716. return "his_doctor_advice_info"
  1717. }
  1718. type HisPrescriptionProject struct {
  1719. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1720. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1721. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1722. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1723. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1724. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1725. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1726. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1727. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1728. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1729. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1730. Count string `gorm:"column:count" json:"count" form:"count"`
  1731. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1732. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  1733. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1734. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1735. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1736. Day string `gorm:"column:day" json:"day" form:"day"`
  1737. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1738. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  1739. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1740. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1741. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1742. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1743. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1744. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1745. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1746. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1747. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1748. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1749. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1750. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1751. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1752. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  1753. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  1754. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  1755. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1756. }
  1757. func (HisPrescriptionProject) TableName() string {
  1758. return "his_prescription_project"
  1759. }
  1760. type HisOrderInfo struct {
  1761. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1762. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  1763. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  1764. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  1765. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  1766. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  1767. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  1768. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1769. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  1770. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1771. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1772. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  1773. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  1774. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1775. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1776. SelfpayProp float64 `gorm:"column:selfpay_prop" json:"selfpay_prop" form:"selfpay_prop"`
  1777. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1778. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1779. OverlmtAmt float64 `gorm:"column:overlmt_amt" json:"overlmt_amt" form:"overlmt_amt"`
  1780. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  1781. InscpScpAmt float64 `json:"inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
  1782. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1783. HisDoctorAdviceInfo HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  1784. }
  1785. func (HisOrderInfo) TableName() string {
  1786. return "his_order_info"
  1787. }
  1788. func GetHisOrderDetailByNumber(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
  1789. err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1790. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  1791. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1792. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  1793. }).Find(&order).Error
  1794. return
  1795. }
  1796. //func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1797. // db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1798. // return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  1799. // })
  1800. // err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  1801. // return
  1802. //}
  1803. func GetHisOrderInfoByNumberOne(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1804. db := readDb.Model(&models.HisOrderInfoTwo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1805. return db.Preload("Drug", "status = 1").Where("status = 1")
  1806. })
  1807. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  1808. return
  1809. }
  1810. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1811. db := readDb.Model(&models.HisOrderInfoTwo{})
  1812. db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  1813. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1814. return db.Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  1815. })
  1816. err = db.Where("his_order_info.order_number = ? AND his_order_info.status = 1 AND his_order_info.project_id > 0 ", order_number).Find(&order).Error
  1817. return
  1818. }
  1819. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1820. db := readDb.Model(&models.HisOrderInfoTwo{})
  1821. db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  1822. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1823. return db.Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  1824. })
  1825. err = db.Where("his_order_info.order_number = ? AND his_order_info.status = 1 AND his_order_info.project_id > 0", order_number).Find(&order).Error
  1826. return
  1827. }
  1828. type MedicalInsuranceCostCompare struct {
  1829. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1830. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1831. EndTime int64 `gorm:"column:end_time" json:"end_time" form:"end_time"`
  1832. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1833. CheckType int64 `gorm:"column:check_type" json:"check_type" form:"check_type"`
  1834. Num int64 `gorm:"column:num" json:"num" form:"num"`
  1835. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1836. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1837. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1838. CostTotal float64 `gorm:"column:cost_total" json:"cost_total" form:"cost_total"`
  1839. FuncTotal float64 `gorm:"column:func_total" json:"func_total" form:"func_total"`
  1840. PsnPay float64 `gorm:"column:psn_pay" json:"psn_pay" form:"psn_pay"`
  1841. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1842. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1843. ClrType string `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
  1844. }
  1845. func (MedicalInsuranceCostCompare) TableName() string {
  1846. return "medical_insurance_cost_compare"
  1847. }
  1848. func GetMedicalInsuranceCostCompareList(orgID, page, limit int64, keywords string, insutype string, start_time int64, end_time int64) (list []*MedicalInsuranceCostCompare, total int, err error) {
  1849. offset := (page - 1) * limit
  1850. db := readDb.Model(&MedicalInsuranceCostCompare{}).Where("medical_insurance_cost_compare.user_org_id = ?", orgID)
  1851. if len(keywords) == 0 {
  1852. db = db.Where("status=1")
  1853. if len(insutype) != 0 {
  1854. db = db.Where("insutype = ?", insutype)
  1855. }
  1856. if start_time != 0 {
  1857. db = db.Where("ctime >= ? ", start_time)
  1858. }
  1859. if end_time != 0 {
  1860. db = db.Where("ctime <= ? ", end_time)
  1861. }
  1862. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1863. } else {
  1864. keywords = "%" + keywords + "%"
  1865. db = db.Joins("join sgj_users.sgj_user_admin_role role on role.admin_user_id = medical_insurance_cost_compare.creator and role.user_name Like ?", keywords)
  1866. db = db.Where("medical_insurance_cost_compare.status=1 ")
  1867. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1868. }
  1869. return
  1870. }
  1871. type TempPatients struct {
  1872. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1873. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1874. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  1875. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  1876. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  1877. Name string `gorm:"column:name" json:"name" form:"name"`
  1878. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1879. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  1880. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  1881. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  1882. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1883. GdybPsnNcdsRecord GdybPsnNcdsRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"record"`
  1884. }
  1885. func (TempPatients) TableName() string {
  1886. return "xt_patients"
  1887. }
  1888. type GdybPsnNcdsRecord struct {
  1889. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1890. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1891. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1892. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1893. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1894. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1895. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1896. IsCancel int64 `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
  1897. TrtDclaDetlSn string `gorm:"column:trt_dcla_detl_sn" json:"trt_dcla_detl_sn" form:"trt_dcla_detl_sn"`
  1898. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1899. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1900. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1901. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1902. OrgName string `gorm:"column:org_name" json:"org_name" form:"org_name"`
  1903. }
  1904. func (GdybPsnNcdsRecord) TableName() string {
  1905. return "gdyb_psn_ncds_record"
  1906. }
  1907. func GetGdybPsnNcdsRecordList(orgID, page, limit int64, keywords string, is_cancel int64) (list []*TempPatients, total int64, err error) {
  1908. offset := (page - 1) * limit
  1909. db := readDb.Model(&TempPatients{})
  1910. db = db.Preload("GdybPsnNcdsRecord", func(db *gorm.DB) *gorm.DB {
  1911. return db.Model(&GdybPsnNcdsRecord{}).Where("user_org_id = ?", orgID).Order("id asc")
  1912. })
  1913. fmt.Println(is_cancel)
  1914. if len(keywords) == 0 {
  1915. if is_cancel == 1 {
  1916. db = db.Joins("JOIN gdyb_psn_ncds_record On gdyb_psn_ncds_record.patient_id = xt_patients.id AND gdyb_psn_ncds_record.is_cancel = ?", is_cancel)
  1917. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1918. } else if is_cancel == 0 {
  1919. db = db.Preload("GdybPsnNcdsRecord", "user_org_id = ?", orgID)
  1920. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1921. } else if is_cancel == 2 {
  1922. db = db.Joins("LEFT JOIN gdyb_psn_ncds_record On gdyb_psn_ncds_record.patient_id = xt_patients.id AND (gdyb_psn_ncds_record.is_cancel <> 1 OR gdyb_psn_ncds_record.is_cancel is null)")
  1923. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1924. }
  1925. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1926. } else {
  1927. keywords = "%" + keywords + "%"
  1928. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1 AND xt_patients.name LIKE ?", orgID, keywords)
  1929. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1930. }
  1931. return
  1932. }
  1933. type CustomAccountFormData struct {
  1934. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1935. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1936. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1937. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1938. MdtrtiId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  1939. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1940. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  1941. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1942. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1943. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1944. CashPay float64 `gorm:"column:cash_pay" json:"cash_pay" form:"cash_pay"`
  1945. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  1946. Sumamt float64 `gorm:"column:sumamt" json:"sumamt" form:"sumamt"`
  1947. Iinfo string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
  1948. DiagnosisId string `gorm:"column:diagnosis_id" json:"diagnosis_id" form:"diagnosis_id"`
  1949. DialysisCount int64 `gorm:"-"`
  1950. PatientId int64 `gorm:"column:patient_id" json:"dialysis_count" form:"dialysis_count"`
  1951. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1952. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1953. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1954. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1955. MayPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1956. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1957. SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
  1958. SettleEndTime int64 `gorm:"column:settle_end_time" json:"settle_end_time" form:"settle_end_time"`
  1959. }
  1960. func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (cus []*CustomAccountFormData, err error) {
  1961. if clr_type == "9903" {
  1962. err = readDb.Raw("select o.setl_detail as setl_detail, o.maf_pay as maf_pay, o.hifmi_pay as hifmi_pay, o.hifob_pay as hifob_pay, o.cvlserv_pay as cvlserv_pay, o.hifes_pay as hifes_pay, o.patient_id as patient_id, p.diagnosis as diagnosis_id, p.iinfo as iinfo, o.medfee_sumamt as medfee_sumamt ,o.psn_name as psn_name ,p.id_card_no as id_card_no ,o.psn_no as psn_no, o.mdtrt_id as mdtrt_id, o.settle_accounts_date as settle_accounts_date,o.act_pay_dedc as act_pay_dedc,O.fund_pay_sumamt as fund_pay_sumamt,o.psn_cash_pay as psn_cash_pay ,o.acct_pay as acct_pay,o.psn_cash_pay as cash_pay,o.medfee_sumamt as sumamt,o.hifp_pay as hifp_pay, o.settle_start_time as settle_start_time, o.settle_end_time as settle_end_time from his_order o Join his_patient p On o.patient_id = p.patient_id AND o.settle_accounts_date = p.record_date where o.user_org_id = ? AND o.status = 1 AND o.order_status = 2 AND o.settle_accounts_date >= ? AND o.settle_accounts_date <= ? AND o.insutype = ? AND o.clr_type = ? Group by o.id", org_id, start_time, end_time, insutype, clr_type).Scan(&cus).Error
  1963. } else {
  1964. err = readDb.Raw("select o.setl_detail as setl_detail, o.maf_pay as maf_pay, o.hifmi_pay as hifmi_pay, o.hifob_pay as hifob_pay, o.cvlserv_pay as cvlserv_pay, o.hifes_pay as hifes_pay, o.patient_id as patient_id, p.diagnosis as diagnosis_id, p.iinfo as iinfo, o.medfee_sumamt as medfee_sumamt ,o.psn_name as psn_name ,p.id_card_no as id_card_no ,o.psn_no as psn_no, o.mdtrt_id as mdtrt_id, o.settle_accounts_date as settle_accounts_date,o.act_pay_dedc as act_pay_dedc,O.fund_pay_sumamt as fund_pay_sumamt,o.psn_cash_pay as psn_cash_pay ,o.acct_pay as acct_pay,o.psn_cash_pay as cash_pay,o.medfee_sumamt as sumamt,o.hifp_pay as hifp_pay,o.settle_start_time as settle_start_time, o.settle_end_time as settle_end_time from his_order o Join his_patient p On o.patient_id = p.patient_id AND o.settle_accounts_date = p.record_date where o.user_org_id = ? AND o.status = 1 AND o.order_status = 2 AND o.settle_accounts_date >= ? AND o.settle_accounts_date <= ? AND o.insutype = ? AND o.clr_type <> 9903 Group by o.id", org_id, start_time, end_time, insutype).Scan(&cus).Error
  1965. }
  1966. for _, item := range cus {
  1967. var total int64
  1968. if item.SettleStartTime == 0 && item.SettleEndTime == 0 {
  1969. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND dialysis_date <= ? AND dialysis_date >= ?", item.PatientId, item.SettleAccountsDate, item.SettleAccountsDate).Count(&total)
  1970. } else {
  1971. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND dialysis_date <= ? AND dialysis_date >= ?", item.PatientId, item.SettleEndTime, item.SettleStartTime).Count(&total)
  1972. }
  1973. fmt.Println(total)
  1974. item.DialysisCount = total
  1975. fmt.Println(item.DialysisCount)
  1976. }
  1977. return
  1978. }
  1979. func GetNewHisPatientInfo(his_patient_id int64) (info models.HisPatient, err error) {
  1980. err = readDb.Model(&models.HisPatient{}).Where("id = ? AND status = 1 ", his_patient_id).First(&info).Error
  1981. return
  1982. }
  1983. func GetLastNewHisPatientInfo(patient_id int64, recordDateTime int64) (info models.HisPatient, err error) {
  1984. err = readDb.Model(&models.HisPatient{}).Where("patient_id = ? AND status = 1 and record_date < ?", patient_id, recordDateTime).First(&info).Error
  1985. return
  1986. }
  1987. func GetNewHisOrder(user_org_id int64, mdtrt_id string, patient_id int64) (order models.HisOrder, err error) {
  1988. err = readDb.Model(&models.HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? ", user_org_id, patient_id, mdtrt_id).
  1989. Last(&order).Error
  1990. return
  1991. }
  1992. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1993. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? AND settle_accounts_date = ? ", user_org_id, patient_id, mdtrt_id, record_time).
  1994. Order("ctime desc").
  1995. Find(&order).Error
  1996. return
  1997. }
  1998. type NewCustomPatients struct {
  1999. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2000. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2001. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2002. Number string `gorm:"column:number" json:"number" form:"number"`
  2003. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2004. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2005. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,Number" json:"order"`
  2006. }
  2007. func (NewCustomPatients) TableName() string {
  2008. return "his_patients"
  2009. }
  2010. type NewSZCustomPatients struct {
  2011. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2012. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2013. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2014. Number string `gorm:"column:number" json:"number" form:"number"`
  2015. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2016. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  2017. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,MzNumber" json:"order"`
  2018. }
  2019. func (NewSZCustomPatients) TableName() string {
  2020. return "his_patients"
  2021. }
  2022. //
  2023. //func GetNewAllChargeHisPatientList(org_id int64, record_date int64) (patients []*NewSZCustomPatients, err error) {
  2024. // var tempPatients []*NewSZCustomPatients
  2025. // db := readDb.Model(&NewSZCustomPatients{}).Where("his_patients.user_org_id = ? AND his_patients.status = 1", org_id)
  2026. // db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  2027. // return tempPatients, err
  2028. //}
  2029. type NewTempPatients struct {
  2030. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2031. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2032. Name string `gorm:"column:name" json:"name" form:"name"`
  2033. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2034. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  2035. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  2036. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  2037. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  2038. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  2039. HisPatient []*HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  2040. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  2041. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  2042. }
  2043. func (NewTempPatients) TableName() string {
  2044. return "xt_patients"
  2045. }
  2046. //"VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date
  2047. func GetNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*NewTempPatients, err error) {
  2048. db := readDb.Model(&NewTempPatients{})
  2049. if sch_type > 0 {
  2050. db = db.Joins("join xt_schedule as sch on sch.patient_id = xt_patients.id and sch.schedule_date = ? and sch.schedule_type = ? and sch.status = 1", record_date, sch_type)
  2051. }
  2052. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2053. db = db.Preload("Schedule", "status = 1")
  2054. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2055. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  2056. })
  2057. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  2058. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Group("xt_patients.id").Error
  2059. for _, item := range patients {
  2060. for _, sumItem := range item.HisPatient {
  2061. if len(sumItem.VMHisOrders) > 0 {
  2062. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2063. }
  2064. }
  2065. }
  2066. return
  2067. }
  2068. func GetNewAllChargeHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*NewTempPatients, err error) {
  2069. db := readDb.Model(&NewTempPatients{})
  2070. fmt.Println("sch_type")
  2071. fmt.Println(sch_type)
  2072. if sch_type > 0 {
  2073. db = db.Joins("join xt_schedule as sch on sch.patient_id = xt_patients.id and sch.schedule_date = ? and sch.schedule_type = ? and sch.status = 1", record_date, sch_type)
  2074. }
  2075. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2076. db = db.Preload("Schedule", "status = 1")
  2077. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2078. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ? ", org_id, record_date)
  2079. })
  2080. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status = 2", org_id, record_date)
  2081. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Group("xt_patients.id").Error
  2082. for _, item := range patients {
  2083. for _, sumItem := range item.HisPatient {
  2084. if len(sumItem.VMHisOrders) > 0 {
  2085. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2086. }
  2087. }
  2088. }
  2089. return
  2090. }
  2091. func GetPrescriptionById(id int64, org_id int64) (prescription models.HisPrescription, err error) {
  2092. err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND user_org_id = ? AND status = 1", id, org_id).First(&prescription).Error
  2093. return
  2094. }
  2095. func GetPrescriptionByIdTwo(id int64) (prescription models.HisPrescription, err error) {
  2096. err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND status = 1", id).First(&prescription).Error
  2097. return
  2098. }
  2099. type CustomInComeStatistics struct {
  2100. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  2101. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  2102. SettleAccountsDate string `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  2103. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  2104. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  2105. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  2106. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  2107. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  2108. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  2109. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  2110. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  2111. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  2112. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  2113. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  2114. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  2115. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  2116. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  2117. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  2118. }
  2119. func (CustomInComeStatistics) TableName() string {
  2120. return "his_order"
  2121. }
  2122. func GetDayIncomeStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (order []*CustomInComeStatistics, total int64, err error) {
  2123. offset := (page - 1) * limit
  2124. if len(keywords) != 0 {
  2125. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  2126. } else {
  2127. if start_time != 0 && end_time != 0 {
  2128. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 AND settle_accounts_date >= ? AND settle_accounts_date <= ?", org_id, start_time, end_time).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  2129. } else {
  2130. err = readDb.Model(&CustomInComeStatistics{}).Select("sum(medfee_sumamt) as medfee_sumamt,sum(`fund_pay_sumamt`) as fund_pay_sumamt, sum(`hifob_pay`) as hifob_pay, sum(`hifmi_pay`) as hifmi_pay , sum(`hifes_pay`) as hifes_pay, sum(`maf_pay`) as maf_pay,sum(`cvlserv_pay`) as cvlserv_pay, sum(`discount_price`) as discount_price, sum(`preferential_price`) as preferential_price,sum(`acct_pay`) as acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Group("settle_accounts_date").Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&order).Error
  2131. }
  2132. }
  2133. return
  2134. }
  2135. func GetDayIncomeDetailStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (cis []*CustomInComeStatistics, total int64, err error) {
  2136. offset := (page - 1) * limit
  2137. if len(keywords) != 0 {
  2138. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  2139. } else {
  2140. if start_time != 0 && end_time != 0 {
  2141. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2 AND settle_accounts_date >= ? AND settle_accounts_date <= ? ", org_id, start_time, end_time).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  2142. } else {
  2143. err = readDb.Model(&CustomInComeStatistics{}).Select("psn_name,setl_time,medfee_sumamt,fund_pay_sumamt, hifob_pay, hifmi_pay , hifes_pay, maf_pay, cvlserv_pay, discount_price,preferential_price,acct_pay,FROM_UNIXTIME(settle_accounts_date,'%Y-%m-%d') as settle_accounts_date").Where("user_org_id = ? AND status = 1 AND order_status = 2", org_id).Count(&total).Offset(offset).Limit(limit).Order("settle_accounts_date").Find(&cis).Error
  2144. }
  2145. }
  2146. return
  2147. }
  2148. //func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  2149. // err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).Find(&info).Error
  2150. // return
  2151. //}
  2152. func CreateHisPrescriptionTemplate(template *models.HisPrescriptionTemplate) (err error) {
  2153. err = writeDb.Create(&template).Error
  2154. return
  2155. }
  2156. func CreateHisPrescriptionAdviceTemplate(s *models.HisPrescriptionAdviceTemplate) (err error) {
  2157. err = writeDb.Save(&s).Error
  2158. return
  2159. }
  2160. func CreateHisPrescriptionInfoTemplate(s *models.HisPrescriptionInfoTemplate) (err error) {
  2161. err = writeDb.Save(&s).Error
  2162. return
  2163. }
  2164. func CreateHisPrescriptionProjectTemplate(project *models.HisPrescriptionProjectTemplate) (err error) {
  2165. err = writeDb.Save(&project).Error
  2166. return
  2167. }
  2168. func GetPatientSch(patient_id int64, sch_date int64, org_id int64) (sch models.Schedule, err error) {
  2169. err = readDb.Model(&models.Schedule{}).Where("user_org_id = ? AND patient_id = ? AND schedule_date = ? AND status = 1", org_id, patient_id, sch_date).First(&sch).Error
  2170. return
  2171. }
  2172. func GetHisPrescriptionBySchMode(mode_id int64, patient_id int64, org_id int64) (prescription models.HisPrescriptionTemplate, err error) {
  2173. err = readDb.Model(&models.HisPrescriptionTemplate{}).Where("user_org_id = ? AND status = 1 AND mode = ? AND patient_id = ?", org_id, mode_id, patient_id).Last(&prescription).Error
  2174. return
  2175. }
  2176. func GetHisPrescriptionTemplate(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplate, err error) {
  2177. err = readDb.Model(&models.HisPrescriptionInfoTemplate{}).
  2178. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  2179. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2180. }).
  2181. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  2182. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  2183. }).
  2184. Where("status = 1 AND p_template_id = ? ", template_id).
  2185. Find(&prescription).Error
  2186. return
  2187. }
  2188. // 组
  2189. func GetHisPrescriptionTemplateL(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplateL, err error) {
  2190. err = readDb.Model(&models.HisPrescriptionInfoTemplateL{}).
  2191. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  2192. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2193. }).
  2194. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  2195. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  2196. }).
  2197. Where("status = 1 AND p_template_id = ? ", template_id).
  2198. Find(&prescription).Error
  2199. return
  2200. }
  2201. func FindHisConsumablesByID(orgID int64, patient_id int64, recordDate int64, good_id int64) (consumables models.DialysisBeforePrepare, err error) {
  2202. err = readDb.Model(&models.DialysisBeforePrepare{}).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND good_id = ?", orgID, patient_id, recordDate, good_id).First(&consumables).Error
  2203. return
  2204. }
  2205. func UpdateConsumables(consumables *models.DialysisBeforePrepare) (err error) {
  2206. err = writeDb.Save(&consumables).Error
  2207. return
  2208. }
  2209. func GetHisPrescriptionProjectsByID(id int64) (projects []*models.HisPrescriptionProject, err error) {
  2210. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("prescription_id = ? AND status = 1", id).Find(&projects).Error
  2211. return
  2212. }
  2213. func GetHisPrescriptionProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  2214. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND team_id = 0", user_org_id, patient_id, record_time).Find(&projects).Error
  2215. return
  2216. }
  2217. func GetHisPrescriptionTeamProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  2218. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("XtHisProjectTeam", "status = 1 AND user_org_id = ?", user_org_id).Preload("HisProject", "status = 1 AND user_org_id = ?", user_org_id).Preload("GoodInfo", "status = 1 AND org_id = ?", user_org_id).Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1 AND team_id > 0", user_org_id, patient_id, record_time).Find(&projects).Error
  2219. return
  2220. }
  2221. func GetHisPrescriptionProjectByID(id int64) (projects models.HisPrescriptionProject, err error) {
  2222. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  2223. return
  2224. }
  2225. func GetHisPrescriptionAdviceByID(id int64) (advices []*models.HisDoctorAdviceInfo, err error) {
  2226. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
  2227. return
  2228. }
  2229. func UpdateGoodInfo(good_info *models.GoodInfo) (err error) {
  2230. err = writeDb.Save(&good_info).Error
  2231. return
  2232. }
  2233. func GetUnChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  2234. err = readDb.Model(&models.HisPrescription{}).
  2235. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2236. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2237. }).
  2238. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2239. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2240. }).
  2241. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2242. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2243. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2244. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2245. }).
  2246. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? AND order_status <> 2 ", org_id, start_date, end_date, patient_id, p_type).
  2247. Find(&prescription).Error
  2248. return
  2249. }
  2250. func GetChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  2251. err = readDb.Model(&models.HisPrescription{}).
  2252. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2253. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2254. }).
  2255. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2256. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2257. }).
  2258. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2259. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2260. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2261. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2262. }).
  2263. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND p_type = ? AND order_status = 2 ", org_id, start_date, end_date, patient_id, p_type).
  2264. Find(&prescription).Error
  2265. return
  2266. }
  2267. func GetChargeHisPrescriptionSeven(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  2268. err = readDb.Model(&models.HisPrescription{}).
  2269. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2270. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2271. }).
  2272. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2273. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  2274. }).
  2275. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2276. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  2277. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2278. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2279. }).
  2280. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND order_status = 2 AND batch_number = ? AND p_type = ?", org_id, patient_id, order_number, p_type).
  2281. Find(&prescription).Error
  2282. return
  2283. }
  2284. // 已收费
  2285. func GetChargeMonthHisPrescriptionFive(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  2286. err = readDb.Model(&models.HisPrescription{}).
  2287. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2288. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2289. }).
  2290. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2291. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2292. }).
  2293. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2294. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2295. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2296. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2297. }).
  2298. Where("user_org_id = ? AND status = 1 AND batch_number = ? AND patient_id = ? AND order_status = 2 AND p_type = ?", org_id, order_number, patient_id, p_type).
  2299. Find(&prescription).Error
  2300. return
  2301. }
  2302. func UpdataHisPateint(his *models.HisPatient) {
  2303. writeDb.Save(&his)
  2304. }
  2305. func UpdataHisPateintTX(his *models.HisPatient, tx *gorm.DB) {
  2306. tx.Save(&his)
  2307. }
  2308. func SaveHisOrder(his *models.HisOrder) (err error) {
  2309. err = writeDb.Save(&his).Error
  2310. return
  2311. }
  2312. func UpdataHisPateintTwo(his *models.VMHisPatient) {
  2313. writeDb.Save(&his)
  2314. }
  2315. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  2316. err = readDb.Model(&models.HisPrescription{}).
  2317. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2318. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2319. }).
  2320. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2321. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2322. }).
  2323. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2324. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2325. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2326. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2327. }).
  2328. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2329. Find(&prescription).Error
  2330. return
  2331. }
  2332. func GetPrescriptionByIdsTX(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  2333. err = tx.Model(&models.HisPrescription{}).
  2334. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  2335. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2336. }).
  2337. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  2338. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2339. }).
  2340. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  2341. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2342. }).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
  2343. return tx.Where("status = 1 AND user_org_id = ?", org_id)
  2344. }).
  2345. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2346. Find(&prescription).Error
  2347. return
  2348. }
  2349. func GetPrescriptionByIdsTxOne(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  2350. err = tx.Model(&models.HisPrescription{}).
  2351. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  2352. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2353. }).
  2354. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  2355. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  2356. }).
  2357. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  2358. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1")
  2359. }).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
  2360. return tx.Where("status = 1 AND user_org_id = ?", org_id)
  2361. }).
  2362. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2363. Find(&prescription).Error
  2364. return
  2365. }
  2366. func GetNewAllUnChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  2367. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2368. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2369. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ? AND order_status <> 2", org_id, record_date)
  2370. })
  2371. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  2372. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
  2373. for _, item := range patients {
  2374. for _, sumItem := range item.HisPatient {
  2375. if len(sumItem.VMHisOrders) > 0 {
  2376. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2377. }
  2378. }
  2379. }
  2380. return
  2381. }
  2382. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  2383. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND settle_accounts_date = ? AND order_status = 2 AND mdtrt_id = ?", org_id, patient_id, record_time, number).Count(&count).Error
  2384. return
  2385. }
  2386. func GetNewHisOrderList(org_id int64) (order []*models.NewHisOrder, err error) {
  2387. err = readDb.Model(&models.NewHisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2", org_id).Preload("HisPatient", "status = 1").Find(&order).Error
  2388. var numbers []string
  2389. for _, item := range order {
  2390. numbers = append(numbers, item.Number)
  2391. }
  2392. return
  2393. }
  2394. func GetNewHisOrderInfoList(order_numbers []string) (order []*models.VMHisOrderInfo, err error) {
  2395. err = readDb.Model(&models.VMHisOrderInfo{}).Where("status = 1 AND order_number in (?)", order_numbers).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2396. return db.Where("status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1")
  2397. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2398. return db.Where("status = 1 ").Preload("Drug", "status =1")
  2399. }).Find(&order).Error
  2400. return
  2401. }
  2402. func FindAllHisDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, drug_id int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2403. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND advice_date > ? AND advice_date <= ? AND drug_id = ? ", orgId, patient_id, end, now, drug_id).Find(&advice).Error
  2404. return
  2405. }
  2406. func FindAllHisProjectByTime(now int64, end int64, patient_id int64, orgId int64, project_id int64) (project []*models.HisPrescriptionProject, err error) {
  2407. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND record_date > ? AND record_date <= ? AND project_id = ? ", orgId, patient_id, end, now, project_id).Find(&project).Error
  2408. return
  2409. }
  2410. func GetProjectByTeamId(user_org_id int64, team_id int64, patient_id int64, record_time int64) (label models.HisLabelPrintInfo, err error) {
  2411. err = readDb.Model(&models.HisLabelPrintInfo{}).Where("user_org_id = ? AND item_id = ? AND patient_id = ? AND record_date = ? AND status = 1", user_org_id, team_id, patient_id, record_time).First(&label).Error
  2412. return
  2413. }
  2414. func GetProjectById(user_org_id int64, p_project_id int64, record_time int64, patient_id int64) (label models.HisLabelPrintInfo, err error) {
  2415. err = readDb.Model(&models.HisLabelPrintInfo{}).Where("user_org_id = ? AND p_project_id = ? AND patient_id = ? AND record_date = ? AND status = 1", user_org_id, p_project_id, patient_id, record_time).First(&label).Error
  2416. return
  2417. }
  2418. func DeletePrintInfo(id int64) {
  2419. writeDb.Model(&models.HisLabelPrintInfo{}).Where("p_project_id = ?", id).Updates(map[string]interface{}{"status": 0})
  2420. }
  2421. func CreateNewHisLabelRecord(label *models.HisLabelPrintInfo, tx *gorm.DB) (err error) {
  2422. if err = tx.Save(&label).Error; err != nil {
  2423. tx.Rollback()
  2424. return
  2425. }
  2426. return
  2427. }
  2428. func CreateHisLabelRecord(label *models.HisLabelPrintInfo) error {
  2429. err := writeDb.Save(&label).Error
  2430. return err
  2431. }
  2432. func CreateHisLabelRecordTwo(label *models.HisLabelPrintInfo) (err error) {
  2433. err = writeDb.Save(&label).Error
  2434. return
  2435. }
  2436. func DeletePsnNCDSRecordById(id int64) (err error) {
  2437. err = writeDb.Model(&models.GdybPsnNcdsRecord{}).Where("id = ?", id).Updates(map[string]interface{}{"user_org_id": 1110000}).Error
  2438. return
  2439. }
  2440. func GetBaiLinOrderData() (order []*models.NewCustomHisOrder) {
  2441. readDb.Model(&models.NewCustomHisOrder{}).Preload("Patients", "status = 1").Preload("NewCustomHisOrderInfo", func(db *gorm.DB) *gorm.DB {
  2442. return db.Where("status = 1 AND project_id > 0").Preload("NewCustomHisPrescriptionProject", "(status = 1 and project_id = 1027 AND type = 2) OR (status = 1 AND project_id = 2036 AND type = 3)")
  2443. }).Where("user_org_id = 10138 AND settle_accounts_date >= 1638288000 AND settle_accounts_date <= 1640880000 AND order_status = 2 AND status = 1 AND (medfee_sumamt = 50 OR medfee_sumamt = 40)").Find(&order)
  2444. return
  2445. }
  2446. func GetHisDoctorAdviceInfo(id int64) (models.HisDoctorAdviceInfo, error) {
  2447. info := models.HisDoctorAdviceInfo{}
  2448. err := readDb.Model(&info).Where("id = ? and status = 1", id).Preload("Drug", "status = 1").Find(&info).Error
  2449. return info, err
  2450. }
  2451. func UpdateBatchHisPrescriptionMedType(ids []string, med_type string, start_time int64, end_time int64, user_org_id int64, old_med_type string) (err error) {
  2452. tx := writeDb.Begin()
  2453. if err = tx.Model(&models.HisPrescription{}).Where("id in (?) AND status = 1 AND user_org_id=? AND med_type = ? AND record_date >= ? AND record_date <= ?", ids, user_org_id, old_med_type, start_time, end_time).Updates(map[string]interface{}{"med_type": med_type}).Error; err != nil {
  2454. tx.Rollback()
  2455. return
  2456. }
  2457. tx.Commit()
  2458. return
  2459. }
  2460. func GetWarehoseInfoByDrugId(drug_id int64, org_id int64) (info OtherDrugWarehouseInfo, err error) {
  2461. err = readDb.Model(&OtherDrugWarehouseInfo{}).Where("(drug_id = ? AND org_id = ? AND status = 1 and stock_max_number > 0) or (drug_id = ? AND org_id = ? AND status = 1 AND stock_min_number >0)", drug_id, org_id, drug_id, org_id).First(&info).Error
  2462. return
  2463. }
  2464. func GetGoodWarehoseInfoByGoodId(good_id int64, org_id int64) (info models.GoodSotckInfo, err error) {
  2465. err = readDb.Model(&models.GoodSotckInfo{}).Where("stock_count > 0 and status = 1 and good_id = ? and org_id = ?", good_id, org_id).First(&info).Error
  2466. return
  2467. }
  2468. type MonthChargePatients struct {
  2469. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2470. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2471. Name string `gorm:"column:name" json:"name" form:"name"`
  2472. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2473. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2474. Number string `gorm:"column:number" json:"number" form:"number"`
  2475. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  2476. }
  2477. func (MonthChargePatients) TableName() string {
  2478. return "his_patient"
  2479. }
  2480. func GetMonthUnChargeHisPatientList(org_id int64, record_date int64, start_time int64, end_time int64) (patients []*MonthChargePatients, err error) {
  2481. db := readDb.Model(&MonthChargePatients{}).Where("his_patient.user_org_id = ? AND his_patient.status = 1 AND his_patient.record_date = ?", org_id, record_date)
  2482. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, start_time, end_time)
  2483. return
  2484. }
  2485. func UpdataOrderStatusThree(number string, user_org_id int64) (err error) {
  2486. err = writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"order_status": 5, "mtime": time.Now().Unix()}).Error
  2487. err = writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND batch_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"prescription_status": 5, "mtime": time.Now().Unix()}).Error
  2488. return
  2489. }
  2490. func UpDateOrderTwo(order *models.HisOrder, tx *gorm.DB) (err error) {
  2491. err = tx.Save(&order).Error
  2492. return
  2493. }
  2494. type HisOrderInfoTen struct {
  2495. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2496. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  2497. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  2498. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  2499. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  2500. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  2501. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  2502. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2503. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  2504. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2505. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  2506. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  2507. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  2508. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2509. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2510. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  2511. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  2512. OverlmtAmt float64 `gorm:"column:overlmt_amt"`
  2513. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  2514. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2515. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  2516. HisDoctorAdviceInfo models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  2517. }
  2518. func (HisOrderInfoTen) TableName() string {
  2519. return "his_order_info"
  2520. }
  2521. func GetHisOrderDetailByNumberTen(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
  2522. err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2523. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  2524. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2525. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2526. }).Find(&order).Error
  2527. return
  2528. }
  2529. func GetHisOrderDetailByNumberEleven(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
  2530. err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2531. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  2532. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2533. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2534. }).Find(&order).Error
  2535. return
  2536. }
  2537. func GetHisOrderByIDTen(order_id int64) (order models.HisOrder, err error) {
  2538. err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
  2539. return
  2540. }
  2541. func GetHisPrescriptonProjectById(id int64) (models.HisPrescriptionProject, error) {
  2542. project := models.HisPrescriptionProject{}
  2543. err := XTReadDB().Where("id = ? and status = 1", id).Find(&project).Error
  2544. return project, err
  2545. }
  2546. type HisOrderInfoTwo struct {
  2547. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2548. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  2549. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  2550. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  2551. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  2552. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  2553. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  2554. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2555. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  2556. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2557. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  2558. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  2559. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  2560. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2561. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2562. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  2563. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  2564. OverlmtAmt float64 `gorm:"column:overlmt_amt"`
  2565. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  2566. InscpScpAmt float64 `json:"inscp_scp_amt"`
  2567. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  2568. HisDoctorAdviceInfo models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  2569. }
  2570. func (HisOrderInfoTwo) TableName() string {
  2571. return "his_order_info"
  2572. }
  2573. func GetHisOrderDetailByNumberTwo(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
  2574. err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2575. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  2576. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2577. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2578. }).Find(&order).Error
  2579. return
  2580. }
  2581. func GetHisOrderDetailByNumberThree(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
  2582. err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2583. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  2584. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2585. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2586. }).Find(&order).Error
  2587. return
  2588. }
  2589. func GetHisOrderByIDThree(order_id int64) (order models.HisOrder, err error) {
  2590. err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
  2591. return
  2592. }
  2593. func GetDrugSumOutCountByDrugId(drug_id int64, user_org_id int64, storehouse_id int64) (models.XtDrugStockCount, error) {
  2594. drug := models.XtDrugStockCount{}
  2595. err := XTReadDB().Where("drug_id = ? and user_org_id = ? and status = 1 and storehouse_id =?", drug_id, user_org_id, storehouse_id).Find(&drug).Error
  2596. return drug, err
  2597. }
  2598. func GetStockGoodList(good_id int64, org_id int64, storehouse_id int64) (models.XtGoodStockCount, error) {
  2599. stockCount := models.XtGoodStockCount{}
  2600. err = XTReadDB().Where("good_id = ? and user_org_id = ? and status= 1 and storehouse_id = ?", good_id, org_id, storehouse_id).Find(&stockCount).Error
  2601. return stockCount, err
  2602. }
  2603. func GetLastOrderTX(user_org_id int64) (models.HisOrder, error) {
  2604. order := models.HisOrder{}
  2605. err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Last(&order).Error
  2606. return order, err
  2607. }
  2608. func GetPatientPlan(orgid int64) (patient []*models.XtPatients, err error) {
  2609. err = XTReadDB().Where("user_org_id = ? and status= 1", orgid).Find(&patient).Error
  2610. return patient, err
  2611. }
  2612. func UpdatePatienPlan(id int64, trement_plan string) error {
  2613. err := XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status = 1", id).Update(map[string]interface{}{"treatment_plan": trement_plan}).Error
  2614. return err
  2615. }
  2616. func GetDialysisOrderList(orgid int64) (order []*models.XtDialysisOrder, err error) {
  2617. err = XTReadDB().Where("user_org_id = ? and status= 1 and url<>''", orgid).Group("patient_id").Find(&order).Error
  2618. return order, err
  2619. }
  2620. func UpdatePatientDialysisOrder(patient_id int64, url string) error {
  2621. err := XTWriteDB().Model(&models.XtPatients{}).Where("id =? and status=1", patient_id).Updates(map[string]interface{}{"url": url}).Error
  2622. return err
  2623. }
  2624. func GetHisOrderByIDTenOne(order_id string) (order models.HisOrder, err error) {
  2625. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  2626. return
  2627. }
  2628. func GetHisDoctorAdviceInfotwo(id int64) (models.HisDoctorAdviceInfo, error) {
  2629. info := models.HisDoctorAdviceInfo{}
  2630. err := readDb.Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
  2631. return info, err
  2632. }
  2633. func GetHisDoctorAdviceInfothree(org_id int64, record_date int64) (info []*models.HisDoctorAdviceInfo, err error) {
  2634. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and status = 1 and record_date = ?", org_id, record_date).Find(&info).Error
  2635. return
  2636. }
  2637. func GetHisPrescriptionProjectByIDFour(org_id int64, record_date int64) (projects []*models.HisPrescriptionProject, err error) {
  2638. err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? and status = 1 and record_date = ?", org_id, record_date).Find(&projects).Error
  2639. return
  2640. }
  2641. func GetHisPrescriptionProjectByIDThree(id int64) (projects models.HisPrescriptionProject, err error) {
  2642. err = readDb.Model(&models.HisPrescriptionProject{}).Where("id = ? AND status = 1", id).First(&projects).Error
  2643. return
  2644. }
  2645. func GetHisPrescriptionProjectByIDTwoone(id int64) (projects models.HisPrescriptionProject, err error) {
  2646. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Preload("HisProject", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  2647. return
  2648. }
  2649. func GetMonthNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64, start_date int64, end_date int64) (patients []NewTempPatients, err error) {
  2650. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2651. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2652. return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  2653. })
  2654. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1 AND order_status <> 2 AND order_status <> 3 and record_date >= ? and record_date <= ?", org_id, start_date, end_date)
  2655. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
  2656. for _, item := range patients {
  2657. for _, sumItem := range item.HisPatient {
  2658. if len(sumItem.VMHisOrders) > 0 {
  2659. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2660. }
  2661. }
  2662. }
  2663. return
  2664. }
  2665. func GetChargeHisPatientList(org_id int64, record_date int64) (order []*HisOrder, err error) {
  2666. err = readDb.Model(&models.HisOrder{}).Preload("Patients", "status = 1").Where("settle_accounts_date = ? and user_org_id = ? AND status = 1 and order_status = 2", record_date, org_id).Find(&order).Error
  2667. return
  2668. }
  2669. func GetGoodByIdIsStop(good_id int64, org_id int64) (models.GoodInfoSeven, error) {
  2670. goodInfoSeven := models.GoodInfoSeven{}
  2671. err = XTReadDB().Where("org_id = ? and status = 1 and find_in_set('停用',good_status) = 0 and id =?", org_id, good_id).Find(&goodInfoSeven).Error
  2672. return goodInfoSeven, err
  2673. }
  2674. func GetNewGoodByIdIsStop(good_id int64, org_id int64, tx *gorm.DB) (models.GoodInfoSeven, error) {
  2675. goodInfoSeven := models.GoodInfoSeven{}
  2676. err = tx.Where("org_id = ? and status = 1 and id =?", org_id, good_id).Find(&goodInfoSeven).Error
  2677. if err != gorm.ErrRecordNotFound {
  2678. if err != nil {
  2679. tx.Rollback()
  2680. return goodInfoSeven, err
  2681. }
  2682. }
  2683. return goodInfoSeven, err
  2684. }
  2685. func GetNewDrugByIdIsStop(good_id int64, org_id int64, tx *gorm.DB) (models.BaseDrugLibSeven, error) {
  2686. goodInfoSeven := models.BaseDrugLibSeven{}
  2687. err = tx.Where("org_id = ? and status = 1 and id =?", org_id, good_id).Find(&goodInfoSeven).Error
  2688. if err != gorm.ErrRecordNotFound {
  2689. if err != nil {
  2690. tx.Rollback()
  2691. return goodInfoSeven, err
  2692. }
  2693. }
  2694. return goodInfoSeven, err
  2695. }
  2696. func CreateCodeInfo(info models.XtGoodCodeInfo, tx *gorm.DB) error {
  2697. err := tx.Create(&info).Error
  2698. if err != nil {
  2699. tx.Rollback()
  2700. return err
  2701. }
  2702. return err
  2703. }
  2704. func CreateDrugCodeInfo(info models.XtDrugCodeInfo, tx *gorm.DB) error {
  2705. err := tx.Create(&info).Error
  2706. if err != nil {
  2707. tx.Rollback()
  2708. return err
  2709. }
  2710. return err
  2711. }
  2712. func UpdateCodeInfo(info models.XtGoodCodeInfo, tx *gorm.DB) error {
  2713. err := tx.Model(&info).Where("warehouse_info_id = ? and good_code =? and status=1 and user_org_id =?", info.WarehouseInfoId, info.GoodCode, info.UserOrgId).Updates(map[string]interface{}{"status": 0}).Error
  2714. if err != nil {
  2715. tx.Rollback()
  2716. return err
  2717. }
  2718. return err
  2719. }
  2720. func UpdateDrugCodeInfo(info models.XtDrugCodeInfo, tx *gorm.DB) error {
  2721. err := tx.Model(&info).Where("warehouse_info_id = ? and drug_code =? and status=1 and user_org_id =?", info.WarehouseInfoId, info.DrugCode, info.UserOrgId).Updates(map[string]interface{}{"status": 0}).Error
  2722. if err != nil {
  2723. tx.Rollback()
  2724. return err
  2725. }
  2726. return err
  2727. }
  2728. func GetHisPrescriptionByBatchNumber(org_id int64, number string) (prescription []*models.HisPrescription, err error) {
  2729. err = readDb.Model(&models.HisPrescription{}).
  2730. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2731. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2732. }).
  2733. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2734. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2735. }).
  2736. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2737. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  2738. }).
  2739. Where("user_org_id = ? AND status = 1 AND batch_number = ?", org_id, number).
  2740. Find(&prescription).Error
  2741. return
  2742. }
  2743. func GetLastHisOrderThree(org_id int64) (err error, o models.HisOrder) {
  2744. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? and status = 1 and order_status = 2", org_id).First(&o).Error
  2745. return
  2746. }
  2747. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  2748. err = readDb.Model(&models.HisOrder{}).Select("max(convert(fa_piao_number,signed)) as fa_piao_number").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Find(&his).Error
  2749. return
  2750. }
  2751. //func GetZuoBiaoNewAllUnChargeHisPatientList(org_id int64, record_date int64) (patients []*NewTempPatients, err error) {
  2752. // db := readDb.Model(&NewTempPatients{})
  2753. //
  2754. // db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2755. // db = db.Preload("Schedule", "status = 1")
  2756. // db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2757. // return db.Where("status = 1 AND user_org_id = ? AND record_date = ?", org_id, record_date).Preload("VMHisOrders", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  2758. // })
  2759. // db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2 AND order_status <> 3", org_id, record_date)
  2760. // err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND prescription_status <> 3", org_id, record_date).Find(&patients).Error
  2761. //
  2762. // for _, item := range patients {
  2763. // for _, sumItem := range item.HisPatient {
  2764. // if len(sumItem.VMHisOrders) > 0 {
  2765. // sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2766. // }
  2767. // }
  2768. //
  2769. // }
  2770. //
  2771. // return
  2772. //}
  2773. //func GetHisPrescriptionByHisPatientID(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescriptionTen, err error) {
  2774. // err = readDb.Model(&models.HisPrescriptionTen{}).
  2775. // Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = 2 and his_patient_id = 0", org_id, record_date, patient_id).
  2776. // Find(&prescription).Error
  2777. // return
  2778. //}
  2779. func GetHisPrescriptionByHisPatientID(record_date int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  2780. err = readDb.Model(&VMOtherHisPrescriptionInfo{}).Where("patient_id = ? AND user_org_id = ? AND status=1 AND record_date >= ? AND record_date <= ? AND p_type = ?", patient_id, org_id, record_date, record_date, 2).
  2781. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  2782. return db.Where("status = 1 AND user_org_id = ?", org_id).
  2783. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2784. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2785. }).
  2786. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2787. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  2788. }).Where("status = 1 and order_status = 1")
  2789. }).Order("record_date desc").Find(&advice).Error
  2790. return
  2791. }
  2792. func GetBatchHisDoctorAdviceByIDs(ids []int64) (list []*models.HisDoctorAdviceInfo, err error) {
  2793. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("id in (?) and status = 1", ids).Find(&list).Error
  2794. return
  2795. }
  2796. func GetBatchHisProjectByIDs(ids []int64) (list []*models.HisPrescriptionProject, err error) {
  2797. err = readDb.Model(&models.HisPrescriptionProject{}).Where("id in (?) and status = 1", ids).Find(&list).Error
  2798. return
  2799. }
  2800. func UpdatePrescriptionAdvice(drug_id int64, user_org_id int64, price float64, patient_id int64) (models.HisPrescriptionAdviceTemplate, error) {
  2801. adviceTemplate := models.HisPrescriptionAdviceTemplate{}
  2802. err := XTWriteDB().Model(&adviceTemplate).Where("drug_id = ? and user_org_id =? and status =1 and patient_id =?", drug_id, user_org_id, patient_id).Updates(map[string]interface{}{"price": price}).Error
  2803. return adviceTemplate, err
  2804. }
  2805. func UpdateBaseMinPrice(drug_id int64, user_org_id int64, retial_price float64) (models.BaseDrugLib, error) {
  2806. lib := models.BaseDrugLib{}
  2807. err := XTWriteDB().Model(&lib).Where("id = ? and org_id = ?", drug_id, user_org_id).Updates(map[string]interface{}{"min_price": retial_price}).Error
  2808. return lib, err
  2809. }
  2810. func UpdatePrescriptionProject(good_id int64, user_org_id int64, packing_price float64, patient_id int64) (models.HisPrescriptionProjectTemplate, error) {
  2811. projectTemplate := models.HisPrescriptionProjectTemplate{}
  2812. err := XTWriteDB().Model(&projectTemplate).Where("project_id = ? and status=1 and user_org_id =? and patient_id =?", good_id, user_org_id, patient_id).Updates(map[string]interface{}{"price": packing_price}).Error
  2813. return projectTemplate, err
  2814. }
  2815. func UpdateGood(good_id int64, user_org_id int64, packing_price float64) (models.GoodInfo, error) {
  2816. goodInfo := models.GoodInfo{}
  2817. err := XTWriteDB().Model(&goodInfo).Where("id = ? and org_id = ? and status=1", good_id, user_org_id).Updates(map[string]interface{}{"packing_price": packing_price}).Error
  2818. return goodInfo, err
  2819. }
  2820. func GetHistory(id int64, user_org_id int64, tx *gorm.DB) (models.HisDoctorAdviceInfo, error) {
  2821. adviceInfo := models.HisDoctorAdviceInfo{}
  2822. err := tx.Where("id = ? and user_org_id = ? and status=1", id, user_org_id).Find(&adviceInfo).Error
  2823. if err != gorm.ErrRecordNotFound {
  2824. if err != nil {
  2825. tx.Rollback()
  2826. return adviceInfo, err
  2827. }
  2828. }
  2829. return adviceInfo, err
  2830. }
  2831. func GetLastHisDoctorAdviceById(patient_id int64, user_org_id int64, advice_date int64, drug_id int64, tx *gorm.DB) (models.HisDoctorAdviceInfo, error) {
  2832. adviceInfo := models.HisDoctorAdviceInfo{}
  2833. err := tx.Where("patient_id = ? and user_org_id = ? and advice_date = ? and drug_id = ? and status =1", patient_id, user_org_id, advice_date, drug_id).Last(&adviceInfo).Error
  2834. if err != gorm.ErrRecordNotFound {
  2835. if err != nil {
  2836. tx.Rollback()
  2837. return adviceInfo, err
  2838. }
  2839. }
  2840. return adviceInfo, err
  2841. }
  2842. func GetLastHisProjectById(patient_id int64, user_org_id int64, record_date int64, drug_id int64, tx *gorm.DB) (models.HisPrescriptionProject, error) {
  2843. projectInfo := models.HisPrescriptionProject{}
  2844. err := tx.Where("patient_id = ? and user_org_id = ? and record_date = ? and project_id = ? and status =1", patient_id, user_org_id, record_date, drug_id).Last(&projectInfo).Error
  2845. if err != gorm.ErrRecordNotFound {
  2846. if err != nil {
  2847. tx.Rollback()
  2848. return projectInfo, err
  2849. }
  2850. }
  2851. return projectInfo, err
  2852. }
  2853. func GetDrugWarehouseOutInfoByAdviceId(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, tx *gorm.DB) (outInfo []*models.DrugWarehouseOutInfo, err error) {
  2854. err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and drug_id = ? and status=1 and advice_id = 0", patient_id, user_org_id, sys_record_date, drug_id).Find(&outInfo).Error
  2855. if err != gorm.ErrRecordNotFound {
  2856. if err != nil {
  2857. tx.Rollback()
  2858. return outInfo, err
  2859. }
  2860. }
  2861. return outInfo, err
  2862. }
  2863. func GetGoodWarehouseOutInfoByAdviceId(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, tx *gorm.DB) (outInfo []*models.WarehouseOutInfo, err error) {
  2864. err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and good_id = ? and status=1 and project_id = 0", patient_id, user_org_id, sys_record_date, drug_id).Find(&outInfo).Error
  2865. if err != gorm.ErrRecordNotFound {
  2866. if err != nil {
  2867. tx.Rollback()
  2868. return outInfo, err
  2869. }
  2870. }
  2871. return outInfo, err
  2872. }
  2873. func GetDrugWarehouseOutInfoByAdviceIdTwo(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, advice_id int64, tx *gorm.DB) (models.DrugWarehouseOutInfo, error) {
  2874. outInfo := models.DrugWarehouseOutInfo{}
  2875. err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and drug_id = ? and status=1 and advice_id = ?", patient_id, user_org_id, sys_record_date, drug_id, advice_id).Order("id desc").First(&outInfo).Error
  2876. if err != gorm.ErrRecordNotFound {
  2877. if err != nil {
  2878. tx.Rollback()
  2879. return outInfo, err
  2880. }
  2881. }
  2882. return outInfo, err
  2883. }
  2884. func GetDrugAutoOutInfoByAdviceIdTwo(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, advice_id int64, tx *gorm.DB) (models.DrugAutomaticReduceDetail, error) {
  2885. outInfo := models.DrugAutomaticReduceDetail{}
  2886. err = tx.Where("patient_id = ? and org_id =? and record_time = ? and drug_id = ? and status=1 and advice_id = ?", patient_id, user_org_id, sys_record_date, drug_id, advice_id).Order("id desc").First(&outInfo).Error
  2887. if err != gorm.ErrRecordNotFound {
  2888. if err != nil {
  2889. tx.Rollback()
  2890. return outInfo, err
  2891. }
  2892. }
  2893. return outInfo, err
  2894. }
  2895. func GetDrugAutoDetail(patient_id int64, org_id int64, record_time int64, drug_id int64, tx *gorm.DB) (automaticReduceDetail []*models.DrugAutomaticReduceDetail, err error) {
  2896. err = tx.Where("patient_id = ? and org_id = ? and record_time =? and drug_id = ? and status =1 and advice_id = 0", patient_id, org_id, record_time, drug_id).Find(&automaticReduceDetail).Error
  2897. if err != gorm.ErrRecordNotFound {
  2898. if err != nil {
  2899. tx.Rollback()
  2900. return automaticReduceDetail, err
  2901. }
  2902. }
  2903. return automaticReduceDetail, err
  2904. }
  2905. func GetGoodAutoDetail(patient_id int64, org_id int64, record_time int64, good_id int64, tx *gorm.DB) (automaticReduceDetail []*models.AutomaticReduceDetail, err error) {
  2906. err = tx.Where("patient_id = ? and org_id = ? and record_time =? and good_id = ? and status =1 and project_id = 0", patient_id, org_id, record_time, good_id).Find(&automaticReduceDetail).Error
  2907. if err != gorm.ErrRecordNotFound {
  2908. if err != nil {
  2909. tx.Rollback()
  2910. return automaticReduceDetail, err
  2911. }
  2912. }
  2913. return automaticReduceDetail, err
  2914. }
  2915. func UpdateDrugAutoDetail(id int64, advice_id int64, tx *gorm.DB) error {
  2916. drugAutomaticReduceDetail := models.DrugAutomaticReduceDetail{}
  2917. err := tx.Model(&drugAutomaticReduceDetail).Where("id = ? and status=1", id).Updates(map[string]interface{}{"advice_id": advice_id}).Error
  2918. if err != nil {
  2919. tx.Rollback()
  2920. return err
  2921. }
  2922. return err
  2923. }
  2924. func UpdateGoodAutoDetail(id int64, project_id int64, tx *gorm.DB) error {
  2925. automaticReduceDetail := models.AutomaticReduceDetail{}
  2926. err := tx.Model(&automaticReduceDetail).Where("id = ? and status=1", id).Updates(map[string]interface{}{"project_id": project_id}).Error
  2927. if err != nil {
  2928. tx.Rollback()
  2929. return err
  2930. }
  2931. return err
  2932. }
  2933. func UpdateDrugOutInfoByAdviceId(id int64, advice_id int64, tx *gorm.DB) (models.DrugWarehouseOutInfo, error) {
  2934. info := models.DrugWarehouseOutInfo{}
  2935. err := tx.Model(&info).Where("id = ? and status=1", id).Updates(map[string]interface{}{"advice_id": advice_id}).Error
  2936. if err != nil {
  2937. tx.Rollback()
  2938. return info, err
  2939. }
  2940. return info, err
  2941. }
  2942. func UpdateGoodOutInfoByAdviceId(id int64, project_id int64, tx *gorm.DB) (models.WarehouseOutInfo, error) {
  2943. info := models.WarehouseOutInfo{}
  2944. err := tx.Model(&info).Where("id = ? and status=1", id).Updates(map[string]interface{}{"project_id": project_id}).Error
  2945. if err != nil {
  2946. tx.Rollback()
  2947. return info, err
  2948. }
  2949. return info, err
  2950. }
  2951. func ModifyDrugWarehouseOutInfoByNumber(id int64, cha_count int64, tx *gorm.DB) error {
  2952. err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
  2953. err = tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("over_count", gorm.Expr("over_count + ?", cha_count)).Error
  2954. if err != nil {
  2955. tx.Rollback()
  2956. return err
  2957. }
  2958. return err
  2959. }
  2960. func ModifyDrugAuToWarehouseOut(id int64, cha_count int64, tx *gorm.DB) error {
  2961. err := tx.Model(&models.DrugAutomaticReduceDetail{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
  2962. if err != nil {
  2963. tx.Rollback()
  2964. return err
  2965. }
  2966. return err
  2967. }
  2968. func ModifyGoodAuToWarehouseOut(id int64, cha_count int64, tx *gorm.DB) error {
  2969. err := tx.Model(&models.AutomaticReduceDetail{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
  2970. if err != nil {
  2971. tx.Rollback()
  2972. return err
  2973. }
  2974. return err
  2975. }
  2976. func DeleteDrugWarehouseOutInfoByNumber(id int64, tx *gorm.DB) error {
  2977. err := tx.Model(&models.DrugWarehouseOutInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
  2978. if err != nil {
  2979. tx.Rollback()
  2980. return err
  2981. }
  2982. return err
  2983. }
  2984. func DeleteDrugWarehouseAutoByNumber(id int64, tx *gorm.DB) error {
  2985. err := tx.Model(&models.DrugAutomaticReduceDetail{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
  2986. if err != nil {
  2987. tx.Rollback()
  2988. return err
  2989. }
  2990. return err
  2991. }
  2992. func DeleteGoodWarehouseAutoByNumberTwo(id int64, tx *gorm.DB) error {
  2993. err := tx.Model(&models.AutomaticReduceDetail{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
  2994. if err != nil {
  2995. tx.Rollback()
  2996. return err
  2997. }
  2998. return err
  2999. }
  3000. func GetHistoryProject(patient_id int64, user_org_id int64, record_date int64, id int64, good_id int64, tx *gorm.DB) (models.HisPrescriptionProject, error) {
  3001. project := models.HisPrescriptionProject{}
  3002. err := tx.Where("patient_id = ? and user_org_id = ? and record_date = ? and id = ? and project_id = ? and status =1", patient_id, user_org_id, record_date, id, good_id).Find(&project).Error
  3003. if err != gorm.ErrRecordNotFound {
  3004. if err != nil {
  3005. tx.Rollback()
  3006. return project, err
  3007. }
  3008. }
  3009. return project, err
  3010. }
  3011. func GetGoodWarehouseOutInfoByProjectIdTwo(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, advice_id int64, tx *gorm.DB) (models.WarehouseOutInfo, error) {
  3012. outInfo := models.WarehouseOutInfo{}
  3013. err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and good_id = ? and status=1 and project_id = ?", patient_id, user_org_id, sys_record_date, drug_id, advice_id).Order("id desc").First(&outInfo).Error
  3014. if err != gorm.ErrRecordNotFound {
  3015. if err != nil {
  3016. tx.Rollback()
  3017. return outInfo, err
  3018. }
  3019. }
  3020. return outInfo, err
  3021. }
  3022. func GetGoodWarehouseOutInfoByProjectIdThree(patient_id int64, user_org_id int64, sys_record_date int64, drug_id int64, tx *gorm.DB) (models.WarehouseOutInfo, error) {
  3023. outInfo := models.WarehouseOutInfo{}
  3024. err = tx.Where("patient_id = ? and org_id =? and sys_record_time = ? and good_id = ? and status=1", patient_id, user_org_id, sys_record_date, drug_id).Order("id desc").Last(&outInfo).Error
  3025. if err != gorm.ErrRecordNotFound {
  3026. if err != nil {
  3027. tx.Rollback()
  3028. return outInfo, err
  3029. }
  3030. }
  3031. return outInfo, err
  3032. }
  3033. func DeleteGoodWarehouseOutInfoByNumber(id int64, tx *gorm.DB) error {
  3034. err := tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
  3035. if err != nil {
  3036. tx.Rollback()
  3037. return err
  3038. }
  3039. return err
  3040. }
  3041. func ModifyGoodWarehouseOutInfoByNumber(id int64, cha_count int64, tx *gorm.DB) error {
  3042. err := tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("count", gorm.Expr("count - ?", cha_count)).Error
  3043. err = tx.Model(&models.WarehouseOutInfo{}).Where("id = ? and status =1", id).UpdateColumn("over_count", gorm.Expr("over_count + ?", cha_count)).Error
  3044. if err != nil {
  3045. tx.Rollback()
  3046. return err
  3047. }
  3048. return err
  3049. }
  3050. func GetBasedrugById(drug_id int64, user_org_id int64) (models.BaseDrugLib, error) {
  3051. lib := models.BaseDrugLib{}
  3052. err := XTReadDB().Where("id = ? and org_id =? and status=1 AND find_in_set('停用',drug_status) = 1", drug_id, user_org_id).Find(&lib).Error
  3053. return lib, err
  3054. }
  3055. func GetBaseGoodById(good_id int64, user_org_id int64) (models.GoodInfo, error) {
  3056. info := models.GoodInfo{}
  3057. err := XTReadDB().Where("id = ? and org_id =? and status=1 AND find_in_set('停用',good_status) = 1", good_id, user_org_id).Find(&info).Error
  3058. return info, err
  3059. }
  3060. func GetBasedrugByIdOne(drug_id int64, user_org_id int64) (models.BaseDrugLib, error) {
  3061. lib := models.BaseDrugLib{}
  3062. err := XTReadDB().Where("id = ? and org_id =? and status=1", drug_id, user_org_id).Find(&lib).Error
  3063. return lib, err
  3064. }
  3065. //func UpDateOrderT111(order models.histen) (err error) {
  3066. // err = writeDb.Save(&order).Error
  3067. // return
  3068. //}
  3069. func GetDialysisPresriptionById(user_org_id int64, patient_id int64, record_date int64) (models.HisPrescriptionInfo, error) {
  3070. prescriptionInfo := models.HisPrescriptionInfo{}
  3071. err := XTReadDB().Where("user_org_id = ? and patient_id = ? and record_date = ? and status=1", user_org_id, patient_id, record_date).First(&prescriptionInfo).Error
  3072. return prescriptionInfo, err
  3073. }
  3074. func CreateGoodTeam(team models.XtGoodTeam) error {
  3075. err := XTWriteDB().Create(&team).Error
  3076. return err
  3077. }
  3078. func SaveGoodTeam(team models.XtGoodTeam) error {
  3079. err := XTWriteDB().Save(&team).Error
  3080. return err
  3081. }
  3082. func GetLastGoodTeam(org_id int64) (models.XtGoodTeam, error) {
  3083. goodTeam := models.XtGoodTeam{}
  3084. err := XTReadDB().Where("user_org_id = ? and status=1", org_id).Last(&goodTeam).Error
  3085. return goodTeam, err
  3086. }
  3087. func CreateGoodList(list models.XtGoodTeamList) error {
  3088. err := XTWriteDB().Create(&list).Error
  3089. return err
  3090. }
  3091. func SaveGoodList(list models.XtGoodTeamList) error {
  3092. err := XTWriteDB().Save(&list).Error
  3093. return err
  3094. }
  3095. func GetGoodList(user_org_id int64, limit int64, page int64, keyword string) (list []*models.XtGoodTeam, total int64, err error) {
  3096. key := "%" + keyword + "%"
  3097. offset := (page - 1) * limit
  3098. db := XTReadDB().Model(&list).Where("status=1")
  3099. if user_org_id > 0 {
  3100. db = db.Where("user_org_id = ?", user_org_id)
  3101. }
  3102. if len(keyword) > 0 {
  3103. db = db.Where("project_name like ?", key)
  3104. }
  3105. err = db.Count(&total).Offset(offset).Limit(limit).Order("id desc").Find(&list).Error
  3106. return list, total, err
  3107. }
  3108. func GetGoodNameDetail(id int64, org_id int64) (models.XtGoodTeam, error) {
  3109. goodTeam := models.XtGoodTeam{}
  3110. err := XTReadDB().Where("id = ? and status =1 and user_org_id = ?", id, org_id).Preload("XtGoodTeamList", "status = 1 and user_org_id = ?", org_id).Find(&goodTeam).Error
  3111. return goodTeam, err
  3112. }
  3113. func DeleteGoodTeam(id int64) (models.XtGoodTeamList, error) {
  3114. goodTeamList := models.XtGoodTeamList{}
  3115. err := XTWriteDB().Model(&goodTeamList).Where("id = ? and status =1", id).Updates(map[string]interface{}{"status": 0}).Error
  3116. return goodTeamList, err
  3117. }
  3118. func DeleteGood(id int64) (models.XtGoodTeam, error) {
  3119. goodTeam := models.XtGoodTeam{}
  3120. err := XTWriteDB().Model(&goodTeam).Where("id = ? and status=1", id).Updates(map[string]interface{}{"status": 0}).Error
  3121. return goodTeam, err
  3122. }
  3123. func GetFaPiaoHisOrderByID(order_id int64) (order models.HisFaPiaoOrder, err error) {
  3124. str := strconv.FormatInt(order_id, 10)
  3125. key := "%" + str + "%"
  3126. err = readDb.Model(&models.HisFaPiaoOrder{}).Where("order_ids like ? and status = 1", key).First(&order).Error
  3127. return
  3128. }
  3129. func GetDrugInfomationList(orgid int64, keyword string) (drug []*models.BaseDrugLib, err error) {
  3130. key := "%" + keyword + "%"
  3131. if len(keyword) == 0 {
  3132. err = XTReadDB().Where("org_id = ? and status = 1 AND find_in_set('停用',drug_status) = 0", orgid).Find(&drug).Error
  3133. } else {
  3134. err = XTReadDB().Where("org_id = ? and status = 1 AND drug_name like ? AND find_in_set('停用',drug_status) = 0", orgid, key).Find(&drug).Error
  3135. }
  3136. return drug, err
  3137. }
  3138. func CreateDoctorAdviceTeamList(list *models.HisDoctorAdviceTeamInfo) error {
  3139. err := XTWriteDB().Model(&list).Save(&list).Error
  3140. return err
  3141. }
  3142. func GetDrugHisListByIds(ids []string) (hisProjectList []*models.HisDoctorAdviceTeamInfo, error error) {
  3143. error = XTReadDB().Model(&hisProjectList).Preload("BaseDrugLib").Where(" status = 1 and id in (?)", ids).Find(&hisProjectList).Error
  3144. return hisProjectList, error
  3145. }