his_service.go 146KB

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