his_service.go 175KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871
  1. package service
  2. import (
  3. "XT_New/models"
  4. "fmt"
  5. "github.com/jinzhu/gorm"
  6. "strings"
  7. "time"
  8. )
  9. type VMSchedule struct {
  10. ID int64 `gorm:"column:id" json:"id" form:"id"`
  11. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  12. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  13. Status int64 `gorm:"column:status" json:"status" form:"status"`
  14. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  15. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  16. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  17. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  18. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  19. }
  20. func (VMSchedule) TableName() string {
  21. return "xt_schedule"
  22. }
  23. type HisPatient struct {
  24. ID int64 `gorm:"column:id" json:"id" form:"id"`
  25. Name string `gorm:"column:name" json:"name" form:"name"`
  26. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  27. Total float64 `gorm:"column:total" json:"total" form:"total"`
  28. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  29. Status int64 `gorm:"column:status" json:"status" form:"status"`
  30. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  31. HisPrescription []*HisPrescription `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  32. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  33. Number string `gorm:"column:number" json:"number" form:"number"`
  34. VMHisOrders []*VMHisOrder `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"orders"`
  35. VMHisOrder VMHisOrder `gorm:"ForeignKey:MdtrtId,PatientId;AssociationForeignKey:Number,PatientId" json:"order"`
  36. }
  37. func (HisPatient) TableName() string {
  38. return "his_patient"
  39. }
  40. type VMHisPrescriptionInfo struct {
  41. ID int64 `gorm:"column:id" json:"id" form:"id"`
  42. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  43. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  44. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  45. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  46. Status int64 `gorm:"column:status" json:"status" form:"status"`
  47. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  48. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  49. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  50. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  51. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  52. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  53. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  54. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  55. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  56. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  57. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  58. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  59. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  60. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  61. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  62. }
  63. func (VMHisPrescriptionInfo) TableName() string {
  64. return "his_prescription_info"
  65. }
  66. type VMHisOrder struct {
  67. ID int64 `gorm:"column:id" json:"id" form:"id"`
  68. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  69. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  70. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  71. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  72. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  73. Status int64 `gorm:"column:status" json:"status" form:"status"`
  74. Number string `gorm:"column:number" json:"number" form:"number"`
  75. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  76. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  77. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  78. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  79. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  80. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  81. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  82. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  83. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  84. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  85. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  86. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  87. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  88. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  89. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  90. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  91. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  92. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  93. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  94. }
  95. func (VMHisOrder) TableName() string {
  96. return "his_order"
  97. }
  98. type Patients struct {
  99. ID int64 `gorm:"column:id" json:"id" form:"id"`
  100. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  101. Name string `gorm:"column:name" json:"name" form:"name"`
  102. Status int64 `gorm:"column:status" json:"status" form:"status"`
  103. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  104. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  105. Phone int64 `gorm:"column:phone" json:"phone" form:"phone"`
  106. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  107. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  108. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  109. HisPatient HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  110. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  111. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  112. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"order"`
  113. }
  114. func (Patients) TableName() string {
  115. return "xt_patients"
  116. }
  117. type HisPrescription struct {
  118. ID int64 `gorm:"column:id" json:"id" form:"id"`
  119. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  120. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  121. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  122. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  123. Status int64 `gorm:"column:status" json:"status" form:"status"`
  124. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  125. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  126. }
  127. func (HisPrescription) TableName() string {
  128. return "his_prescription"
  129. }
  130. func GetScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*Patients, err error) {
  131. 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,sch.schedule_type as sch_type").Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  132. if sch_type != 0 {
  133. 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)
  134. } else {
  135. 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)
  136. }
  137. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  138. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  139. 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").Order("sch_type").Find(&patients).Error
  140. return
  141. }
  142. func GetChargeHisPatientListOne(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  143. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  144. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  145. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  146. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  147. return
  148. }
  149. func GetAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  150. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  151. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  152. db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  153. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  154. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  155. return
  156. }
  157. func GetChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  158. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  159. 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)
  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 GetHisPatientList(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. 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)
  168. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  169. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  170. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  171. return
  172. }
  173. type PatientTwo struct {
  174. ID int64 `gorm:"column:id" json:"id" form:"id"`
  175. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  176. Name string `gorm:"column:name" json:"name" form:"name"`
  177. Status int64 `gorm:"column:status" json:"status" form:"status"`
  178. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  179. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  180. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  181. HisPatient []*HisPatientTwo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  182. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  183. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  184. }
  185. func (PatientTwo) TableName() string {
  186. return "xt_patients"
  187. }
  188. type HisPatientTwo struct {
  189. ID int64 `gorm:"column:id" json:"id" form:"id"`
  190. Name string `gorm:"column:name" json:"name" form:"name"`
  191. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  192. Total float64 `gorm:"column:total" json:"total" form:"total"`
  193. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  194. Status int64 `gorm:"column:status" json:"status" form:"status"`
  195. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  196. HisPrescriptionTwo []*HisPrescriptionTwo `gorm:"ForeignKey:PatientId,HisPatientId;AssociationForeignKey:PatientId,ID" json:"prescription"`
  197. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  198. Number string `gorm:"column:number" json:"number" form:"number"`
  199. }
  200. func (HisPatientTwo) TableName() string {
  201. return "his_patient"
  202. }
  203. type HisPrescriptionTwo struct {
  204. ID int64 `gorm:"column:id" json:"id" form:"id"`
  205. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  206. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  207. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  208. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  209. Status int64 `gorm:"column:status" json:"status" form:"status"`
  210. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  211. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  212. Number string `gorm:"column:number" json:"number" form:"number"`
  213. Type int64 `gorm:"column:type" json:"type" form:"type"`
  214. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  215. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  216. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  217. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  218. PreTime int64 `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
  219. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  220. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  221. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  222. }
  223. func (HisPrescriptionTwo) TableName() string {
  224. return "his_prescription"
  225. }
  226. func GetNewHisPatientList(org_id int64, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  227. db := readDb.Model(&PatientTwo{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  228. 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)
  229. if sch_type > 0 {
  230. 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)
  231. }
  232. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  233. 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)
  234. })
  235. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("id").Find(&patients).Error
  236. return
  237. }
  238. func GetNewScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  239. 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)
  240. if sch_type != 0 {
  241. 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)
  242. } else {
  243. 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)
  244. }
  245. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  246. 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
  247. return
  248. }
  249. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  250. err = readDb.Model(&models.BaseDrugLib{}).Where("org_id = ? AND status = 1", org_id).Find(&drugs).Error
  251. return
  252. }
  253. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  254. 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
  255. return
  256. }
  257. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  258. 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
  259. return
  260. }
  261. func GetHisPatientInfoThree(org_id int64, number string) (info models.HisPatient, err error) {
  262. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND number = ?", org_id, number).First(&info).Error
  263. return
  264. }
  265. func GetHisPatientInfoTen(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  266. 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
  267. return
  268. }
  269. func GetHisPatientInfoFour(org_id int64, patient_id int64, record_date int64, his_patient_id int64) (info models.HisPatient, err error) {
  270. 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
  271. return
  272. }
  273. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  274. 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
  275. return
  276. }
  277. func GetNewHisPatientInfoTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  278. 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
  279. return
  280. }
  281. func GetNewHisHosptialRecordTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  282. 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
  283. return
  284. }
  285. func GetHisPatientCount(org_id int64, patient_id int64, record_date int64) (total int64, err error) {
  286. 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
  287. return
  288. }
  289. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  290. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  291. return
  292. }
  293. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  294. 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
  295. return
  296. }
  297. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  298. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  299. err = db.Find(&caseHistorys).Error
  300. return
  301. }
  302. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  303. likekey := "%" + keyword + "%"
  304. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  305. if startime > 0 {
  306. db = db.Where("record_date>=?", startime)
  307. }
  308. if endtime > 0 {
  309. db = db.Where("record_date<=?", endtime)
  310. }
  311. if len(keyword) > 0 {
  312. db = db.Where("template_name like ? ", likekey)
  313. }
  314. err = db.Find(&caseHistorys).Error
  315. return
  316. }
  317. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  318. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  319. return caseHistory, err
  320. }
  321. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  322. err = writeDb.Create(&template).Error
  323. return
  324. }
  325. func GetHisPatientCaseHistoryById(patient_id int64, record_date int64, user_org_id int64) (*models.HisPatientCaseHistory, error) {
  326. history := models.HisPatientCaseHistory{}
  327. 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
  328. if err != nil {
  329. if err == gorm.ErrRecordNotFound {
  330. return nil, err
  331. } else {
  332. return nil, err
  333. }
  334. }
  335. return &history, nil
  336. }
  337. func GetLastHisPatientCaseHistoryById(patient_id int64) (models.HisPatientCaseHistory, error) {
  338. history := models.HisPatientCaseHistory{}
  339. err := XTReadDB().Model(&history).Where("patient_id = ? and status = 1", patient_id).Last(&history).Error
  340. return history, err
  341. }
  342. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  343. err := writeDb.Create(&caseHistory).Error
  344. return err
  345. }
  346. func UpdatePatientCaseHistory(patient_id int64, record_date int64, user_org_id int64, his *models.HisPatientCaseHistory) error {
  347. 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
  348. return err
  349. }
  350. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  351. tx := writeDb.Begin()
  352. if err = tx.Model(&models.HisPrescription{}).Save(prescription).Error; err != nil {
  353. tx.Rollback()
  354. return
  355. }
  356. tx.Commit()
  357. return
  358. }
  359. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  360. 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
  361. 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
  362. 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
  363. return
  364. }
  365. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  366. 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
  367. return
  368. }
  369. func DelelteProject(id int64, user_org_id int64) (err error) {
  370. 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
  371. return
  372. }
  373. func GetHisPrescription(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  374. err = readDb.Model(&models.HisPrescription{}).
  375. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  376. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  377. }).
  378. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  379. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  380. }).
  381. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  382. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  383. }).
  384. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ?", org_id, record_date, patient_id, p_type).
  385. Find(&prescription).Error
  386. return
  387. }
  388. func GetNewHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  389. err = readDb.Model(&models.HisPrescription{}).
  390. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  391. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  392. }).
  393. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  394. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  395. }).
  396. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  397. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  398. }).
  399. 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).
  400. Find(&prescription).Error
  401. return
  402. }
  403. func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  404. err = readDb.Model(&models.HisPrescription{}).
  405. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  406. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  407. }).
  408. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  409. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  410. }).
  411. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  412. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  413. }).
  414. 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).
  415. Find(&prescription).Error
  416. return
  417. }
  418. func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  419. err = readDb.Model(&models.HisPrescription{}).
  420. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  421. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  422. }).
  423. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  424. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  425. }).
  426. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  427. 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")
  428. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  429. return db.Where("status = 1 AND user_org_id = ? AND order_status <> 3 AND order_status <> 2 ", org_id)
  430. }).
  431. 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).
  432. Find(&prescription).Error
  433. return
  434. }
  435. func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  436. err = readDb.Model(&models.HisPrescription{}).
  437. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  438. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  439. }).
  440. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  441. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  442. }).
  443. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  444. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  445. }).
  446. 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).
  447. Find(&prescription).Error
  448. return
  449. }
  450. 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) {
  451. err = tx.Model(&models.HisPrescription{}).
  452. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  453. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  454. }).
  455. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  456. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  457. }).
  458. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  459. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  460. }).
  461. 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).
  462. Find(&prescription).Error
  463. return
  464. }
  465. 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) {
  466. err = tx.Model(&models.HisPrescription{}).
  467. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  468. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  469. }).
  470. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  471. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  472. }).
  473. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  474. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  475. }).
  476. 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).
  477. Find(&prescription).Error
  478. return
  479. }
  480. func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  481. err = readDb.Model(&models.HisPrescription{}).
  482. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  483. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  484. }).
  485. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  486. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  487. }).
  488. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  489. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  490. }).
  491. 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).
  492. Find(&prescription).Error
  493. return
  494. }
  495. 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) {
  496. err = tx.Model(&models.HisPrescription{}).
  497. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  498. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  499. }).
  500. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  501. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  502. }).
  503. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  504. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  505. }).
  506. 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).
  507. Find(&prescription).Error
  508. return
  509. }
  510. 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) {
  511. err = tx.Model(&models.HisPrescription{}).
  512. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  513. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  514. }).
  515. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  516. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  517. }).
  518. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  519. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  520. }).
  521. 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).
  522. Find(&prescription).Error
  523. return
  524. }
  525. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  526. err = readDb.Model(&models.HisPrescription{}).
  527. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  528. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  529. }).
  530. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  531. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  532. }).
  533. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  534. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  535. }).
  536. 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).
  537. Find(&prescription).Error
  538. return
  539. }
  540. func GetMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  541. err = readDb.Model(&models.HisPrescription{}).
  542. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  543. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  544. }).
  545. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  546. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  547. }).
  548. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  549. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  550. }).
  551. 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).
  552. Find(&prescription).Error
  553. return
  554. }
  555. // 未收费
  556. func GetUnChargeMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  557. err = readDb.Model(&models.HisPrescription{}).
  558. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  559. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  560. }).
  561. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  562. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  563. }).
  564. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  565. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  566. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  567. return db.Where("status = 1 AND user_org_id = ?", org_id)
  568. }).
  569. 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).
  570. Find(&prescription).Error
  571. return
  572. }
  573. // 已收费
  574. func GetChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  575. err = readDb.Model(&models.HisPrescription{}).
  576. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  577. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  578. }).
  579. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  580. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  581. }).
  582. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  583. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  584. }).
  585. 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).
  586. Find(&prescription).Error
  587. return
  588. }
  589. func GetUnChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64) (prescription []*models.HisPrescription, err error) {
  590. err = readDb.Model(&models.HisPrescription{}).
  591. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  592. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  593. }).
  594. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  595. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  596. }).
  597. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  598. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  599. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  600. return db.Where("status = 1 AND user_org_id = ?", org_id)
  601. }).
  602. 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).
  603. Find(&prescription).Error
  604. return
  605. }
  606. type OtherDrugWarehouseInfo struct {
  607. ID int64 `gorm:"column:id" json:"id" form:"id"`
  608. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  609. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  610. Status int64 `gorm:"column:status" json:"status" form:"status"`
  611. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  612. StockMaxNumber int64 `gorm:"column:stock_max_number" json:"stock_max_number" form:"stock_max_number"`
  613. StockMinNumber int64 `gorm:"column:stock_min_number" json:"stock_min_number" form:"stock_min_number"`
  614. Price float64 `gorm:"column:price" json:"price" form:"price"`
  615. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  616. }
  617. func (OtherDrugWarehouseInfo) TableName() string {
  618. return "xt_drug_warehouse_info"
  619. }
  620. type VMDrugSalesReturnInfo struct {
  621. ID int64 `gorm:"column:id" json:"id" form:"id"`
  622. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  623. Count int64 `gorm:"column:count" json:"count" form:"count"`
  624. Status int64 `gorm:"column:status" json:"status" form:"status"`
  625. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  626. }
  627. func (VMDrugSalesReturnInfo) TableName() string {
  628. return "xt_drug_sales_return_info"
  629. }
  630. type VMDrugWarehouseOutInfo struct {
  631. ID int64 `gorm:"column:id" json:"id" form:"id"`
  632. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  633. Count int64 `gorm:"column:count" json:"count" form:"count"`
  634. Status int64 `gorm:"column:status" json:"status" form:"status"`
  635. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  636. }
  637. func (VMDrugWarehouseOutInfo) TableName() string {
  638. return "xt_drug_warehouse_out_info"
  639. }
  640. type VMDrugCancelStockInfo struct {
  641. ID int64 `gorm:"column:id" json:"id" form:"id"`
  642. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  643. Count int64 `gorm:"column:count" json:"count" form:"count"`
  644. Status int64 `gorm:"column:status" json:"status" form:"status"`
  645. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  646. }
  647. func (VMDrugCancelStockInfo) TableName() string {
  648. return "xt_drug_cancel_stock_info"
  649. }
  650. type BaseDrugLib struct {
  651. ID int64 `gorm:"column:id" json:"id" form:"id"`
  652. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  653. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  654. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  655. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  656. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  657. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  658. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  659. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  660. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  661. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  662. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  663. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  664. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  665. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  666. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  667. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  668. Dose string `gorm:"column:dose" json:"dose" form:"dose"`
  669. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  670. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  671. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  672. MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
  673. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  674. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  675. Number string `gorm:"column:number" json:"number" form:"number"`
  676. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  677. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  678. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  679. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  680. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  681. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  682. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  683. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  684. Code string `gorm:"column:code" json:"code" form:"code"`
  685. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  686. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  687. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  688. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  689. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  690. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  691. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  692. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  693. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  694. Label int64 `gorm:"column:label" json:"label" form:"label"`
  695. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  696. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  697. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  698. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  699. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  700. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  701. Status int64 `gorm:"column:status" json:"status" form:"status"`
  702. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  703. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  704. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  705. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  706. Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
  707. PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
  708. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  709. DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
  710. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  711. DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
  712. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  713. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  714. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  715. //Dosage string `gorm:"column:dosage" json:"dosage" form:"dosage"`
  716. //Unval string `gorm:"column:unval" json:"unval" form:"unval"`
  717. //PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  718. PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
  719. DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
  720. Total float64 `gorm:"column:total" json:"total" form:"total"`
  721. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  722. BatchRetaiPrice float64 `gorm:"column:batch_retai_price" json:"batch_retai_price" form:"batch_retai_price"`
  723. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  724. SumCount int64 `gorm:"column:sum_count" json:"sum_count" form:"sum_count"`
  725. SumInCount int64 `gorm:"column:sum_in_count" json:"sum_in_count" form:"sum_in_count"`
  726. FirstLetter string `gorm:"column:first_letter" json:"first_letter" form:"first_letter"`
  727. Bby01 string `gorm:"column:bby01" json:"bby01" form:"bby01"`
  728. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  729. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  730. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  731. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  732. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  733. }
  734. func (BaseDrugLib) TableName() string {
  735. return "xt_base_drug"
  736. }
  737. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  738. 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 {
  739. return db.Where("(status = 1 and stock_max_number > 0) or (status = 1 AND stock_min_number >0)")
  740. }).Find(&list).Error
  741. //err = readDb.Model(&BaseDrugLib{}).Where("org_id = ? AND status = 1 AND find_in_set('停用',drug_status) = 0", org_id).Find(&list).Error
  742. return
  743. }
  744. func GetAllDrugLibListSix(org_id int64, storehouse_id int64) (list []*BaseDrugLib, err error) {
  745. 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 {
  746. 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)
  747. }).Find(&list).Error
  748. return
  749. }
  750. func GetAllDrugLibListSeven(org_id int64, storehouse_id int64) (list []*BaseDrugLib, err error) {
  751. 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 {
  752. return db.Where("(status = 1 and storehouse_id = ? ) or (status = 1 and storehouse_id = ?)", storehouse_id, storehouse_id)
  753. }).Find(&list).Error
  754. return
  755. }
  756. func GetAllDrugLibs(org_id int64) (drugs []*Drugs, err error) {
  757. 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")
  758. err = db.Find(&drugs).Error
  759. return
  760. }
  761. func GetAllProjectList(org_id int64, keyword string) (list []*models.HisProject, err error) {
  762. if len(keyword) != 0 {
  763. key := "%" + keyword + "%"
  764. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 AND project_name Like ? ", org_id, key).Find(&list).Error
  765. } else {
  766. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 ", org_id).Find(&list).Error
  767. }
  768. return
  769. }
  770. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  771. err = writeDb.Create(&charge).Error
  772. return
  773. }
  774. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  775. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  776. 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")
  777. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  778. return
  779. }
  780. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  781. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  782. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  783. }).Where("org_id = ? AND status = 1 AND user_type = 2", org_id).Find(&doctors).Error
  784. return
  785. }
  786. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  787. tx := writeDb.Begin()
  788. if err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error; err != nil {
  789. tx.Rollback()
  790. return
  791. }
  792. tx.Commit()
  793. return
  794. }
  795. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  796. tx := writeDb.Begin()
  797. if err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error; err != nil {
  798. tx.Rollback()
  799. return
  800. }
  801. tx.Commit()
  802. return
  803. }
  804. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  805. err = writeDb.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
  806. return
  807. }
  808. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  809. err := writeDb.Create(&patient).Error
  810. return err
  811. }
  812. func GetVMHisPatientInfo(org_id int64, id int64, record_date int64) (info models.VMHisPatient, err error) {
  813. 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
  814. return
  815. }
  816. func CreateOrder(order *models.HisOrder) (err error) {
  817. err = writeDb.Create(&order).Error
  818. return
  819. }
  820. func CreateOrderTX(order *models.HisOrder, tx *gorm.DB) (err error) {
  821. err = tx.Create(&order).Error
  822. return
  823. }
  824. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  825. err = writeDb.Create(&order).Error
  826. return
  827. }
  828. func CreateOrderInfoTX(order *models.HisOrderInfo, tx *gorm.DB) (err error) {
  829. err = tx.Create(&order).Error
  830. return
  831. }
  832. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  833. 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
  834. return
  835. }
  836. func FindPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  837. 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
  838. return
  839. }
  840. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  841. 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
  842. return
  843. }
  844. func FindHisPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  845. 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
  846. return
  847. }
  848. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  849. 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
  850. return
  851. }
  852. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  853. tx := writeDb.Begin()
  854. if err = tx.Model(&models.HisPrescription{}).Save(&info).Error; err != nil {
  855. tx.Rollback()
  856. return
  857. }
  858. tx.Commit()
  859. return
  860. }
  861. 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) (order []*models.HisOrder, err error, total int64) {
  862. offset := (page - 1) * limit
  863. db := readDb.Model(&models.HisOrder{})
  864. if doctor_id > 0 {
  865. 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)
  866. }
  867. if len(keywords) > 0 {
  868. keywords = "%" + keywords + "%"
  869. db = db.Joins("join xt_patients as patient on patient.id = his_order.patient_id AND patient.name like ? AND patient.user_org_id = ?", keywords, user_org_id)
  870. }
  871. if sch_type > 0 && zone_type > 0 {
  872. 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)
  873. }
  874. if sch_type > 0 && zone_type == 0 {
  875. 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)
  876. }
  877. if sch_type == 0 && zone_type > 0 {
  878. 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)
  879. }
  880. if med_type > 0 {
  881. db = db.Where("his_order.med_type = ?", med_type)
  882. }
  883. //if zone_type > 0 {
  884. // 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)
  885. //}
  886. if sort_type == 1 {
  887. if start_time_timestamp != 0 {
  888. db = db.Where("his_order.settle_accounts_date>=?", start_time_timestamp)
  889. }
  890. if end_time_timestamp != 0 {
  891. db = db.Where("his_order.settle_accounts_date<=?", end_time_timestamp)
  892. }
  893. } else {
  894. if len(start_time) != 0 {
  895. db = db.Where("his_order.setl_time>=?", start_time+" 00:00:00")
  896. }
  897. if len(end_time) != 0 {
  898. db = db.Where("his_order.setl_time<=?", end_time+" 23:59:59")
  899. }
  900. }
  901. if p_type > 0 {
  902. 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)
  903. } else {
  904. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.order_status = 2", user_org_id)
  905. }
  906. if charge_type > 0 {
  907. if charge_type == 2 {
  908. db = db.Where("his_order.is_medicine_insurance = 0")
  909. } else {
  910. db = db.Where("his_order.is_medicine_insurance = ?", charge_type)
  911. }
  912. }
  913. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  914. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  915. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  916. Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ?", user_org_id)
  917. db = db.Preload("HisFundSettleListResult", "status = 1")
  918. db = db.Count(&total)
  919. db = db.Limit(limit).Offset(offset)
  920. if user_org_id == 10215 {
  921. if sort_type == 1 {
  922. err = db.Order("settle_accounts_date asc,ctime asc").Group("his_order.id").Find(&order).Error
  923. }
  924. if sort_type == 2 {
  925. err = db.Order("setl_time asc,ctime asc").Group("his_order.id").Find(&order).Error
  926. }
  927. } else {
  928. if sort_type == 1 {
  929. err = db.Order("settle_accounts_date desc,ctime desc").Group("his_order.id").Find(&order).Error
  930. }
  931. if sort_type == 2 {
  932. err = db.Order("setl_time desc,ctime desc").Group("his_order.id").Find(&order).Error
  933. }
  934. }
  935. return
  936. }
  937. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  938. 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
  939. return
  940. }
  941. func UpDatePrescriptionNumberTX(user_org_id int64, ids []int64, number string, tx *gorm.DB) (err error) {
  942. 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
  943. return
  944. }
  945. func UpDateAddtionNumber(user_org_id int64, ids []int64, number string) (err error) {
  946. 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
  947. return
  948. }
  949. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  950. 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
  951. return
  952. }
  953. func UpDateHisPrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64) (err error) {
  954. 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
  955. return
  956. }
  957. func UpDateHisPrescriptionInfoNumberTX(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64, tx *gorm.DB) (err error) {
  958. 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
  959. return
  960. }
  961. func UpDateHospitalHisPrescriptionInfoNumber(user_org_id int64, number string, start_time int64, end_time int64) (err error) {
  962. 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
  963. return
  964. }
  965. type HisOrder struct {
  966. ID int64 `gorm:"column:id" json:"id" form:"id"`
  967. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  968. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  969. Number string `gorm:"column:number" json:"number" form:"number"`
  970. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  971. Status int64 `gorm:"column:status" json:"status" form:"status"`
  972. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  973. Infcode int64 `gorm:"column:infcode" json:"infcode" form:"infcode"`
  974. WarnMsg string `gorm:"column:warn_msg" json:"warn_msg" form:"warn_msg"`
  975. Cainfo string `gorm:"column:cainfo" json:"cainfo" form:"cainfo"`
  976. ErrMsg string `gorm:"column:err_msg" json:"err_msg" form:"err_msg"`
  977. RespondTime string `gorm:"column:respond_time" json:"respond_time" form:"respond_time"`
  978. InfRefmsgid string `gorm:"column:inf_refmsgid" json:"inf_refmsgid" form:"inf_refmsgid"`
  979. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  980. MdtrtId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  981. SetlId string `gorm:"column:setl_id" json:"setl_id" form:"setl_id"`
  982. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  983. PsnType string `gorm:"column:psn_type" json:"psn_type" form:"psn_type"`
  984. CvlservFlag string `gorm:"column:cvlserv_flag" json:"cvlserv_flag" form:"cvlserv_flag"`
  985. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  986. MdtrtCertType string `gorm:"column:mdtrt_cert_type" json:"mdtrt_cert_type" form:"mdtrt_cert_type"`
  987. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  988. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  989. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  990. OverlmtSelfPay float64 `gorm:"column:overlmt_self_pay" json:"overlmt_self_pay" form:"overlmt_self_pay"`
  991. PreselfpayAmt float64 `gorm:"column:preselfpay_amt" json:"preselfpay_amt" form:"preselfpay_amt"`
  992. InscpScpAmt float64 `gorm:"column:inscp_scp_amt" json:"inscp_scp_amt" form:"inscp_scp_amt"`
  993. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  994. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  995. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  996. PoolPropSelfpay float64 `gorm:"column:pool_prop_selfpay" json:"pool_prop_selfpay" form:"pool_prop_selfpay"`
  997. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  998. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  999. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1000. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1001. OthPay float64 `gorm:"column:oth_pay" json:"oth_pay" form:"oth_pay"`
  1002. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1003. PsnPartAmt float64 `gorm:"column:psn_part_amt" json:"psn_part_amt" form:"psn_part_amt"`
  1004. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1005. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1006. HospPartAmt float64 `gorm:"column:hosp_part_amt" json:"hosp_part_amt" form:"hosp_part_amt"`
  1007. Balc float64 `gorm:"column:balc" json:"balc" form:"balc"`
  1008. AcctMulaidPay float64 `gorm:"column:acct_mulaid_pay" json:"acct_mulaid_pay" form:"acct_mulaid_pay"`
  1009. MedinsSetlId string `gorm:"column:medins_setl_id" json:"medins_setl_id" form:"medins_setl_id"`
  1010. ClrOptins string `gorm:"column:clr_optins" json:"clr_optins" form:"clr_optins"`
  1011. ClrWay string `gorm:"column:clr_way" json:"clr_way" form:"clr_way"`
  1012. ClrType string `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
  1013. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1014. IsMedicineInsurance int64 `gorm:"column:is_medicine_insurance" json:"is_medicine_insurance" form:"is_medicine_insurance"`
  1015. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1016. SettleType int64 `gorm:"column:settle_type" json:"settle_type" form:"settle_type"`
  1017. SettleStartTime int64 `gorm:"column:settle_start_time" json:"settle_start_time" form:"settle_start_time"`
  1018. SettleEndTime int64 `gorm:"column:settle_end_time" json:"settle_end_time" form:"settle_end_time"`
  1019. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1020. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  1021. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1022. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  1023. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  1024. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  1025. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1026. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1027. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1028. }
  1029. func (HisOrder) TableName() string {
  1030. return "his_order"
  1031. }
  1032. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  1033. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  1034. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1035. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  1036. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  1037. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1038. Order("ctime desc").
  1039. Find(&order).Error
  1040. return
  1041. }
  1042. func GetHisPrescriptionThree(org_id int64, patient_id int64, number string) (prescription []*models.HisPrescription, err error) {
  1043. err = readDb.Model(&models.HisPrescription{}).
  1044. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  1045. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1046. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1047. }).
  1048. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1049. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND batch_number=?", org_id, patient_id, number).
  1050. Find(&prescription).Error
  1051. return
  1052. }
  1053. type HisPrescriptionInfo struct {
  1054. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1055. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1056. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1057. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1058. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1059. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1060. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1061. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1062. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1063. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1064. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1065. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  1066. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1067. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1068. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  1069. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1070. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  1071. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  1072. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1073. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1074. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  1075. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1076. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1077. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1078. }
  1079. func (HisPrescriptionInfo) TableName() string {
  1080. return "his_prescription_info"
  1081. }
  1082. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  1083. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  1084. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  1085. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  1086. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  1087. Order("ctime desc").Find(&prescriptionOrder).Error
  1088. return
  1089. }
  1090. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  1091. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, org_id).
  1092. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  1093. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  1094. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  1095. return
  1096. }
  1097. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  1098. err = readDb.Model(&models.HisPrescription{}).
  1099. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  1100. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1101. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  1102. }).
  1103. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  1104. Find(&prescription).Error
  1105. return
  1106. }
  1107. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  1108. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  1109. return
  1110. }
  1111. func UpdataOrderStatus(id int64, number string, user_org_id int64) (err error) {
  1112. 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
  1113. 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
  1114. 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
  1115. return
  1116. }
  1117. func UpdataHospitalOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  1118. 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
  1119. 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
  1120. 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
  1121. return
  1122. }
  1123. func UpdataOrderInfoStatus(id int64, number string, user_org_id int64) {
  1124. 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
  1125. 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
  1126. return
  1127. }
  1128. func SaveHisPatient(his models.HisPatient) (err error) {
  1129. 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()})
  1130. 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()})
  1131. 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()})
  1132. return
  1133. }
  1134. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  1135. 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()})
  1136. }
  1137. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  1138. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  1139. return
  1140. }
  1141. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  1142. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  1143. First(&order).Error
  1144. return
  1145. }
  1146. func UpDateOrder(order models.HisOrder) (err error) {
  1147. err = writeDb.Save(&order).Error
  1148. return
  1149. }
  1150. func UpDateOrderTX(order models.HisOrder, tx *gorm.DB) (err error) {
  1151. err = writeDb.Save(&order).Error
  1152. return
  1153. }
  1154. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  1155. 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
  1156. 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
  1157. return
  1158. }
  1159. func UpdataOrderStatusTwoTX(number string, user_org_id int64, tx *gorm.DB) (err error) {
  1160. 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
  1161. 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
  1162. return
  1163. }
  1164. func CreateErrMsgLog(log *models.HisOrderError) {
  1165. writeDb.Model(&models.HisOrderError{}).Create(&log)
  1166. }
  1167. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  1168. 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
  1169. return
  1170. }
  1171. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  1172. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  1173. return
  1174. }
  1175. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  1176. db := readDb.Model(&models.OutpatientServiceSick{})
  1177. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1178. err = db.Order("ctime desc").Find(&list).Error
  1179. return
  1180. }
  1181. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  1182. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  1183. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1184. err = db.Order("ctime desc").Find(&list).Error
  1185. return
  1186. }
  1187. func FindPatientDianose(orgId int64) (list []*models.XtPatientDiagnose, err error) {
  1188. err = readDb.Where("user_org_id =?", orgId).Find(&list).Error
  1189. return list, err
  1190. }
  1191. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  1192. db := readDb.Model(&models.XtHisAddtionConfig{})
  1193. db = db.Where("user_org_id = ? AND status = 1", orgId)
  1194. err = db.Order("ctime desc").Find(&list).Error
  1195. return
  1196. }
  1197. type XtHisOrder struct {
  1198. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1199. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1200. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1201. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1202. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1203. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1204. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1205. Number string `gorm:"column:number" json:"number" form:"number"`
  1206. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1207. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  1208. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1209. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  1210. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  1211. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  1212. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1213. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1214. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1215. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1216. }
  1217. func (XtHisOrder) TableName() string {
  1218. return "his_order"
  1219. }
  1220. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  1221. err = readDb.Model(&models.HisPrescription{}).
  1222. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  1223. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1224. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1225. }).
  1226. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  1227. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  1228. Find(&prescription).Error
  1229. return
  1230. }
  1231. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  1232. 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
  1233. return
  1234. }
  1235. func DelelteAddition(id int64, user_org_id int64) (err error) {
  1236. 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
  1237. return
  1238. }
  1239. func GetNewHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64, sch_type int64) (patients []*VMHisHospitalPrescriptionInfo, err error, total int64) {
  1240. offset := (page - 1) * limit
  1241. 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)
  1242. if len(keywords) > 0 {
  1243. keywords = "%" + keywords + "%"
  1244. db = db.Joins("JOIN xt_patients On his_prescription_info.patient_id = xt_patients.id AND xt_patients.name like ?", keywords)
  1245. }
  1246. if sch_type > 0 {
  1247. 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)
  1248. }
  1249. db = db.Preload("Patients", "xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1250. db = db.Preload("HisPrescription", "his_prescription.user_org_id = ? AND his_prescription.status = 1 AND his_prescription.p_type <> 1", org_id)
  1251. db = db.Count(&total)
  1252. err = db.Limit(limit).Offset(offset).Group("his_prescription_info.id").Find(&patients).Error
  1253. return
  1254. }
  1255. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMSchedule, err error, total int64) {
  1256. offset := (page - 1) * limit
  1257. db := readDb.Model(&VMSchedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  1258. if len(keywords) > 0 {
  1259. keywords = "%" + keywords + "%"
  1260. 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)
  1261. 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)
  1262. }
  1263. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  1264. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  1265. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id).
  1266. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id)
  1267. db = db.Count(&total)
  1268. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  1269. return
  1270. }
  1271. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  1272. patient := models.VMHisPatient{}
  1273. 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
  1274. return patient, err
  1275. }
  1276. type VMOtherHisPrescriptionInfo struct {
  1277. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1278. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1279. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1280. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1281. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1282. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  1283. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1284. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1285. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  1286. }
  1287. func (VMOtherHisPrescriptionInfo) TableName() string {
  1288. return "his_prescription_info"
  1289. }
  1290. type VMHisPrescription struct {
  1291. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1292. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1293. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1294. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1295. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1296. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1297. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1298. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1299. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1300. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  1301. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1302. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1303. }
  1304. func (VMHisPrescription) TableName() string {
  1305. return "his_prescription"
  1306. }
  1307. func GetHisPrescriptionByType(change_type int64, record_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1308. if change_type == 1 { //根据日期取出上一方数据
  1309. var Id AdviceDate
  1310. 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
  1311. 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).
  1312. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1313. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1314. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1315. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1316. }).
  1317. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1318. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1319. })
  1320. }).Find(&advice).Error
  1321. } else if change_type == 2 {
  1322. var Id AdviceDate
  1323. 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
  1324. 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).
  1325. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1326. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1327. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1328. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1329. }).
  1330. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1331. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1332. })
  1333. }).Find(&advice).Error
  1334. }
  1335. return
  1336. }
  1337. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1338. 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).
  1339. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1340. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1341. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1342. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1343. }).
  1344. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1345. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1346. })
  1347. }).Order("record_date desc").Find(&advice).Error
  1348. return
  1349. }
  1350. func GetMobileCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1351. 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).
  1352. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1353. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1354. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1355. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1356. }).
  1357. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1358. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1359. })
  1360. }).Find(&advice).Error
  1361. return
  1362. }
  1363. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1364. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1365. return
  1366. }
  1367. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  1368. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1369. return
  1370. }
  1371. func GetHisOrderByIDTX(order_id int64, tx *gorm.DB) (order models.HisOrder, err error) {
  1372. err = tx.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1373. return
  1374. }
  1375. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1376. err = readDb.Model(&models.HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1377. return
  1378. }
  1379. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  1380. 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
  1381. return
  1382. }
  1383. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  1384. 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
  1385. return
  1386. }
  1387. func GetHisDoctorAdvicesById(id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1388. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND id = ?", id).First(&advice).Error
  1389. return
  1390. }
  1391. func GetAdditionChargeByID(org_id int64, id int64) (addition models.XtHisAddtionConfig, err error) {
  1392. err = readDb.Model(&models.XtHisAddtionConfig{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&addition).Error
  1393. return
  1394. }
  1395. func GetHisPrescriptionByID(org_id int64, id int64) (pre models.HisPrescription, err error) {
  1396. err = readDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&pre).Error
  1397. return
  1398. }
  1399. func GetHisProjectByID(id int64) (project models.HisPrescriptionProject, err error) {
  1400. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id = ?", id).First(&project).Error
  1401. return
  1402. }
  1403. func GetHisAdditionByID(id int64) (addition models.HisAdditionalCharge, err error) {
  1404. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND id = ?", id).First(&addition).Error
  1405. return
  1406. }
  1407. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1408. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  1409. return
  1410. }
  1411. func GetPatientByIDCardAndName(id_card_no string, user_org_id int64, name string) (patient Patients, err error) {
  1412. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ? AND name = ?", id_card_no, user_org_id, name).First(&patient).Error
  1413. return
  1414. }
  1415. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1416. 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
  1417. return
  1418. }
  1419. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1420. var patient Patients
  1421. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1422. return patient, err
  1423. }
  1424. func GetPatientByIDTenTwo(orgID int64, patientID int64) (models.PatientTwos, error) {
  1425. var patient models.PatientTwos
  1426. err := readDb.Model(&models.PatientTwos{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1427. return patient, err
  1428. }
  1429. func GetHisPrescriptionByPatientID(patientID int64, orgID int64) (info models.HisPrescriptionInfo, err error) {
  1430. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND patient_id = ? AND status = 1", orgID, patientID).Preload("XtHisDepartment", "status = 1").Last(&info).Error
  1431. return
  1432. }
  1433. type VMHisProjectTeam struct {
  1434. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1435. ProjectTeam string `gorm:"column:project_team" json:"project_team" form:"project_team"`
  1436. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1437. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  1438. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  1439. TubeColor int64 `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
  1440. TeamType int64 `gorm:"column:team_type" json:"team_type" form:"team_type"`
  1441. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1442. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1443. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1444. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1445. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1446. ProjectId string `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1447. VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
  1448. ItemId string `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1449. }
  1450. func (VMHisProjectTeam) TableName() string {
  1451. return "xt_his_project_team"
  1452. }
  1453. type VMHisProject struct {
  1454. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1455. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1456. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1457. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1458. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  1459. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  1460. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1461. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1462. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1463. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1464. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1465. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  1466. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  1467. }
  1468. func (VMHisProject) TableName() string {
  1469. return "xt_his_project"
  1470. }
  1471. type VMItemProjectList struct {
  1472. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1473. Number int64 `gorm:"column:number" json:"number" form:"number"`
  1474. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1475. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1476. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1477. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1478. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1479. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1480. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1481. VMHisProject VMHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1482. GoodInfo GoodInfo `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"good_info"`
  1483. }
  1484. func (VMItemProjectList) TableName() string {
  1485. return "xt_his_project_list"
  1486. }
  1487. type VMHisPrescriptionTwo struct {
  1488. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1489. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1490. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1491. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1492. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1493. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1494. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1495. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1496. }
  1497. func (VMHisPrescriptionTwo) TableName() string {
  1498. return "his_prescription"
  1499. }
  1500. func GetAllProjectTeamList(orgid int64) (project []*VMHisProjectTeam, err error) {
  1501. err = XTReadDB().Model(&VMHisProjectTeam{}).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1502. for _, item := range project {
  1503. var project_item []*VMItemProjectList
  1504. ids := strings.Split(item.ItemId, ",")
  1505. 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)
  1506. item.VMItemProjectList = append(item.VMItemProjectList, project_item...)
  1507. }
  1508. return
  1509. }
  1510. type HisDoctorAdviceInfo struct {
  1511. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1512. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1513. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1514. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  1515. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  1516. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  1517. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1518. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  1519. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1520. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1521. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1522. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1523. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1524. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1525. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1526. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1527. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  1528. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1529. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1530. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  1531. Drug Drug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
  1532. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1533. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1534. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1535. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  1536. }
  1537. func (HisDoctorAdviceInfo) TableName() string {
  1538. return "his_doctor_advice_info"
  1539. }
  1540. type HisPrescriptionProject struct {
  1541. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1542. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1543. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1544. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1545. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1546. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1547. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1548. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1549. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1550. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1551. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1552. Count string `gorm:"column:count" json:"count" form:"count"`
  1553. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1554. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  1555. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1556. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1557. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1558. Day string `gorm:"column:day" json:"day" form:"day"`
  1559. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1560. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  1561. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1562. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1563. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1564. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1565. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1566. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1567. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1568. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1569. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1570. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1571. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1572. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1573. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1574. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  1575. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  1576. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  1577. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1578. }
  1579. func (HisPrescriptionProject) TableName() string {
  1580. return "his_prescription_project"
  1581. }
  1582. type HisOrderInfo struct {
  1583. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1584. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  1585. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  1586. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  1587. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  1588. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  1589. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  1590. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1591. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  1592. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1593. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1594. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  1595. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  1596. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1597. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1598. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1599. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1600. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1601. HisDoctorAdviceInfo HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  1602. }
  1603. func (HisOrderInfo) TableName() string {
  1604. return "his_order_info"
  1605. }
  1606. func GetHisOrderDetailByNumber(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
  1607. err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1608. 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)
  1609. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1610. 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)
  1611. }).Find(&order).Error
  1612. return
  1613. }
  1614. //func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1615. // db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1616. // return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  1617. // })
  1618. // err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  1619. // return
  1620. //}
  1621. func GetHisOrderInfoByNumberOne(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1622. db := readDb.Model(&models.HisOrderInfoTwo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1623. return db.Preload("Drug", "status = 1").Where("status = 1")
  1624. })
  1625. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  1626. return
  1627. }
  1628. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1629. db := readDb.Model(&models.HisOrderInfoTwo{})
  1630. db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  1631. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1632. return db.Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  1633. })
  1634. 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
  1635. return
  1636. }
  1637. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfoTwo, err error) {
  1638. db := readDb.Model(&models.HisOrderInfoTwo{})
  1639. db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  1640. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1641. return db.Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  1642. })
  1643. 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
  1644. return
  1645. }
  1646. type MedicalInsuranceCostCompare struct {
  1647. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1648. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1649. EndTime int64 `gorm:"column:end_time" json:"end_time" form:"end_time"`
  1650. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1651. CheckType int64 `gorm:"column:check_type" json:"check_type" form:"check_type"`
  1652. Num int64 `gorm:"column:num" json:"num" form:"num"`
  1653. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1654. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1655. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1656. CostTotal float64 `gorm:"column:cost_total" json:"cost_total" form:"cost_total"`
  1657. FuncTotal float64 `gorm:"column:func_total" json:"func_total" form:"func_total"`
  1658. PsnPay float64 `gorm:"column:psn_pay" json:"psn_pay" form:"psn_pay"`
  1659. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1660. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1661. ClrType string `gorm:"column:clr_type" json:"clr_type" form:"clr_type"`
  1662. }
  1663. func (MedicalInsuranceCostCompare) TableName() string {
  1664. return "medical_insurance_cost_compare"
  1665. }
  1666. func GetMedicalInsuranceCostCompareList(orgID, page, limit int64, keywords string, insutype string, start_time int64, end_time int64) (list []*MedicalInsuranceCostCompare, total int, err error) {
  1667. offset := (page - 1) * limit
  1668. db := readDb.Model(&MedicalInsuranceCostCompare{}).Where("medical_insurance_cost_compare.user_org_id = ?", orgID)
  1669. if len(keywords) == 0 {
  1670. db = db.Where("status=1")
  1671. if len(insutype) != 0 {
  1672. db = db.Where("insutype = ?", insutype)
  1673. }
  1674. if start_time != 0 {
  1675. db = db.Where("ctime >= ? ", start_time)
  1676. }
  1677. if end_time != 0 {
  1678. db = db.Where("ctime <= ? ", end_time)
  1679. }
  1680. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1681. } else {
  1682. keywords = "%" + keywords + "%"
  1683. 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)
  1684. db = db.Where("medical_insurance_cost_compare.status=1 ")
  1685. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1686. }
  1687. return
  1688. }
  1689. type TempPatients struct {
  1690. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1691. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1692. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  1693. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  1694. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  1695. Name string `gorm:"column:name" json:"name" form:"name"`
  1696. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1697. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  1698. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  1699. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  1700. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1701. GdybPsnNcdsRecord GdybPsnNcdsRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"record"`
  1702. }
  1703. func (TempPatients) TableName() string {
  1704. return "xt_patients"
  1705. }
  1706. type GdybPsnNcdsRecord struct {
  1707. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1708. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1709. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1710. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1711. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1712. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1713. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1714. IsCancel int64 `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
  1715. TrtDclaDetlSn string `gorm:"column:trt_dcla_detl_sn" json:"trt_dcla_detl_sn" form:"trt_dcla_detl_sn"`
  1716. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1717. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1718. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1719. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1720. OrgName string `gorm:"column:org_name" json:"org_name" form:"org_name"`
  1721. }
  1722. func (GdybPsnNcdsRecord) TableName() string {
  1723. return "gdyb_psn_ncds_record"
  1724. }
  1725. func GetGdybPsnNcdsRecordList(orgID, page, limit int64, keywords string, is_cancel int64) (list []*TempPatients, total int64, err error) {
  1726. offset := (page - 1) * limit
  1727. db := readDb.Model(&TempPatients{})
  1728. db = db.Preload("GdybPsnNcdsRecord", func(db *gorm.DB) *gorm.DB {
  1729. return db.Model(&GdybPsnNcdsRecord{}).Where("user_org_id = ?", orgID).Order("id asc")
  1730. })
  1731. fmt.Println(is_cancel)
  1732. if len(keywords) == 0 {
  1733. if is_cancel == 1 {
  1734. 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)
  1735. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1736. } else if is_cancel == 0 {
  1737. db = db.Preload("GdybPsnNcdsRecord", "user_org_id = ?", orgID)
  1738. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1739. } else if is_cancel == 2 {
  1740. 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)")
  1741. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1742. }
  1743. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1744. } else {
  1745. keywords = "%" + keywords + "%"
  1746. 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)
  1747. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1748. }
  1749. return
  1750. }
  1751. type CustomAccountFormData struct {
  1752. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1753. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1754. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1755. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1756. MdtrtiId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  1757. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1758. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  1759. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1760. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1761. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1762. CashPay float64 `gorm:"column:cash_pay" json:"cash_pay" form:"cash_pay"`
  1763. HifpPay float64 `gorm:"column:hifp_pay" json:"hifp_pay" form:"hifp_pay"`
  1764. Sumamt float64 `gorm:"column:sumamt" json:"sumamt" form:"sumamt"`
  1765. Iinfo string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
  1766. DiagnosisId string `gorm:"column:diagnosis_id" json:"diagnosis_id" form:"diagnosis_id"`
  1767. DialysisCount int64 `gorm:"-"`
  1768. PatientId int64 `gorm:"column:patient_id" json:"dialysis_count" form:"dialysis_count"`
  1769. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1770. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1771. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1772. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1773. MayPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1774. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1775. }
  1776. func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (cus []*CustomAccountFormData, err error) {
  1777. if clr_type == "9903" {
  1778. 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 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
  1779. } else {
  1780. 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 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
  1781. }
  1782. for _, item := range cus {
  1783. var total int64
  1784. readDb.Model(&models.DialysisOrder{}).Where("patient_id = ? AND status = 1 AND stage = 2 AND dialysis_date <= ? AND dialysis_date >= ?", item.PatientId, end_time, start_time).Count(&total)
  1785. fmt.Println(total)
  1786. item.DialysisCount = total
  1787. fmt.Println(item.DialysisCount)
  1788. }
  1789. return
  1790. }
  1791. func GetNewHisPatientInfo(his_patient_id int64) (info models.HisPatient, err error) {
  1792. err = readDb.Model(&models.HisPatient{}).Where("id = ? AND status = 1 ", his_patient_id).First(&info).Error
  1793. return
  1794. }
  1795. func GetNewHisOrder(user_org_id int64, mdtrt_id string, patient_id int64) (order models.HisOrder, err error) {
  1796. 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).
  1797. Last(&order).Error
  1798. return
  1799. }
  1800. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1801. 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).
  1802. Order("ctime desc").
  1803. Find(&order).Error
  1804. return
  1805. }
  1806. type NewCustomPatients struct {
  1807. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1808. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1809. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1810. Number string `gorm:"column:number" json:"number" form:"number"`
  1811. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1812. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1813. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,Number" json:"order"`
  1814. }
  1815. func (NewCustomPatients) TableName() string {
  1816. return "his_patients"
  1817. }
  1818. type NewSZCustomPatients struct {
  1819. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1820. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1821. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1822. Number string `gorm:"column:number" json:"number" form:"number"`
  1823. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1824. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1825. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,MzNumber" json:"order"`
  1826. }
  1827. func (NewSZCustomPatients) TableName() string {
  1828. return "his_patients"
  1829. }
  1830. //
  1831. //func GetNewAllChargeHisPatientList(org_id int64, record_date int64) (patients []*NewSZCustomPatients, err error) {
  1832. // var tempPatients []*NewSZCustomPatients
  1833. // db := readDb.Model(&NewSZCustomPatients{}).Where("his_patients.user_org_id = ? AND his_patients.status = 1", org_id)
  1834. // db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  1835. // return tempPatients, err
  1836. //}
  1837. type NewTempPatients struct {
  1838. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1839. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1840. Name string `gorm:"column:name" json:"name" form:"name"`
  1841. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1842. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1843. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  1844. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  1845. HisPatient []*HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  1846. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  1847. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  1848. }
  1849. func (NewTempPatients) TableName() string {
  1850. return "xt_patients"
  1851. }
  1852. //"VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date
  1853. func GetNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*NewTempPatients, err error) {
  1854. db := readDb.Model(&NewTempPatients{})
  1855. //if sch_type > 0 {
  1856. // db = db.Joins("join xt_schedule as sch on sch.patient_id = xt_patients.id and sch.schedule_date = ? and sch.schedule_type = ?", record_date, sch_type)
  1857. //}
  1858. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1859. db = db.Preload("Schedule", "status = 1")
  1860. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1861. 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)
  1862. })
  1863. 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)
  1864. 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
  1865. for _, item := range patients {
  1866. for _, sumItem := range item.HisPatient {
  1867. if len(sumItem.VMHisOrders) > 0 {
  1868. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1869. }
  1870. }
  1871. }
  1872. return
  1873. }
  1874. func GetNewAllChargeHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*NewTempPatients, err error) {
  1875. db := readDb.Model(&NewTempPatients{})
  1876. //if sch_type > 0 {
  1877. // db = db.Joins("join xt_schedule as sch on sch.patient_id = xt_patients.id and sch.schedule_date = ? and sch.schedule_type = ?", record_date, sch_type)
  1878. //}
  1879. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1880. db = db.Preload("Schedule", "status = 1")
  1881. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1882. 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)
  1883. })
  1884. 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)
  1885. 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
  1886. for _, item := range patients {
  1887. for _, sumItem := range item.HisPatient {
  1888. if len(sumItem.VMHisOrders) > 0 {
  1889. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1890. }
  1891. }
  1892. }
  1893. return
  1894. }
  1895. func GetPrescriptionById(id int64, org_id int64) (prescription models.HisPrescription, err error) {
  1896. err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND user_org_id = ? AND status = 1", id, org_id).First(&prescription).Error
  1897. return
  1898. }
  1899. type CustomInComeStatistics struct {
  1900. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1901. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  1902. SettleAccountsDate string `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1903. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1904. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1905. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1906. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1907. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1908. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1909. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1910. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1911. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  1912. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  1913. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1914. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1915. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1916. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1917. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1918. }
  1919. func (CustomInComeStatistics) TableName() string {
  1920. return "his_order"
  1921. }
  1922. func GetDayIncomeStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (order []*CustomInComeStatistics, total int64, err error) {
  1923. offset := (page - 1) * limit
  1924. if len(keywords) != 0 {
  1925. 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
  1926. } else {
  1927. if start_time != 0 && end_time != 0 {
  1928. 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
  1929. } else {
  1930. 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
  1931. }
  1932. }
  1933. return
  1934. }
  1935. func GetDayIncomeDetailStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (cis []*CustomInComeStatistics, total int64, err error) {
  1936. offset := (page - 1) * limit
  1937. if len(keywords) != 0 {
  1938. 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
  1939. } else {
  1940. if start_time != 0 && end_time != 0 {
  1941. 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
  1942. } else {
  1943. 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
  1944. }
  1945. }
  1946. return
  1947. }
  1948. //func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1949. // 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
  1950. // return
  1951. //}
  1952. func CreateHisPrescriptionTemplate(template *models.HisPrescriptionTemplate) (err error) {
  1953. err = writeDb.Create(&template).Error
  1954. return
  1955. }
  1956. func CreateHisPrescriptionAdviceTemplate(s *models.HisPrescriptionAdviceTemplate) (err error) {
  1957. err = writeDb.Save(&s).Error
  1958. return
  1959. }
  1960. func CreateHisPrescriptionInfoTemplate(s *models.HisPrescriptionInfoTemplate) (err error) {
  1961. err = writeDb.Save(&s).Error
  1962. return
  1963. }
  1964. func CreateHisPrescriptionProjectTemplate(project *models.HisPrescriptionProjectTemplate) (err error) {
  1965. err = writeDb.Save(&project).Error
  1966. return
  1967. }
  1968. func GetPatientSch(patient_id int64, sch_date int64, org_id int64) (sch models.Schedule, err error) {
  1969. 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
  1970. return
  1971. }
  1972. func GetHisPrescriptionBySchMode(mode_id int64, patient_id int64, org_id int64) (prescription models.HisPrescriptionTemplate, err error) {
  1973. 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
  1974. return
  1975. }
  1976. func GetHisPrescriptionTemplate(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplate, err error) {
  1977. err = readDb.Model(&models.HisPrescriptionInfoTemplate{}).
  1978. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  1979. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1980. }).
  1981. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  1982. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  1983. }).
  1984. Where("status = 1 AND p_template_id = ? ", template_id).
  1985. Find(&prescription).Error
  1986. return
  1987. }
  1988. // 组
  1989. func GetHisPrescriptionTemplateL(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplateL, err error) {
  1990. err = readDb.Model(&models.HisPrescriptionInfoTemplateL{}).
  1991. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  1992. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1993. }).
  1994. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  1995. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  1996. }).
  1997. Where("status = 1 AND p_template_id = ? ", template_id).
  1998. Find(&prescription).Error
  1999. return
  2000. }
  2001. func FindHisConsumablesByID(orgID int64, patient_id int64, recordDate int64, good_id int64) (consumables models.DialysisBeforePrepare, err error) {
  2002. 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
  2003. return
  2004. }
  2005. func UpdateConsumables(consumables *models.DialysisBeforePrepare) (err error) {
  2006. err = writeDb.Save(&consumables).Error
  2007. return
  2008. }
  2009. func GetHisPrescriptionProjectsByID(id int64) (projects []*models.HisPrescriptionProject, err error) {
  2010. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("prescription_id = ? AND status = 1", id).Find(&projects).Error
  2011. return
  2012. }
  2013. func GetHisPrescriptionProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  2014. 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
  2015. return
  2016. }
  2017. func GetHisPrescriptionTeamProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  2018. 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
  2019. return
  2020. }
  2021. func GetHisPrescriptionProjectByID(id int64) (projects models.HisPrescriptionProject, err error) {
  2022. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  2023. return
  2024. }
  2025. func GetHisPrescriptionAdviceByID(id int64) (advices []*models.HisDoctorAdviceInfo, err error) {
  2026. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
  2027. return
  2028. }
  2029. func UpdateGoodInfo(good_info *models.GoodInfo) (err error) {
  2030. err = writeDb.Save(&good_info).Error
  2031. return
  2032. }
  2033. func GetUnChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  2034. err = readDb.Model(&models.HisPrescription{}).
  2035. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2036. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2037. }).
  2038. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2039. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2040. }).
  2041. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2042. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2043. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2044. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2045. }).
  2046. 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).
  2047. Find(&prescription).Error
  2048. return
  2049. }
  2050. func GetChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  2051. err = readDb.Model(&models.HisPrescription{}).
  2052. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2053. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2054. }).
  2055. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2056. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2057. }).
  2058. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2059. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2060. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2061. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2062. }).
  2063. 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).
  2064. Find(&prescription).Error
  2065. return
  2066. }
  2067. func GetChargeHisPrescriptionSeven(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  2068. err = readDb.Model(&models.HisPrescription{}).
  2069. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2070. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2071. }).
  2072. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2073. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("Drug", "status=1")
  2074. }).
  2075. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2076. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject").Preload("GoodInfo", "status=1")
  2077. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2078. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2079. }).
  2080. 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).
  2081. Find(&prescription).Error
  2082. return
  2083. }
  2084. // 已收费
  2085. func GetChargeMonthHisPrescriptionFive(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  2086. err = readDb.Model(&models.HisPrescription{}).
  2087. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2088. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2089. }).
  2090. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2091. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2092. }).
  2093. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2094. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2095. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2096. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2097. }).
  2098. 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).
  2099. Find(&prescription).Error
  2100. return
  2101. }
  2102. func UpdataHisPateint(his *models.HisPatient) {
  2103. writeDb.Save(&his)
  2104. }
  2105. func UpdataHisPateintTX(his *models.HisPatient, tx *gorm.DB) {
  2106. tx.Save(&his)
  2107. }
  2108. func SaveHisOrder(his *models.HisOrder) (err error) {
  2109. err = writeDb.Save(&his).Error
  2110. return
  2111. }
  2112. func UpdataHisPateintTwo(his *models.VMHisPatient) {
  2113. writeDb.Save(&his)
  2114. }
  2115. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  2116. err = readDb.Model(&models.HisPrescription{}).
  2117. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2118. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2119. }).
  2120. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2121. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2122. }).
  2123. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2124. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2125. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  2126. return db.Where("status = 1 AND user_org_id = ?", org_id)
  2127. }).
  2128. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2129. Find(&prescription).Error
  2130. return
  2131. }
  2132. func GetPrescriptionByIdsTX(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  2133. err = tx.Model(&models.HisPrescription{}).
  2134. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  2135. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2136. }).
  2137. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  2138. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2139. }).
  2140. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  2141. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  2142. }).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
  2143. return tx.Where("status = 1 AND user_org_id = ?", org_id)
  2144. }).
  2145. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2146. Find(&prescription).Error
  2147. return
  2148. }
  2149. func GetPrescriptionByIdsTxOne(ids []string, org_id int64, tx *gorm.DB) (prescription []*models.HisPrescription, err error) {
  2150. err = tx.Model(&models.HisPrescription{}).
  2151. Preload("HisAdditionalCharge", func(tx *gorm.DB) *gorm.DB {
  2152. return tx.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2153. }).
  2154. Preload("HisDoctorAdviceInfo", func(tx *gorm.DB) *gorm.DB {
  2155. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("drug_id").Preload("Drug", "status=1")
  2156. }).
  2157. Preload("HisPrescriptionProject", func(tx *gorm.DB) *gorm.DB {
  2158. return tx.Where("status = 1 AND user_org_id = ?", org_id).Group("project_id").Preload("HisProject").Preload("GoodInfo", "status=1")
  2159. }).Preload("TempHisOrder", func(tx *gorm.DB) *gorm.DB {
  2160. return tx.Where("status = 1 AND user_org_id = ?", org_id)
  2161. }).
  2162. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  2163. Find(&prescription).Error
  2164. return
  2165. }
  2166. func GetNewAllUnChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  2167. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2168. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2169. 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)
  2170. })
  2171. 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)
  2172. 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
  2173. for _, item := range patients {
  2174. for _, sumItem := range item.HisPatient {
  2175. if len(sumItem.VMHisOrders) > 0 {
  2176. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2177. }
  2178. }
  2179. }
  2180. return
  2181. }
  2182. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  2183. 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
  2184. return
  2185. }
  2186. func GetNewHisOrderList(org_id int64) (order []*models.NewHisOrder, err error) {
  2187. 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
  2188. var numbers []string
  2189. for _, item := range order {
  2190. numbers = append(numbers, item.Number)
  2191. }
  2192. return
  2193. }
  2194. func GetNewHisOrderInfoList(order_numbers []string) (order []*models.VMHisOrderInfo, err error) {
  2195. err = readDb.Model(&models.VMHisOrderInfo{}).Where("status = 1 AND order_number in (?)", order_numbers).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2196. return db.Where("status = 1 ").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1")
  2197. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2198. return db.Where("status = 1 ").Preload("Drug", "status =1")
  2199. }).Find(&order).Error
  2200. return
  2201. }
  2202. func FindAllHisDoctorAdviceByTime(now int64, end int64, patient_id int64, orgId int64, drug_id int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  2203. 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
  2204. return
  2205. }
  2206. func FindAllHisProjectByTime(now int64, end int64, patient_id int64, orgId int64, project_id int64) (project []*models.HisPrescriptionProject, err error) {
  2207. 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
  2208. return
  2209. }
  2210. func GetProjectByTeamId(user_org_id int64, team_id int64, patient_id int64, record_time int64) (label models.HisLabelPrintInfo, err error) {
  2211. 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
  2212. return
  2213. }
  2214. func GetProjectById(user_org_id int64, p_project_id int64, record_time int64, patient_id int64) (label models.HisLabelPrintInfo, err error) {
  2215. 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
  2216. return
  2217. }
  2218. func DeletePrintInfo(id int64) {
  2219. writeDb.Model(&models.HisLabelPrintInfo{}).Where("p_project_id = ?", id).Updates(map[string]interface{}{"status": 0})
  2220. }
  2221. func CreateHisLabelRecord(label *models.HisLabelPrintInfo) error {
  2222. err := writeDb.Save(&label).Error
  2223. return err
  2224. }
  2225. func DeletePsnNCDSRecordById(id int64) (err error) {
  2226. err = writeDb.Model(&models.GdybPsnNcdsRecord{}).Where("id = ?", id).Updates(map[string]interface{}{"user_org_id": 1110000}).Error
  2227. return
  2228. }
  2229. func GetBaiLinOrderData() (order []*models.NewCustomHisOrder) {
  2230. readDb.Model(&models.NewCustomHisOrder{}).Preload("Patients", "status = 1").Preload("NewCustomHisOrderInfo", func(db *gorm.DB) *gorm.DB {
  2231. 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)")
  2232. }).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)
  2233. return
  2234. }
  2235. func GetHisDoctorAdviceInfo(id int64) (models.HisDoctorAdviceInfo, error) {
  2236. info := models.HisDoctorAdviceInfo{}
  2237. err := readDb.Model(&info).Where("id = ? and status = 1", id).Preload("Drug", "status = 1").Find(&info).Error
  2238. return info, err
  2239. }
  2240. func UpdateBatchHisPrescriptionMedType(ids []string, med_type string, start_time int64, end_time int64, user_org_id int64, old_med_type string) (err error) {
  2241. tx := writeDb.Begin()
  2242. 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 {
  2243. tx.Rollback()
  2244. return
  2245. }
  2246. tx.Commit()
  2247. return
  2248. }
  2249. func GetWarehoseInfoByDrugId(drug_id int64, org_id int64) (info OtherDrugWarehouseInfo, err error) {
  2250. 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
  2251. return
  2252. }
  2253. func GetGoodWarehoseInfoByGoodId(good_id int64, org_id int64) (info models.GoodSotckInfo, err error) {
  2254. 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
  2255. return
  2256. }
  2257. type MonthChargePatients struct {
  2258. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2259. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2260. Name string `gorm:"column:name" json:"name" form:"name"`
  2261. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2262. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2263. Number string `gorm:"column:number" json:"number" form:"number"`
  2264. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  2265. }
  2266. func (MonthChargePatients) TableName() string {
  2267. return "his_patient"
  2268. }
  2269. func GetMonthUnChargeHisPatientList(org_id int64, record_date int64, start_time int64, end_time int64) (patients []*MonthChargePatients, err error) {
  2270. db := readDb.Model(&MonthChargePatients{}).Where("his_patient.user_org_id = ? AND his_patient.status = 1 AND his_patient.record_date = ?", org_id, record_date)
  2271. 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)
  2272. return
  2273. }
  2274. func UpdataOrderStatusThree(number string, user_org_id int64) (err error) {
  2275. 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
  2276. 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
  2277. return
  2278. }
  2279. func UpDateOrderTwo(order *models.HisOrder, tx *gorm.DB) (err error) {
  2280. err = tx.Save(&order).Error
  2281. return
  2282. }
  2283. type HisOrderInfoTen struct {
  2284. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2285. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  2286. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  2287. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  2288. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  2289. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  2290. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  2291. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2292. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  2293. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2294. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  2295. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  2296. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  2297. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2298. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2299. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  2300. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  2301. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  2302. HisDoctorAdviceInfo models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  2303. }
  2304. func (HisOrderInfoTen) TableName() string {
  2305. return "his_order_info"
  2306. }
  2307. func GetHisOrderDetailByNumberTen(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
  2308. err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2309. 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)
  2310. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2311. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2312. }).Find(&order).Error
  2313. return
  2314. }
  2315. func GetHisOrderDetailByNumberEleven(order_number string, org_id int64) (order []*HisOrderInfoTen, err error) {
  2316. err = readDb.Model(&HisOrderInfoTen{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2317. 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)
  2318. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2319. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2320. }).Find(&order).Error
  2321. return
  2322. }
  2323. func GetHisOrderByIDTen(order_id int64) (order models.HisOrder, err error) {
  2324. err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
  2325. return
  2326. }
  2327. func GetHisPrescriptonProjectById(id int64) (models.HisPrescriptionProject, error) {
  2328. project := models.HisPrescriptionProject{}
  2329. err := XTReadDB().Where("id = ? and status = 1", id).Find(&project).Error
  2330. return project, err
  2331. }
  2332. type HisOrderInfoTwo struct {
  2333. ID int64 `gorm:"column:id" json:"id" form:"id"`
  2334. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  2335. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  2336. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  2337. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  2338. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  2339. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  2340. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  2341. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  2342. Status int64 `gorm:"column:status" json:"status" form:"status"`
  2343. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  2344. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  2345. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  2346. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  2347. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  2348. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  2349. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  2350. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  2351. HisDoctorAdviceInfo models.HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  2352. }
  2353. func (HisOrderInfoTwo) TableName() string {
  2354. return "his_order_info"
  2355. }
  2356. func GetHisOrderDetailByNumberTwo(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
  2357. err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2358. 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)
  2359. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2360. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2361. }).Find(&order).Error
  2362. return
  2363. }
  2364. func GetHisOrderDetailByNumberThree(order_number string, org_id int64) (order []*HisOrderInfoTwo, err error) {
  2365. err = readDb.Model(&HisOrderInfoTwo{}).Where("order_number = ?", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2366. 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)
  2367. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2368. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status = 1 AND org_id = ?", org_id)
  2369. }).Find(&order).Error
  2370. return
  2371. }
  2372. func GetHisOrderByIDThree(order_id int64) (order models.HisOrder, err error) {
  2373. err = readDb.Model(&models.HisOrder{}).Where("id = ?", order_id).First(&order).Error
  2374. return
  2375. }
  2376. func GetDrugSumOutCountByDrugId(drug_id int64, user_org_id int64, storehouse_id int64) (models.XtDrugStockCount, error) {
  2377. drug := models.XtDrugStockCount{}
  2378. 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
  2379. return drug, err
  2380. }
  2381. func GetStockGoodList(good_id int64, org_id int64, storehouse_id int64) (models.XtGoodStockCount, error) {
  2382. stockCount := models.XtGoodStockCount{}
  2383. err = XTReadDB().Where("good_id = ? and user_org_id = ? and status= 1 and storehouse_id = ?", good_id, org_id, storehouse_id).Find(&stockCount).Error
  2384. return stockCount, err
  2385. }
  2386. func GetLastOrderTX(user_org_id int64) (models.HisOrder, error) {
  2387. order := models.HisOrder{}
  2388. err := XTReadDB().Where("user_org_id = ? and status = 1", user_org_id).Last(&order).Error
  2389. return order, err
  2390. }
  2391. func GetPatientPlan(orgid int64) (patient []*models.XtPatients, err error) {
  2392. err = XTReadDB().Where("user_org_id = ? and status= 1", orgid).Find(&patient).Error
  2393. return patient, err
  2394. }
  2395. func UpdatePatienPlan(id int64, trement_plan string) error {
  2396. err := XTWriteDB().Model(&models.XtPatientsNew{}).Where("blood_id = ? and status = 1", id).Update(map[string]interface{}{"treatment_plan": trement_plan}).Error
  2397. return err
  2398. }
  2399. func GetDialysisOrderList(orgid int64) (order []*models.XtDialysisOrder, err error) {
  2400. err = XTReadDB().Where("user_org_id = ? and status= 1 and url<>''", orgid).Group("patient_id").Find(&order).Error
  2401. return order, err
  2402. }
  2403. func UpdatePatientDialysisOrder(patient_id int64, url string) error {
  2404. err := XTWriteDB().Model(&models.XtPatients{}).Where("id =? and status=1", patient_id).Updates(map[string]interface{}{"url": url}).Error
  2405. return err
  2406. }
  2407. func GetHisOrderByIDTenOne(order_id string) (order models.HisOrder, err error) {
  2408. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  2409. return
  2410. }
  2411. func GetHisDoctorAdviceInfotwo(id int64) (models.HisDoctorAdviceInfo, error) {
  2412. info := models.HisDoctorAdviceInfo{}
  2413. err := readDb.Model(&info).Where("id = ? and status = 1", id).Find(&info).Error
  2414. return info, err
  2415. }
  2416. func GetHisDoctorAdviceInfothree(org_id int64, record_date int64) (info []*models.HisDoctorAdviceInfo, err error) {
  2417. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("user_org_id = ? and status = 1 and record_date = ?", org_id, record_date).Find(&info).Error
  2418. return
  2419. }
  2420. func GetHisPrescriptionProjectByIDFour(org_id int64, record_date int64) (projects []*models.HisPrescriptionProject, err error) {
  2421. err = readDb.Model(&models.HisPrescriptionProject{}).Where("user_org_id = ? and status = 1 and record_date = ?", org_id, record_date).Find(&projects).Error
  2422. return
  2423. }
  2424. func GetHisPrescriptionProjectByIDThree(id int64) (projects models.HisPrescriptionProject, err error) {
  2425. err = readDb.Model(&models.HisPrescriptionProject{}).Where("id = ? AND status = 1", id).First(&projects).Error
  2426. return
  2427. }
  2428. func GetHisPrescriptionProjectByIDTwoone(id int64) (projects models.HisPrescriptionProject, err error) {
  2429. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Preload("HisProject", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  2430. return
  2431. }
  2432. func GetMonthNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64, start_date int64, end_date int64) (patients []NewTempPatients, err error) {
  2433. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  2434. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  2435. 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)
  2436. })
  2437. 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)
  2438. 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
  2439. for _, item := range patients {
  2440. for _, sumItem := range item.HisPatient {
  2441. if len(sumItem.VMHisOrders) > 0 {
  2442. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  2443. }
  2444. }
  2445. }
  2446. return
  2447. }
  2448. func GetChargeHisPatientList(org_id int64, record_date int64) (order []*HisOrder, err error) {
  2449. 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
  2450. return
  2451. }
  2452. func GetGoodByIdIsStop(good_id int64, org_id int64) (models.GoodInfoSeven, error) {
  2453. goodInfoSeven := models.GoodInfoSeven{}
  2454. err = XTReadDB().Where("org_id = ? and status = 1 and find_in_set('停用',good_status) = 0 and id =?", org_id, good_id).Find(&goodInfoSeven).Error
  2455. return goodInfoSeven, err
  2456. }
  2457. func GetHisPrescriptionByBatchNumber(org_id int64, number string) (prescription []*models.HisPrescription, err error) {
  2458. err = readDb.Model(&models.HisPrescription{}).
  2459. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  2460. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  2461. }).
  2462. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  2463. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  2464. }).
  2465. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  2466. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1").Preload("XtHisProjectTeam", "status = 1")
  2467. }).
  2468. Where("user_org_id = ? AND status = 1 AND batch_number = ?", org_id, number).
  2469. Find(&prescription).Error
  2470. return
  2471. }
  2472. func GetLastHisOrderThree(org_id int64) (err error, o models.HisOrder) {
  2473. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? and status = 1 and order_status = 2", org_id).First(&o).Error
  2474. return
  2475. }
  2476. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  2477. 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
  2478. return
  2479. }