his_service.go 154KB

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