his_service.go 163KB

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