his_service.go 123KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037
  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:PatientId,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 int64 `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. }
  104. func (VMHisOrder) TableName() string {
  105. return "his_order"
  106. }
  107. type Patients struct {
  108. ID int64 `gorm:"column:id" json:"id" form:"id"`
  109. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  110. Name string `gorm:"column:name" json:"name" form:"name"`
  111. Status int64 `gorm:"column:status" json:"status" form:"status"`
  112. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  113. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  114. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  115. HisPatient HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  116. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  117. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  118. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"order"`
  119. }
  120. func (Patients) TableName() string {
  121. return "xt_patients"
  122. }
  123. type HisPrescription struct {
  124. ID int64 `gorm:"column:id" json:"id" form:"id"`
  125. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  126. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  127. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  128. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  129. Status int64 `gorm:"column:status" json:"status" form:"status"`
  130. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  131. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  132. }
  133. func (HisPrescription) TableName() string {
  134. return "his_prescription"
  135. }
  136. func GetScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*Patients, err error) {
  137. 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)
  138. if sch_type != 0 {
  139. 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)
  140. } else {
  141. 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)
  142. }
  143. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  144. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  145. 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
  146. return
  147. }
  148. func GetChargeHisPatientListOne(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  149. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  150. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  151. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  152. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  153. return
  154. }
  155. func GetAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  156. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  157. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  158. db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  159. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  160. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  161. return
  162. }
  163. func GetChargeHisPatientListTwo(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  164. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  165. 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)
  166. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  167. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  168. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Find(&patients).Error
  169. return
  170. }
  171. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Patients, err error) {
  172. db := readDb.Model(&Patients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  173. 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)
  174. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  175. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  176. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  177. return
  178. }
  179. type PatientTwo struct {
  180. ID int64 `gorm:"column:id" json:"id" form:"id"`
  181. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  182. Name string `gorm:"column:name" json:"name" form:"name"`
  183. Status int64 `gorm:"column:status" json:"status" form:"status"`
  184. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  185. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  186. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  187. HisPatient []*HisPatientTwo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  188. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  189. }
  190. func (PatientTwo) TableName() string {
  191. return "xt_patients"
  192. }
  193. type HisPatientTwo struct {
  194. ID int64 `gorm:"column:id" json:"id" form:"id"`
  195. Name string `gorm:"column:name" json:"name" form:"name"`
  196. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  197. Total float64 `gorm:"column:total" json:"total" form:"total"`
  198. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  199. Status int64 `gorm:"column:status" json:"status" form:"status"`
  200. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  201. HisPrescriptionTwo []*HisPrescriptionTwo `gorm:"ForeignKey:PatientId,HisPatientId;AssociationForeignKey:PatientId,ID" json:"prescription"`
  202. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  203. Number string `gorm:"column:number" json:"number" form:"number"`
  204. }
  205. func (HisPatientTwo) TableName() string {
  206. return "his_patient"
  207. }
  208. type HisPrescriptionTwo struct {
  209. ID int64 `gorm:"column:id" json:"id" form:"id"`
  210. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  211. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  212. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  213. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  214. Status int64 `gorm:"column:status" json:"status" form:"status"`
  215. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  216. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  217. Number string `gorm:"column:number" json:"number" form:"number"`
  218. Type int64 `gorm:"column:type" json:"type" form:"type"`
  219. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  220. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  221. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  222. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  223. PreTime int64 `gorm:"column:pre_time" json:"pre_time" form:"pre_time"`
  224. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  225. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  226. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  227. }
  228. func (HisPrescriptionTwo) TableName() string {
  229. return "his_prescription"
  230. }
  231. func GetNewHisPatientList(org_id int64, record_date int64) (patients []*PatientTwo, err error) {
  232. db := readDb.Model(&PatientTwo{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id).
  233. 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)
  234. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  235. 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)
  236. })
  237. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date).Group("id").Find(&patients).Error
  238. return
  239. }
  240. func GetNewScheduleHisPatientList(org_id int64, keywords string, record_date int64, sch_type int64) (patients []*PatientTwo, err error) {
  241. 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)
  242. if sch_type != 0 {
  243. db = db.Joins("join xt_schedule as sch ON sch.patient_id = xt_patients.id AND sch.schedule_date = ? AND sch.status = 1 AND sch.user_org_id = ? AND sch.schedule_type = ?", record_date, org_id, sch_type)
  244. } else {
  245. 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)
  246. }
  247. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1 AND record_date = ?", org_id, record_date)
  248. 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
  249. return
  250. }
  251. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  252. err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
  253. return
  254. }
  255. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  256. 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
  257. return
  258. }
  259. func GetHisPatientInfoTwo(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).Find(&info).Error
  261. return
  262. }
  263. func GetHisPatientInfoList(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 GetNewHisPatientInfoTwo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  268. 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
  269. return
  270. }
  271. func GetHisPatientCount(org_id int64, patient_id int64, record_date int64) (total int64, err error) {
  272. 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
  273. return
  274. }
  275. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  276. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  277. return
  278. }
  279. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  280. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  281. return
  282. }
  283. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  284. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  285. err = db.Find(&caseHistorys).Error
  286. return
  287. }
  288. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  289. likekey := "%" + keyword + "%"
  290. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  291. if startime > 0 {
  292. db = db.Where("record_date>=?", startime)
  293. }
  294. if endtime > 0 {
  295. db = db.Where("record_date<=?", endtime)
  296. }
  297. if len(keyword) > 0 {
  298. db = db.Where("template_name like ? ", likekey)
  299. }
  300. err = db.Find(&caseHistorys).Error
  301. return
  302. }
  303. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  304. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  305. return caseHistory, err
  306. }
  307. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  308. err = writeDb.Create(&template).Error
  309. return
  310. }
  311. func GetHisPatientCaseHistoryById(id int64) (*models.HisPatientCaseHistory, error) {
  312. history := models.HisPatientCaseHistory{}
  313. err := XTReadDB().Model(&history).Where("id = ? and status = 1", id).Find(&history).Error
  314. if err != nil {
  315. if err == gorm.ErrRecordNotFound {
  316. return nil, err
  317. } else {
  318. return nil, err
  319. }
  320. }
  321. return &history, nil
  322. }
  323. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  324. err := writeDb.Create(&caseHistory).Error
  325. return err
  326. }
  327. func UpdatePatientCaseHistory(id int64, his *models.HisPatientCaseHistory) error {
  328. err := XTWriteDB().Model(&his).Where("id = ? and status =1", id).Updates(map[string]interface{}{"temperature": his.Temperature, "blood_sugar": his.BloodSugar, "pulse": his.BloodSugar, "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}).Error
  329. return err
  330. }
  331. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  332. tx := writeDb.Begin()
  333. if err = tx.Model(&models.HisPrescription{}).Save(prescription).Error; err != nil {
  334. tx.Rollback()
  335. return
  336. }
  337. tx.Commit()
  338. return
  339. }
  340. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  341. 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
  342. 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
  343. 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
  344. return
  345. }
  346. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  347. 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
  348. return
  349. }
  350. func DelelteProject(id int64, user_org_id int64) (err error) {
  351. 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
  352. return
  353. }
  354. func GetHisPrescription(org_id int64, patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  355. err = readDb.Model(&models.HisPrescription{}).
  356. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  357. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  358. }).
  359. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  360. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  361. }).
  362. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  363. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  364. }).
  365. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND p_type = ?", org_id, record_date, patient_id, p_type).
  366. Find(&prescription).Error
  367. return
  368. }
  369. func GetNewHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  370. err = readDb.Model(&models.HisPrescription{}).
  371. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  372. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  373. }).
  374. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  375. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  376. }).
  377. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  378. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  379. }).
  380. 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).
  381. Find(&prescription).Error
  382. return
  383. }
  384. func GetChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  385. err = readDb.Model(&models.HisPrescription{}).
  386. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  387. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  388. }).
  389. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  390. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  391. }).
  392. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  393. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  394. }).
  395. 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).
  396. Find(&prescription).Error
  397. return
  398. }
  399. func GetUnChargeHisPrescriptionFive(org_id int64, patient_id int64, his_patient_id int64, record_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  400. err = readDb.Model(&models.HisPrescription{}).
  401. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  402. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  403. }).
  404. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  405. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  406. }).
  407. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  408. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  409. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  410. return db.Where("status = 1 AND user_org_id = ?", org_id)
  411. }).
  412. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND his_patient_id = ? AND order_status <> 2 AND order_status <> 3 AND p_type = ?", org_id, record_date, patient_id, his_patient_id, p_type).
  413. Find(&prescription).Error
  414. return
  415. }
  416. func GetSettleHisPrescription(org_id int64, patient_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  417. err = readDb.Model(&models.HisPrescription{}).
  418. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  419. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  420. }).
  421. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  422. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  423. }).
  424. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  425. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  426. }).
  427. 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).
  428. Find(&prescription).Error
  429. return
  430. }
  431. func GetMonthHisPrescription(org_id int64, patient_id int64, start_date int64, end_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  432. err = readDb.Model(&models.HisPrescription{}).
  433. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  434. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  435. }).
  436. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  437. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  438. }).
  439. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  440. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  441. }).
  442. 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).
  443. Find(&prescription).Error
  444. return
  445. }
  446. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  447. err = readDb.Model(&models.HisPrescription{}).
  448. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  449. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  450. }).
  451. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  452. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  453. }).
  454. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  455. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  456. }).
  457. 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).
  458. Find(&prescription).Error
  459. return
  460. }
  461. func GetMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  462. err = readDb.Model(&models.HisPrescription{}).
  463. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  464. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  465. }).
  466. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  467. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  468. }).
  469. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  470. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  471. }).
  472. 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).
  473. Find(&prescription).Error
  474. return
  475. }
  476. //未收费
  477. func GetUnChargeMonthHisPrescriptionThree(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  478. err = readDb.Model(&models.HisPrescription{}).
  479. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  480. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  481. }).
  482. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  483. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  484. }).
  485. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  486. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  487. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  488. return db.Where("status = 1 AND user_org_id = ?", org_id)
  489. }).
  490. 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 p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  491. Find(&prescription).Error
  492. return
  493. }
  494. //已收费
  495. func GetChargeMonthHisPrescriptionFour(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  496. err = readDb.Model(&models.HisPrescription{}).
  497. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  498. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  499. }).
  500. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  501. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  502. }).
  503. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  504. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  505. }).
  506. Where("user_org_id = ? AND status = 1 AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status = 2 AND p_type = ?", org_id, start_date, end_date, patient_id, p_type).
  507. Find(&prescription).Error
  508. return
  509. }
  510. type OtherDrugWarehouseInfo struct {
  511. ID int64 `gorm:"column:id" json:"id" form:"id"`
  512. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  513. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  514. Status int64 `gorm:"column:status" json:"status" form:"status"`
  515. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  516. }
  517. func (OtherDrugWarehouseInfo) TableName() string {
  518. return "xt_drug_warehouse_info"
  519. }
  520. type VMDrugSalesReturnInfo struct {
  521. ID int64 `gorm:"column:id" json:"id" form:"id"`
  522. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  523. Count int64 `gorm:"column:count" json:"count" form:"count"`
  524. Status int64 `gorm:"column:status" json:"status" form:"status"`
  525. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  526. }
  527. func (VMDrugSalesReturnInfo) TableName() string {
  528. return "xt_drug_sales_return_info"
  529. }
  530. type VMDrugWarehouseOutInfo struct {
  531. ID int64 `gorm:"column:id" json:"id" form:"id"`
  532. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  533. Count int64 `gorm:"column:count" json:"count" form:"count"`
  534. Status int64 `gorm:"column:status" json:"status" form:"status"`
  535. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  536. }
  537. func (VMDrugWarehouseOutInfo) TableName() string {
  538. return "xt_drug_warehouse_out_info"
  539. }
  540. type VMDrugCancelStockInfo struct {
  541. ID int64 `gorm:"column:id" json:"id" form:"id"`
  542. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  543. Count int64 `gorm:"column:count" json:"count" form:"count"`
  544. Status int64 `gorm:"column:status" json:"status" form:"status"`
  545. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  546. }
  547. func (VMDrugCancelStockInfo) TableName() string {
  548. return "xt_drug_cancel_stock_info"
  549. }
  550. type BaseDrugLib struct {
  551. ID int64 `gorm:"column:id" json:"id" form:"id"`
  552. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  553. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  554. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  555. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  556. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  557. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  558. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  559. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  560. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  561. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  562. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  563. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  564. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  565. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  566. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  567. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  568. Dose float64 `gorm:"column:dose" json:"dose" form:"dose"`
  569. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  570. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  571. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  572. MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
  573. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  574. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  575. Number string `gorm:"column:number" json:"number" form:"number"`
  576. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  577. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  578. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  579. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  580. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  581. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  582. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  583. Code string `gorm:"column:code" json:"code" form:"code"`
  584. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  585. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  586. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  587. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  588. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  589. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  590. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  591. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  592. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  593. Label int64 `gorm:"column:label" json:"label" form:"label"`
  594. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  595. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  596. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  597. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  598. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  599. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  600. Status int64 `gorm:"column:status" json:"status" form:"status"`
  601. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  602. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  603. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  604. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  605. Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
  606. PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
  607. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  608. DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
  609. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  610. DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
  611. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  612. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  613. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  614. Dosage string `gorm:"column:dosage" json:"dosage" form:"dosage"`
  615. Unval string `gorm:"column:unval" json:"unval" form:"unval"`
  616. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  617. PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
  618. DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
  619. Total float64 `gorm:"column:total" json:"total" form:"total"`
  620. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  621. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  622. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  623. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  624. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  625. }
  626. func (BaseDrugLib) TableName() string {
  627. return "xt_base_drug"
  628. }
  629. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  630. err = readDb.Model(&BaseDrugLib{}).Preload("OtherDrugWarehouseInfo", "status = 1 AND org_id = ?", org_id).
  631. Preload("VMDrugSalesReturnInfo", "status = 1 AND org_id = ?", org_id).
  632. Preload("VMDrugWarehouseOutInfo", "status = 1 AND org_id = ?", org_id).
  633. Preload("VMDrugCancelStockInfo", "status = 1 AND org_id = ?", org_id).
  634. Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  635. return
  636. }
  637. func GetAllDrugLibs(org_id int64) (drugs []*Drugs, err error) {
  638. 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")
  639. err = db.Find(&drugs).Error
  640. return
  641. }
  642. func GetAllProjectList(org_id int64, keyword string) (list []*models.HisProject, err error) {
  643. if len(keyword) != 0 {
  644. key := "%" + keyword + "%"
  645. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1 AND project_name Like ?", org_id, key).Find(&list).Error
  646. } else {
  647. err = readDb.Model(&models.HisProject{}).Where("user_org_id = ? AND status = 1", org_id).Find(&list).Error
  648. }
  649. return
  650. }
  651. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  652. err = writeDb.Create(&charge).Error
  653. return
  654. }
  655. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  656. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  657. 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")
  658. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  659. return
  660. }
  661. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  662. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  663. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  664. }).Where("org_id = ? AND status = 1 AND user_type = 2", org_id).Find(&doctors).Error
  665. return
  666. }
  667. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  668. tx := writeDb.Begin()
  669. if err = tx.Model(&models.HisDoctorAdviceInfo{}).Save(s).Error; err != nil {
  670. tx.Rollback()
  671. return
  672. }
  673. tx.Commit()
  674. return
  675. }
  676. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  677. tx := writeDb.Begin()
  678. if err = tx.Model(&models.HisPrescriptionProject{}).Save(project).Error; err != nil {
  679. tx.Rollback()
  680. return
  681. }
  682. tx.Commit()
  683. return
  684. }
  685. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  686. 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
  687. return
  688. }
  689. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  690. err := writeDb.Create(&patient).Error
  691. return err
  692. }
  693. func GetVMHisPatientInfo(org_id int64, id int64, record_date int64) (info models.VMHisPatient, err error) {
  694. 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
  695. return
  696. }
  697. func CreateOrder(order *models.HisOrder) (err error) {
  698. err = writeDb.Create(&order).Error
  699. return
  700. }
  701. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  702. err = writeDb.Create(&order).Error
  703. return
  704. }
  705. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64) (info models.HisPrescriptionInfo, err error) {
  706. 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
  707. return
  708. }
  709. func FindHisPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64, p_type int64, his_patient_id int64) (info models.HisPrescriptionInfo, err error) {
  710. 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
  711. return
  712. }
  713. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  714. 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
  715. return
  716. }
  717. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  718. tx := writeDb.Begin()
  719. if err = tx.Model(&models.HisPrescription{}).Save(&info).Error; err != nil {
  720. tx.Rollback()
  721. return
  722. }
  723. tx.Commit()
  724. return
  725. }
  726. func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int64, end_time int64, doctor_id int64, keywords string, p_type int64) (order []*models.HisOrder, err error, total int64) {
  727. offset := (page - 1) * limit
  728. db := readDb.Model(&models.HisOrder{})
  729. if doctor_id > 0 {
  730. 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)
  731. }
  732. if len(keywords) > 0 {
  733. keywords = "%" + keywords + "%"
  734. 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)
  735. }
  736. if start_time != 0 {
  737. db = db.Where("his_order.settle_accounts_date>=?", start_time)
  738. }
  739. if end_time != 0 {
  740. db = db.Where("his_order.settle_accounts_date<=?", end_time)
  741. }
  742. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ? AND his_order.p_type = ?", user_org_id, p_type)
  743. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  744. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  745. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  746. Preload("HisHospitalCheckRecord", "status = 1 AND user_org_id = ?", user_org_id)
  747. db = db.Preload("HisFundSettleListResult", "status = 1")
  748. db = db.Count(&total)
  749. err = db.Limit(limit).Offset(offset).Order("settle_accounts_date desc,ctime").Find(&order).Error
  750. return
  751. }
  752. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  753. 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
  754. return
  755. }
  756. func UpDateAddtionNumber(user_org_id int64, ids []int64, number string) (err error) {
  757. 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
  758. return
  759. }
  760. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  761. 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
  762. return
  763. }
  764. func UpDateHisPrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64, his_patient_id int64) (err error) {
  765. 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
  766. return
  767. }
  768. type HisOrder struct {
  769. ID int64 `gorm:"column:id" json:"id" form:"id"`
  770. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  771. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  772. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  773. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  774. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  775. Status int64 `gorm:"column:status" json:"status" form:"status"`
  776. Number string `gorm:"column:number" json:"number" form:"number"`
  777. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  778. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  779. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  780. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  781. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  782. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  783. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  784. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  785. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  786. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  787. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  788. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  789. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  790. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  791. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  792. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  793. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  794. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  795. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  796. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  797. }
  798. func (HisOrder) TableName() string {
  799. return "his_order"
  800. }
  801. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  802. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  803. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  804. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  805. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  806. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  807. Order("ctime desc").
  808. Find(&order).Error
  809. return
  810. }
  811. func GetHisPrescriptionThree(org_id int64, patient_id int64, number string) (prescription []*models.HisPrescription, err error) {
  812. err = readDb.Model(&models.HisPrescription{}).
  813. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  814. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  815. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  816. }).
  817. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  818. Where("user_org_id = ? AND status = 1 AND patient_id = ? AND batch_number=?", org_id, patient_id, number).
  819. Find(&prescription).Error
  820. return
  821. }
  822. type HisPrescriptionInfo struct {
  823. ID int64 `gorm:"column:id" json:"id" form:"id"`
  824. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  825. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  826. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  827. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  828. Status int64 `gorm:"column:status" json:"status" form:"status"`
  829. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  830. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  831. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  832. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  833. Diagnosis int64 `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  834. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  835. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  836. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  837. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  838. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  839. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  840. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  841. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  842. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  843. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  844. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  845. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  846. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  847. }
  848. func (HisPrescriptionInfo) TableName() string {
  849. return "his_prescription_info"
  850. }
  851. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  852. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  853. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  854. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  855. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  856. Order("ctime desc").Find(&prescriptionOrder).Error
  857. return
  858. }
  859. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  860. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, org_id).
  861. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  862. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  863. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  864. return
  865. }
  866. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  867. err = readDb.Model(&models.HisPrescription{}).
  868. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  869. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  870. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  871. }).
  872. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  873. Find(&prescription).Error
  874. return
  875. }
  876. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  877. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  878. return
  879. }
  880. func UpdataOrderStatus(id int64, number string, user_org_id int64) (err error) {
  881. 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()}).Error
  882. 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
  883. 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
  884. return
  885. }
  886. func SaveHisPatient(his models.HisPatient) (err error) {
  887. err = writeDb.Save(&his).Error
  888. return
  889. }
  890. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  891. 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()})
  892. }
  893. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  894. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  895. return
  896. }
  897. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  898. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  899. First(&order).Error
  900. return
  901. }
  902. func UpDateOrder(order models.HisOrder) (err error) {
  903. err = writeDb.Save(&order).Error
  904. return
  905. }
  906. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  907. 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
  908. 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
  909. return
  910. }
  911. func CreateErrMsgLog(log *models.HisOrderError) {
  912. writeDb.Model(&models.HisOrderError{}).Create(&log)
  913. }
  914. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  915. 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
  916. return
  917. }
  918. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  919. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  920. return
  921. }
  922. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  923. db := readDb.Model(&models.OutpatientServiceSick{})
  924. db = db.Where("user_org_id = ? AND status = 1", orgId)
  925. err = db.Order("ctime desc").Find(&list).Error
  926. return
  927. }
  928. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  929. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  930. db = db.Where("user_org_id = ? AND status = 1", orgId)
  931. err = db.Order("ctime desc").Find(&list).Error
  932. return
  933. }
  934. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  935. db := readDb.Model(&models.XtHisAddtionConfig{})
  936. db = db.Where("user_org_id = ? AND status = 1", orgId)
  937. err = db.Order("ctime desc").Find(&list).Error
  938. return
  939. }
  940. type XtHisOrder struct {
  941. ID int64 `gorm:"column:id" json:"id" form:"id"`
  942. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  943. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  944. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  945. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  946. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  947. Status int64 `gorm:"column:status" json:"status" form:"status"`
  948. Number string `gorm:"column:number" json:"number" form:"number"`
  949. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  950. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  951. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  952. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  953. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  954. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  955. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  956. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  957. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  958. }
  959. func (XtHisOrder) TableName() string {
  960. return "his_order"
  961. }
  962. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  963. err = readDb.Model(&models.HisPrescription{}).
  964. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  965. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  966. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  967. }).
  968. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  969. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  970. Find(&prescription).Error
  971. return
  972. }
  973. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  974. 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
  975. return
  976. }
  977. func DelelteAddition(id int64, user_org_id int64) (err error) {
  978. 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
  979. return
  980. }
  981. func GetNewHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMHisHospitalPrescriptionInfo, err error, total int64) {
  982. offset := (page - 1) * limit
  983. db := readDb.Model(&VMHisHospitalPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 ", org_id, record_date)
  984. if len(keywords) > 0 {
  985. keywords = "%" + keywords + "%"
  986. db = db.Joins("JOIN xt_patients as p On his_prescription_info.patient_id = p.id AND p.user_org_id = ? AND p.name like ?", org_id, keywords)
  987. }
  988. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  989. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id)
  990. db = db.Count(&total)
  991. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  992. return
  993. }
  994. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*VMSchedule, err error, total int64) {
  995. offset := (page - 1) * limit
  996. db := readDb.Model(&VMSchedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  997. if len(keywords) > 0 {
  998. keywords = "%" + keywords + "%"
  999. 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)
  1000. 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)
  1001. }
  1002. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  1003. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  1004. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id).
  1005. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND p_type <> 1", org_id)
  1006. db = db.Count(&total)
  1007. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  1008. return
  1009. }
  1010. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  1011. patient := models.VMHisPatient{}
  1012. 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
  1013. return patient, err
  1014. }
  1015. type VMOtherHisPrescriptionInfo struct {
  1016. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1017. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1018. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1019. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1020. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1021. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  1022. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1023. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1024. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  1025. }
  1026. func (VMOtherHisPrescriptionInfo) TableName() string {
  1027. return "his_prescription_info"
  1028. }
  1029. type VMHisPrescription struct {
  1030. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1031. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1032. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1033. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1034. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1035. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1036. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1037. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1038. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1039. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  1040. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1041. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1042. }
  1043. func (VMHisPrescription) TableName() string {
  1044. return "his_prescription"
  1045. }
  1046. func GetHisPrescriptionByType(change_type int64, record_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1047. if change_type == 1 { //根据日期取出上一方数据
  1048. var Id AdviceDate
  1049. 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
  1050. 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).
  1051. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1052. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1053. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1054. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1055. }).
  1056. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1057. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1058. })
  1059. }).Find(&advice).Error
  1060. } else if change_type == 2 {
  1061. var Id AdviceDate
  1062. 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
  1063. 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).
  1064. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1065. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1066. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1067. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1068. }).
  1069. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1070. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1071. })
  1072. }).Find(&advice).Error
  1073. }
  1074. return
  1075. }
  1076. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64, p_type int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1077. 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).
  1078. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1079. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1080. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1081. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1082. }).
  1083. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1084. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1085. })
  1086. }).Find(&advice).Error
  1087. return
  1088. }
  1089. func GetMobileCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  1090. 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).
  1091. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  1092. return db.Where("status = 1 AND user_org_id = ?", org_id).
  1093. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1094. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1095. }).
  1096. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1097. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status = 1")
  1098. })
  1099. }).Find(&advice).Error
  1100. return
  1101. }
  1102. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  1103. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1104. return
  1105. }
  1106. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  1107. err = readDb.Model(&models.HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1108. return
  1109. }
  1110. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  1111. 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
  1112. return
  1113. }
  1114. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  1115. 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
  1116. return
  1117. }
  1118. func GetHisDoctorAdvicesById(id int64) (advice models.HisDoctorAdviceInfo, err error) {
  1119. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("status = 1 AND id = ?", id).First(&advice).Error
  1120. return
  1121. }
  1122. func GetAdditionChargeByID(org_id int64, id int64) (addition models.XtHisAddtionConfig, err error) {
  1123. err = readDb.Model(&models.XtHisAddtionConfig{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&addition).Error
  1124. return
  1125. }
  1126. func GetHisPrescriptionByID(org_id int64, id int64) (pre models.HisPrescription, err error) {
  1127. err = readDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND id = ?", org_id, id).First(&pre).Error
  1128. return
  1129. }
  1130. func GetHisProjectByID(id int64) (project models.HisPrescriptionProject, err error) {
  1131. err = readDb.Model(&models.HisPrescriptionProject{}).Where("status = 1 AND id = ?", id).First(&project).Error
  1132. return
  1133. }
  1134. func GetHisAdditionByID(id int64) (addition models.HisAdditionalCharge, err error) {
  1135. err = readDb.Model(&models.HisAdditionalCharge{}).Where("status = 1 AND id = ?", id).First(&addition).Error
  1136. return
  1137. }
  1138. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1139. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ?", id_card_no, user_org_id).First(&patient).Error
  1140. return
  1141. }
  1142. func GetPatientByIDCardAndName(id_card_no string, user_org_id int64, name string) (patient Patients, err error) {
  1143. err = readDb.Model(&Patients{}).Where("id_card_no = ? AND user_org_id = ? AND name = ?", id_card_no, user_org_id, name).First(&patient).Error
  1144. return
  1145. }
  1146. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1147. 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
  1148. return
  1149. }
  1150. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1151. var patient Patients
  1152. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1153. return patient, err
  1154. }
  1155. func GetHisPrescriptionByPatientID(patientID int64, orgID int64) (info models.HisPrescriptionInfo, err error) {
  1156. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND patient_id = ? AND status = 1", orgID, patientID).Preload("XtHisDepartment", "status = 1").Last(&info).Error
  1157. return
  1158. }
  1159. type VMHisProjectTeam struct {
  1160. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1161. ProjectTeam string `gorm:"column:project_team" json:"project_team" form:"project_team"`
  1162. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1163. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  1164. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  1165. TubeColor int64 `gorm:"column:tube_color" json:"tube_color" form:"tube_color"`
  1166. TeamType int64 `gorm:"column:team_type" json:"team_type" form:"team_type"`
  1167. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1168. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1169. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1170. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1171. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1172. ProjectId string `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1173. VMItemProjectList []*VMItemProjectList `gorm:"-" json:"list" form:"list"`
  1174. ItemId string `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1175. }
  1176. func (VMHisProjectTeam) TableName() string {
  1177. return "xt_his_project_team"
  1178. }
  1179. type VMHisProject struct {
  1180. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1181. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1182. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1183. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1184. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  1185. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  1186. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1187. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1188. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1189. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1190. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1191. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  1192. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  1193. }
  1194. func (VMHisProject) TableName() string {
  1195. return "xt_his_project"
  1196. }
  1197. type VMItemProjectList struct {
  1198. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1199. Number int64 `gorm:"column:number" json:"number" form:"number"`
  1200. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1201. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1202. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1203. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1204. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  1205. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1206. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1207. VMHisProject VMHisProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1208. GoodInfo GoodInfo `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"good_info"`
  1209. }
  1210. func (VMItemProjectList) TableName() string {
  1211. return "xt_his_project_list"
  1212. }
  1213. type VMHisPrescriptionTwo struct {
  1214. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1215. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1216. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1217. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1218. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1219. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1220. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1221. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1222. }
  1223. func (VMHisPrescriptionTwo) TableName() string {
  1224. return "his_prescription"
  1225. }
  1226. func GetAllProjectTeamList(orgid int64) (project []*VMHisProjectTeam, err error) {
  1227. err = XTReadDB().Model(&VMHisProjectTeam{}).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1228. for _, item := range project {
  1229. var project_item []*VMItemProjectList
  1230. ids := strings.Split(item.ItemId, ",")
  1231. 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)
  1232. item.VMItemProjectList = append(item.VMItemProjectList, project_item...)
  1233. }
  1234. return
  1235. }
  1236. type HisDoctorAdviceInfo struct {
  1237. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1238. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1239. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1240. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  1241. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  1242. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  1243. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1244. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  1245. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1246. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1247. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1248. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1249. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1250. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1251. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1252. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1253. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  1254. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1255. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1256. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  1257. Drug Drug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
  1258. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1259. }
  1260. func (HisDoctorAdviceInfo) TableName() string {
  1261. return "his_doctor_advice_info"
  1262. }
  1263. type HisPrescriptionProject struct {
  1264. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1265. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1266. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1267. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1268. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1269. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1270. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1271. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1272. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1273. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1274. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1275. Count int64 `gorm:"column:count" json:"count" form:"count"`
  1276. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1277. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  1278. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1279. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1280. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1281. Day string `gorm:"column:day" json:"day" form:"day"`
  1282. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1283. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  1284. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1285. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1286. VMHisPrescriptionTwo VMHisPrescriptionTwo `gorm:"ForeignKey:ID;AssociationForeignKey:PrescriptionId" json:"prescription"`
  1287. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1288. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1289. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1290. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1291. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1292. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1293. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1294. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1295. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1296. }
  1297. func (HisPrescriptionProject) TableName() string {
  1298. return "his_prescription_project"
  1299. }
  1300. type HisOrderInfo struct {
  1301. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1302. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  1303. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  1304. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  1305. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  1306. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  1307. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  1308. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1309. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  1310. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1311. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1312. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  1313. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  1314. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1315. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1316. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1317. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1318. HisDoctorAdviceInfo HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  1319. }
  1320. func (HisOrderInfo) TableName() string {
  1321. return "his_order_info"
  1322. }
  1323. func GetHisOrderDetailByNumber(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
  1324. err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1325. 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)
  1326. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1327. 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)
  1328. }).Find(&order).Error
  1329. return
  1330. }
  1331. type MedicalInsuranceCostCompare struct {
  1332. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1333. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1334. EndTime int64 `gorm:"column:end_time" json:"end_time" form:"end_time"`
  1335. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1336. CheckType int64 `gorm:"column:check_type" json:"check_type" form:"check_type"`
  1337. Num int64 `gorm:"column:num" json:"num" form:"num"`
  1338. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1339. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1340. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1341. CostTotal float64 `gorm:"column:cost_total" json:"cost_total" form:"cost_total"`
  1342. FuncTotal float64 `gorm:"column:func_total" json:"func_total" form:"func_total"`
  1343. PsnPay float64 `gorm:"column:psn_pay" json:"psn_pay" form:"psn_pay"`
  1344. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1345. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1346. }
  1347. func (MedicalInsuranceCostCompare) TableName() string {
  1348. return "medical_insurance_cost_compare"
  1349. }
  1350. func GetMedicalInsuranceCostCompareList(orgID, page, limit int64, keywords string, insutype string, start_time int64, end_time int64) (list []*MedicalInsuranceCostCompare, total int, err error) {
  1351. offset := (page - 1) * limit
  1352. db := readDb.Model(&MedicalInsuranceCostCompare{}).Where("medical_insurance_cost_compare.user_org_id = ?", orgID)
  1353. if len(keywords) == 0 {
  1354. db = db.Where("status=1")
  1355. if len(insutype) != 0 {
  1356. db = db.Where("insutype = ?", insutype)
  1357. }
  1358. if start_time != 0 {
  1359. db = db.Where("ctime >= ? ", start_time)
  1360. }
  1361. if end_time != 0 {
  1362. db = db.Where("ctime <= ? ", end_time)
  1363. }
  1364. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1365. } else {
  1366. keywords = "%" + keywords + "%"
  1367. 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)
  1368. db = db.Where("medical_insurance_cost_compare.status=1 ")
  1369. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1370. }
  1371. return
  1372. }
  1373. type TempPatients struct {
  1374. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1375. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1376. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  1377. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  1378. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  1379. Name string `gorm:"column:name" json:"name" form:"name"`
  1380. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1381. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  1382. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  1383. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  1384. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1385. GdybPsnNcdsRecord GdybPsnNcdsRecord `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"record"`
  1386. }
  1387. func (TempPatients) TableName() string {
  1388. return "xt_patients"
  1389. }
  1390. type GdybPsnNcdsRecord struct {
  1391. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1392. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1393. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1394. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1395. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1396. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1397. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1398. IsCancel int64 `gorm:"column:is_cancel" json:"is_cancel" form:"is_cancel"`
  1399. TrtDclaDetlSn string `gorm:"column:trt_dcla_detl_sn" json:"trt_dcla_detl_sn" form:"trt_dcla_detl_sn"`
  1400. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  1401. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  1402. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  1403. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1404. OrgName string `gorm:"column:org_name" json:"org_name" form:"org_name"`
  1405. }
  1406. func (GdybPsnNcdsRecord) TableName() string {
  1407. return "gdyb_psn_ncds_record"
  1408. }
  1409. func GetGdybPsnNcdsRecordList(orgID, page, limit int64, keywords string, is_cancel int64) (list []*TempPatients, total int64, err error) {
  1410. offset := (page - 1) * limit
  1411. db := readDb.Model(&TempPatients{})
  1412. db = db.Preload("GdybPsnNcdsRecord", func(db *gorm.DB) *gorm.DB {
  1413. return db.Model(&GdybPsnNcdsRecord{}).Where("user_org_id = ?", orgID).Order("id asc")
  1414. })
  1415. fmt.Println(is_cancel)
  1416. if len(keywords) == 0 {
  1417. if is_cancel == 1 {
  1418. 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)
  1419. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1420. } else if is_cancel == 0 {
  1421. db = db.Preload("GdybPsnNcdsRecord", "user_org_id = ?", orgID)
  1422. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1423. } else if is_cancel == 2 {
  1424. 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)")
  1425. db = db.Where("xt_patients.user_org_id = ? AND xt_patients.status = 1 AND xt_patients.lapseto = 1", orgID)
  1426. }
  1427. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1428. } else {
  1429. keywords = "%" + keywords + "%"
  1430. 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)
  1431. err = db.Count(&total).Offset(offset).Limit(limit).Find(&list).Error
  1432. }
  1433. return
  1434. }
  1435. type CustomAccountFormData struct {
  1436. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1437. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1438. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1439. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1440. MdtrtiId string `gorm:"column:mdtrt_id" json:"mdtrt_id" form:"mdtrt_id"`
  1441. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1442. ActPayDedc float64 `gorm:"column:act_pay_dedc" json:"act_pay_dedc" form:"act_pay_dedc"`
  1443. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1444. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1445. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1446. CashPay float64 `gorm:"column:cash_pay" json:"cash_pay" form:"cash_pay"`
  1447. Sumamt float64 `gorm:"column:sumamt" json:"sumamt" form:"sumamt"`
  1448. Iinfo string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
  1449. DiagnosisId int64 `gorm:"column:diagnosis_id" json:"diagnosis_id" form:"diagnosis_id"`
  1450. DialysisCount int64 `gorm:"-"`
  1451. PatientId int64 `gorm:"column:patient_id" json:"dialysis_count" form:"dialysis_count"`
  1452. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1453. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1454. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1455. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1456. MayPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1457. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  1458. }
  1459. func GetCheckAccountFormData(start_time int64, end_time int64, org_id int64, insutype string) (cus []*CustomAccountFormData, err error) {
  1460. 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 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 insutype = ? Group by o.id", org_id, start_time, end_time, insutype).Scan(&cus).Error
  1461. for _, item := range cus {
  1462. var total int64
  1463. 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)
  1464. fmt.Println(total)
  1465. item.DialysisCount = total
  1466. fmt.Println(item.DialysisCount)
  1467. }
  1468. return
  1469. }
  1470. func GetNewHisPatientInfo(his_patient_id int64) (info models.HisPatient, err error) {
  1471. err = readDb.Model(&models.HisPatient{}).Where("id = ? AND status = 1 ", his_patient_id).First(&info).Error
  1472. return
  1473. }
  1474. func GetNewHisOrder(user_org_id int64, mdtrt_id string, patient_id int64) (order HisOrder, err error) {
  1475. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND mdtrt_id=? ", user_org_id, patient_id, mdtrt_id).
  1476. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1477. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  1478. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  1479. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  1480. Order("ctime desc").
  1481. Last(&order).Error
  1482. return
  1483. }
  1484. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1485. 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).
  1486. Order("ctime desc").
  1487. Find(&order).Error
  1488. return
  1489. }
  1490. type NewCustomPatients struct {
  1491. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1492. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1493. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1494. Number string `gorm:"column:number" json:"number" form:"number"`
  1495. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1496. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1497. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,Number" json:"order"`
  1498. }
  1499. func (NewCustomPatients) TableName() string {
  1500. return "his_patients"
  1501. }
  1502. type NewSZCustomPatients struct {
  1503. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1504. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1505. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1506. Number string `gorm:"column:number" json:"number" form:"number"`
  1507. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1508. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1509. VMHisOrder VMHisOrder `gorm:"ForeignKey:PatientId,MdtrtId;AssociationForeignKey:PatientId,MzNumber" json:"order"`
  1510. }
  1511. func (NewSZCustomPatients) TableName() string {
  1512. return "his_patients"
  1513. }
  1514. //
  1515. //func GetNewAllChargeHisPatientList(org_id int64, record_date int64) (patients []*NewSZCustomPatients, err error) {
  1516. // var tempPatients []*NewSZCustomPatients
  1517. // db := readDb.Model(&NewSZCustomPatients{}).Where("his_patients.user_org_id = ? AND his_patients.status = 1", org_id)
  1518. // db = db.Preload("VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date)
  1519. // return tempPatients, err
  1520. //}
  1521. type NewTempPatients struct {
  1522. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1523. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1524. Name string `gorm:"column:name" json:"name" form:"name"`
  1525. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1526. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1527. ScheduleType int64 `gorm:"column:schedule_type" json:"schedule_type" form:"schedule_type"`
  1528. Schedule Schedule `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"schedule"`
  1529. HisPatient []*HisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"his_patient"`
  1530. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"prescription"`
  1531. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"info"`
  1532. }
  1533. func (NewTempPatients) TableName() string {
  1534. return "xt_patients"
  1535. }
  1536. //"VMHisOrder", "user_org_id = ? AND status = 1 AND settle_accounts_date = ?", org_id, record_date
  1537. func GetNewAllUnChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  1538. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1539. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1540. 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)
  1541. })
  1542. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1 AND order_status <> 2", org_id, record_date)
  1543. 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
  1544. for _, item := range patients {
  1545. for _, sumItem := range item.HisPatient {
  1546. if len(sumItem.VMHisOrders) > 0 {
  1547. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1548. }
  1549. }
  1550. }
  1551. return
  1552. }
  1553. func GetNewAllChargeHisPatientList(org_id int64, keywords string, record_date int64) (patients []*NewTempPatients, err error) {
  1554. db := readDb.Model(&NewTempPatients{}).Where("xt_patients.user_org_id = ? AND xt_patients.status = 1", org_id)
  1555. db = db.Preload("HisPatient", func(db *gorm.DB) *gorm.DB {
  1556. 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)
  1557. })
  1558. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date)
  1559. err = db.Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1 AND record_date = ? AND p_type <> 1", org_id, record_date).Find(&patients).Error
  1560. for _, item := range patients {
  1561. for _, sumItem := range item.HisPatient {
  1562. if len(sumItem.VMHisOrders) > 0 {
  1563. sumItem.VMHisOrder.OrderStatus = sumItem.VMHisOrders[len(sumItem.VMHisOrders)-1].OrderStatus
  1564. }
  1565. }
  1566. }
  1567. return
  1568. }
  1569. func GetPrescriptionById(id int64, org_id int64) (prescription models.HisPrescription, err error) {
  1570. err = readDb.Model(&models.HisPrescription{}).Where("id = ? AND user_org_id = ? AND status = 1", id, org_id).First(&prescription).Error
  1571. return
  1572. }
  1573. type CustomInComeStatistics struct {
  1574. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1575. SetlTime string `gorm:"column:setl_time" json:"setl_time" form:"setl_time"`
  1576. SettleAccountsDate string `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  1577. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  1578. FundPaySumamt float64 `gorm:"column:fund_pay_sumamt" json:"fund_pay_sumamt" form:"fund_pay_sumamt"`
  1579. HifobPay float64 `gorm:"column:hifob_pay" json:"hifob_pay" form:"hifob_pay"`
  1580. HifmiPay float64 `gorm:"column:hifmi_pay" json:"hifmi_pay" form:"hifmi_pay"`
  1581. HifesPay float64 `gorm:"column:hifes_pay" json:"hifes_pay" form:"hifes_pay"`
  1582. MafPay float64 `gorm:"column:maf_pay" json:"maf_pay" form:"maf_pay"`
  1583. CvlservPay float64 `gorm:"column:cvlserv_pay" json:"cvlserv_pay" form:"cvlserv_pay"`
  1584. PsnCashPay float64 `gorm:"column:psn_cash_pay" json:"psn_cash_pay" form:"psn_cash_pay"`
  1585. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  1586. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  1587. AcctPay float64 `gorm:"column:acct_pay" json:"acct_pay" form:"acct_pay"`
  1588. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  1589. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  1590. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  1591. }
  1592. func (CustomInComeStatistics) TableName() string {
  1593. return "his_order"
  1594. }
  1595. func GetDayIncomeStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (order []*CustomInComeStatistics, total int64, err error) {
  1596. offset := (page - 1) * limit
  1597. if len(keywords) != 0 {
  1598. 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
  1599. } else {
  1600. if start_time != 0 && end_time != 0 {
  1601. 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
  1602. } else {
  1603. 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
  1604. }
  1605. }
  1606. return
  1607. }
  1608. func GetDayIncomeDetailStatisticsData(org_id int64, keywords string, start_time int64, end_time int64, page int64, limit int64) (cis []*CustomInComeStatistics, total int64, err error) {
  1609. offset := (page - 1) * limit
  1610. if len(keywords) != 0 {
  1611. 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
  1612. } else {
  1613. if start_time != 0 && end_time != 0 {
  1614. 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
  1615. } else {
  1616. 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
  1617. }
  1618. }
  1619. return
  1620. }
  1621. //func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1622. // 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
  1623. // return
  1624. //}
  1625. func CreateHisPrescriptionTemplate(template *models.HisPrescriptionTemplate) (err error) {
  1626. err = writeDb.Create(&template).Error
  1627. return
  1628. }
  1629. func CreateHisPrescriptionAdviceTemplate(s *models.HisPrescriptionAdviceTemplate) (err error) {
  1630. err = writeDb.Save(&s).Error
  1631. return
  1632. }
  1633. func CreateHisPrescriptionInfoTemplate(s *models.HisPrescriptionInfoTemplate) (err error) {
  1634. err = writeDb.Save(&s).Error
  1635. return
  1636. }
  1637. func CreateHisPrescriptionProjectTemplate(project *models.HisPrescriptionProjectTemplate) (err error) {
  1638. err = writeDb.Save(&project).Error
  1639. return
  1640. }
  1641. func GetPatientSch(patient_id int64, sch_date int64, org_id int64) (sch models.Schedule, err error) {
  1642. 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
  1643. return
  1644. }
  1645. func GetHisPrescriptionBySchMode(mode_id int64, patient_id int64, org_id int64) (prescription models.HisPrescriptionTemplate, err error) {
  1646. 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
  1647. return
  1648. }
  1649. func GetHisPrescriptionTemplate(template_id int64, org_id int64) (prescription []*models.HisPrescriptionInfoTemplate, err error) {
  1650. err = readDb.Model(&models.HisPrescriptionInfoTemplate{}).
  1651. Preload("HisPrescriptionAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  1652. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1653. }).
  1654. Preload("HisPrescriptionProjectTemplate", func(db *gorm.DB) *gorm.DB {
  1655. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisProject").Preload("GoodInfo", "status=1")
  1656. }).
  1657. Where("status = 1 AND p_template_id = ? ", template_id).
  1658. Find(&prescription).Error
  1659. return
  1660. }
  1661. func FindHisConsumablesByID(orgID int64, patient_id int64, recordDate int64, good_id int64) (consumables models.DialysisBeforePrepare, err error) {
  1662. 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
  1663. return
  1664. }
  1665. func UpdateConsumables(consumables *models.DialysisBeforePrepare) (err error) {
  1666. err = writeDb.Save(&consumables).Error
  1667. return
  1668. }
  1669. func GetHisPrescriptionProjectsByID(id int64) (projects []*models.HisPrescriptionProject, err error) {
  1670. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("prescription_id = ? AND status = 1", id).Find(&projects).Error
  1671. return
  1672. }
  1673. func GetHisPrescriptionProjects(user_org_id int64, patient_id int64, record_time int64) (projects []*models.HisPrescriptionProject, err error) {
  1674. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("user_org_id = ? AND patient_id = ? AND record_date = ? AND status = 1", user_org_id, patient_id, record_time).Find(&projects).Error
  1675. return
  1676. }
  1677. func GetHisPrescriptionProjectByID(id int64) (projects models.HisPrescriptionProject, err error) {
  1678. err = readDb.Model(&models.HisPrescriptionProject{}).Preload("GoodInfo", "status = 1").Where("id = ? AND status = 1", id).First(&projects).Error
  1679. return
  1680. }
  1681. func GetHisPrescriptionAdviceByID(id int64) (advices []*models.HisDoctorAdviceInfo, err error) {
  1682. err = readDb.Model(&models.HisDoctorAdviceInfo{}).Where("prescription_id = ? AND status = 1", id).Find(&advices).Error
  1683. return
  1684. }
  1685. func UpdateGoodInfo(good_info *models.GoodInfo) (err error) {
  1686. err = writeDb.Save(&good_info).Error
  1687. return
  1688. }
  1689. func GetUnChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  1690. err = readDb.Model(&models.HisPrescription{}).
  1691. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1692. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1693. }).
  1694. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1695. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1696. }).
  1697. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1698. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1699. }).
  1700. 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).
  1701. Find(&prescription).Error
  1702. return
  1703. }
  1704. func GetChargeMonthHisPrescriptionSix(org_id int64, patient_id int64, start_date int64, end_date int64, p_type int64) (prescription []*models.HisPrescription, err error) {
  1705. err = readDb.Model(&models.HisPrescription{}).
  1706. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1707. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1708. }).
  1709. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1710. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1711. }).
  1712. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1713. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1714. }).
  1715. 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).
  1716. Find(&prescription).Error
  1717. return
  1718. }
  1719. func GetChargeHisPrescriptionSeven(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  1720. err = readDb.Model(&models.HisPrescription{}).
  1721. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1722. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1723. }).
  1724. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1725. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1726. }).
  1727. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1728. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1729. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  1730. return db.Where("status = 1 AND user_org_id = ?", org_id)
  1731. }).
  1732. 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).
  1733. Find(&prescription).Error
  1734. return
  1735. }
  1736. //已收费
  1737. func GetChargeMonthHisPrescriptionFive(org_id int64, patient_id int64, order_number string, p_type int64) (prescription []*models.HisPrescription, err error) {
  1738. err = readDb.Model(&models.HisPrescription{}).
  1739. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1740. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1741. }).
  1742. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1743. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("Drug", "status=1")
  1744. }).
  1745. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1746. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1747. }).Preload("TempHisOrder", func(db *gorm.DB) *gorm.DB {
  1748. return db.Where("status = 1 AND user_org_id = ?", org_id)
  1749. }).
  1750. 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).
  1751. Find(&prescription).Error
  1752. return
  1753. }
  1754. func UpdataHisPateint(his *models.HisPatient) {
  1755. writeDb.Save(&his)
  1756. }
  1757. func SaveHisOrder(his *models.HisOrder) (err error) {
  1758. err = writeDb.Save(&his).Error
  1759. return
  1760. }