his_service.go 155KB

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