his_service.go 134KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172
  1. package service
  2. import (
  3. "fmt"
  4. "gdyb/models"
  5. "github.com/jinzhu/gorm"
  6. "strconv"
  7. "time"
  8. )
  9. type HisPatient struct {
  10. ID int64 `gorm:"column:id" json:"id" form:"id"`
  11. Name string `gorm:"column:name" json:"name" form:"name"`
  12. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  13. Total float64 `gorm:"column:total" json:"total" form:"total"`
  14. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  15. Status int64 `gorm:"column:status" json:"status" form:"status"`
  16. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  17. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"prescription"`
  18. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  19. Number string `gorm:"column:number" json:"number" form:"number"`
  20. PatientInfo string `gorm:"column:patient_info" json:"patient_info" form:"patient_info"`
  21. Insutype string `gorm:"column:insutype" json:"insutype" form:"insutype"`
  22. }
  23. func (HisPatient) TableName() string {
  24. return "his_patient"
  25. }
  26. type Schedule struct {
  27. ID int64 `gorm:"column:id" json:"id" form:"id"`
  28. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  29. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  30. Status int64 `gorm:"column:status" json:"status" form:"status"`
  31. ScheduleDate int64 `gorm:"column:schedule_date" json:"schedule_date" form:"schedule_date"`
  32. Patients Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patients"`
  33. HisPatient HisPatient `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"his_patient"`
  34. HisPrescription []*HisPrescription `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"prescription"`
  35. VMHisPrescriptionInfo VMHisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  36. }
  37. func (Schedule) TableName() string {
  38. return "xt_schedule"
  39. }
  40. type VMHisPrescriptionInfo 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. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  44. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  45. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  46. Status int64 `gorm:"column:status" json:"status" form:"status"`
  47. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  48. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  49. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  50. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  51. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  52. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  53. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  54. Departments string `gorm:"column:departments" json:"departments" form:"departments"`
  55. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  56. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  57. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  58. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  59. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  60. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  61. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  62. }
  63. func (VMHisPrescriptionInfo) TableName() string {
  64. return "his_prescription_info"
  65. }
  66. type Patients struct {
  67. ID int64 `gorm:"column:id" json:"id" form:"id"`
  68. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  69. UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
  70. Avatar string `gorm:"column:avatar" json:"avatar" form:"avatar"`
  71. PatientType int64 `gorm:"column:patient_type" json:"patient_type" form:"patient_type"`
  72. DialysisNo string `gorm:"column:dialysis_no" json:"dialysis_no" form:"dialysis_no"`
  73. AdmissionNumber string `gorm:"column:admission_number" json:"admission_number" form:"admission_number"`
  74. Source int64 `gorm:"column:source" json:"source" form:"source"`
  75. Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
  76. PartitionId int64 `gorm:"column:partition_id" json:"partition_id" form:"partition_id"`
  77. BedId int64 `gorm:"column:bed_id" json:"bed_id" form:"bed_id"`
  78. Name string `gorm:"column:name" json:"name" form:"name"`
  79. Alias string `gorm:"column:alias" json:"alias" form:"alias"`
  80. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  81. MaritalStatus int64 `gorm:"column:marital_status" json:"marital_status" form:"marital_status"`
  82. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  83. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  84. ReimbursementWayId int64 `gorm:"column:reimbursement_way_id" json:"reimbursement_way_id" form:"reimbursement_way_id"`
  85. HealthCareType int64 `gorm:"column:health_care_type" json:"health_care_type" form:"health_care_type"`
  86. HealthCareNo string `gorm:"column:health_care_no" json:"health_care_no" form:"health_care_no"`
  87. HealthCareDueDate int64 `gorm:"column:health_care_due_date" json:"health_care_due_date" form:"health_care_due_date"`
  88. Height int64 `gorm:"column:height" json:"height" form:"height"`
  89. BloodType int64 `gorm:"column:blood_type" json:"blood_type" form:"blood_type"`
  90. Rh int64 `gorm:"column:rh" json:"rh" form:"rh"`
  91. HealthCareDueAlertDate int64 `gorm:"column:health_care_due_alert_date" json:"health_care_due_alert_date" form:"health_care_due_alert_date"`
  92. EducationLevel int64 `gorm:"column:education_level" json:"education_level" form:"education_level"`
  93. Profession int64 `gorm:"column:profession" json:"profession" form:"profession"`
  94. Phone string `gorm:"column:phone" json:"phone" form:"phone"`
  95. HomeTelephone string `gorm:"column:home_telephone" json:"home_telephone" form:"home_telephone"`
  96. RelativePhone string `gorm:"column:relative_phone" json:"relative_phone" form:"relative_phone"`
  97. RelativeRelations string `gorm:"column:relative_relations" json:"relative_relations" form:"relative_relations"`
  98. HomeAddress string `gorm:"column:home_address" json:"home_address" form:"home_address"`
  99. WorkUnit string `gorm:"column:work_unit" json:"work_unit" form:"work_unit"`
  100. UnitAddress string `gorm:"column:unit_address" json:"unit_address" form:"unit_address"`
  101. Children int64 `gorm:"column:children" json:"children" form:"children"`
  102. ReceivingDate int64 `gorm:"column:receiving_date" json:"receiving_date" form:"receiving_date"`
  103. IsHospitalFirstDialysis int64 `gorm:"column:is_hospital_first_dialysis" json:"is_hospital_first_dialysis" form:"is_hospital_first_dialysis"`
  104. FirstDialysisDate int64 `gorm:"column:first_dialysis_date" json:"first_dialysis_date" form:"first_dialysis_date"`
  105. FirstDialysisHospital string `gorm:"column:first_dialysis_hospital" json:"first_dialysis_hospital" form:"first_dialysis_hospital"`
  106. PredialysisCondition string `gorm:"column:predialysis_condition" json:"predialysis_condition" form:"predialysis_condition"`
  107. PreHospitalDialysisFrequency string `gorm:"column:pre_hospital_dialysis_frequency" json:"pre_hospital_dialysis_frequency" form:"pre_hospital_dialysis_frequency"`
  108. PreHospitalDialysisTimes int64 `gorm:"column:pre_hospital_dialysis_times" json:"pre_hospital_dialysis_times" form:"pre_hospital_dialysis_times"`
  109. HospitalFirstDialysisDate int64 `gorm:"column:hospital_first_dialysis_date" json:"hospital_first_dialysis_date" form:"hospital_first_dialysis_date"`
  110. InductionPeriod int64 `gorm:"column:induction_period" json:"induction_period" form:"induction_period"`
  111. InitialDialysis int64 `gorm:"column:initial_dialysis" json:"initial_dialysis" form:"initial_dialysis"`
  112. TotalDialysis int64 `gorm:"column:total_dialysis" json:"total_dialysis" form:"total_dialysis"`
  113. AttendingDoctorId int64 `gorm:"column:attending_doctor_id" json:"attending_doctor_id" form:"attending_doctor_id"`
  114. HeadNurseId int64 `gorm:"column:head_nurse_id" json:"head_nurse_id" form:"head_nurse_id"`
  115. Evaluate string `gorm:"column:evaluate" json:"evaluate" form:"evaluate"`
  116. Diagnose string `gorm:"column:diagnose" json:"diagnose" form:"diagnose"`
  117. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  118. RegistrarsId int64 `gorm:"column:registrars_id" json:"registrars_id" form:"registrars_id"`
  119. Registrars string `gorm:"column:registrars" json:"registrars" form:"registrars"`
  120. QrCode string `gorm:"column:qr_code" json:"qr_code" form:"qr_code"`
  121. BindingState int64 `gorm:"column:binding_state" json:"binding_state" form:"binding_state"`
  122. PatientComplains string `gorm:"column:patient_complains" json:"patient_complains" form:"patient_complains"`
  123. PresentHistory string `gorm:"column:present_history" json:"present_history" form:"present_history"`
  124. PastHistory string `gorm:"column:past_history" json:"past_history" form:"past_history"`
  125. Temperature float64 `gorm:"column:temperature" json:"temperature" form:"temperature"`
  126. Pulse int64 `gorm:"column:pulse" json:"pulse" form:"pulse"`
  127. Respiratory int64 `gorm:"column:respiratory" json:"respiratory" form:"respiratory"`
  128. Sbp int64 `gorm:"column:sbp" json:"sbp" form:"sbp"`
  129. Dbp int64 `gorm:"column:dbp" json:"dbp" form:"dbp"`
  130. Status int64 `gorm:"column:status" json:"status" form:"status"`
  131. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  132. UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
  133. Nation string `gorm:"column:nation" json:"nation" form:"nation"`
  134. NativePlace string `gorm:"column:native_place" json:"native_place" form:"native_place"`
  135. Age int64 `gorm:"column:age" json:"age" form:"age"`
  136. InfectiousNextRecordTime int64 `gorm:"column:infectious_next_record_time" json:"infectious_next_record_time" form:"infectious_next_record_time"`
  137. IsInfectious int64 `gorm:"column:is_infectious" json:"is_infectious" form:"is_infectious"`
  138. IsOpenRemind int64 `gorm:"column:is_open_remind" json:"is_open_remind" form:"is_open_remind"`
  139. RemindCycle int64 `gorm:"column:remind_cycle" json:"remind_cycle" form:"remind_cycle"`
  140. ResponseResult string `gorm:"column:response_result" json:"response_result" form:"response_result"`
  141. FirstTreatmentDate int64 `gorm:"column:first_treatment_date" json:"first_treatment_date" form:"first_treatment_date"`
  142. DialysisAge int64 `gorm:"column:dialysis_age" json:"dialysis_age" form:"dialysis_age"`
  143. ExpenseKind int64 `gorm:"column:expense_kind" json:"expense_kind" form:"expense_kind"`
  144. TellPhone string `gorm:"column:tell_phone" json:"tell_phone" form:"tell_phone"`
  145. ContactName string `gorm:"column:contact_name" json:"contact_name" form:"contact_name"`
  146. UserSysBeforeCount int64 `gorm:"column:user_sys_before_count" json:"user_sys_before_count" form:"user_sys_before_count"`
  147. IsExcelExport int64 `gorm:"column:is_excel_export" json:"is_excel_export" form:"is_excel_export"`
  148. SchRemark string `gorm:"column:sch_remark" json:"sch_remark" form:"sch_remark"`
  149. OutReason string `gorm:"column:out_reason" json:"out_reason" form:"out_reason"`
  150. InsuplcAdmdvs string `gorm:"column:insuplc_admdvs" json:"insuplc_admdvs" form:"insuplc_admdvs"`
  151. }
  152. func (Patients) TableName() string {
  153. return "xt_patients"
  154. }
  155. type HisPrescription struct {
  156. ID int64 `gorm:"column:id" json:"id" form:"id"`
  157. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  158. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  159. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  160. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  161. Status int64 `gorm:"column:status" json:"status" form:"status"`
  162. }
  163. func (HisPrescription) TableName() string {
  164. return "his_prescription"
  165. }
  166. func GetHisPatientList(org_id int64, keywords string, record_date int64) (patients []*Schedule, err error) {
  167. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  168. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  169. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  170. err = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id).Find(&patients).Error
  171. return
  172. }
  173. func GetAllBaseDrugStockList(org_id int64) (drugs []*models.BaseDrugLib, err error) {
  174. err = readDb.Model(&models.BaseDrugLib{}).Where("user_org_id = ? AND status = 1", org_id).Find(&drugs).Error
  175. return
  176. }
  177. func GetHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatient, err error) {
  178. 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
  179. return
  180. }
  181. func GetNewHisPatientInfo(org_id int64, id int64, record_date int64) (info models.HisPatient, err error) {
  182. 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
  183. return
  184. }
  185. func GetXTPatientInfo(org_id int64, patient_id int64) (info models.Patients, err error) {
  186. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, patient_id).First(&info).Error
  187. return
  188. }
  189. func GetHisPatientCaseHistoryInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPatientCaseHistory, err error) {
  190. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  191. return
  192. }
  193. func GetHisPatientCaseHistoryList(org_id int64, patient_id int64) (caseHistorys []*models.HisPatientCaseHistory, err error) {
  194. db := readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? AND status = 1 AND his_patient_id = ?", org_id, patient_id)
  195. err = db.Find(&caseHistorys).Error
  196. return
  197. }
  198. func GetHisPatientCaseHistoryTemplate(org_id int64, startime int64, endtime int64, keyword string) (caseHistorys []*models.HisCaseHistoryTemplate, err error) {
  199. likekey := "%" + keyword + "%"
  200. db := readDb.Model(&models.HisCaseHistoryTemplate{}).Where("user_org_id = ? AND status = 1", org_id)
  201. if startime > 0 {
  202. db = db.Where("record_date>=?", startime)
  203. }
  204. if endtime > 0 {
  205. db = db.Where("record_date<=?", endtime)
  206. }
  207. if len(keyword) > 0 {
  208. db = db.Where("template_name like ? ", likekey)
  209. }
  210. err = db.Find(&caseHistorys).Error
  211. return
  212. }
  213. func GetHisPatientCaseHistory(org_id int64) (caseHistory []*models.HisPatientCaseHistory, err error) {
  214. err = readDb.Model(&models.HisPatientCaseHistory{}).Where("user_org_id = ? and status = 1", org_id).Find(&caseHistory).Error
  215. return caseHistory, err
  216. }
  217. func SaveHisPatientCaseHistoryTemplate(template models.HisCaseHistoryTemplate) (err error) {
  218. err = writeDb.Create(&template).Error
  219. return
  220. }
  221. func GetHisPatientCaseHistoryById(hispatientid int64) (*models.HisPatientCaseHistory, error) {
  222. history := models.HisPatientCaseHistory{}
  223. err := XTReadDB().Model(&history).Where("his_patient_id = ? and status = 1", hispatientid).Find(&history).Error
  224. if err != nil {
  225. if err == gorm.ErrRecordNotFound {
  226. return nil, err
  227. } else {
  228. return nil, err
  229. }
  230. }
  231. return &history, nil
  232. }
  233. func SaveHisPatientCaseHistory(caseHistory *models.HisPatientCaseHistory) error {
  234. err := writeDb.Create(&caseHistory).Error
  235. return err
  236. }
  237. func SaveHisPrescription(prescription *models.HisPrescription) (err error) {
  238. err = writeDb.Save(&prescription).Error
  239. return
  240. }
  241. func DelelteHisPrescription(id int64, user_org_id int64) (err error) {
  242. 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
  243. 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
  244. 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
  245. return
  246. }
  247. func DelelteDoctorAdvice(id int64, user_org_id int64) (err error) {
  248. 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
  249. return
  250. }
  251. func DelelteProject(id int64, user_org_id int64) (err error) {
  252. 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
  253. return
  254. }
  255. func GetHisPrescription(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  256. err = readDb.Model(&models.HisPrescription{}).
  257. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  258. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  259. }).
  260. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  261. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  262. }).
  263. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  264. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  265. }).
  266. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1", org_id, record_date, patient_id).
  267. Find(&prescription).Error
  268. return
  269. }
  270. func GetNewHisPrescription(org_id int64, his_patient_id int64, record_date int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  271. err = readDb.Model(&models.HisPrescription{}).
  272. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  273. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  274. }).
  275. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  276. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  277. }).
  278. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  279. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  280. }).
  281. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, record_date, his_patient_id, reg_type).
  282. Find(&prescription).Error
  283. return
  284. }
  285. type OtherDrugWarehouseInfo struct {
  286. ID int64 `gorm:"column:id" json:"id" form:"id"`
  287. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  288. WarehousingCount int64 `gorm:"column:warehousing_count" json:"warehousing_count" form:"warehousing_count"`
  289. Status int64 `gorm:"column:status" json:"status" form:"status"`
  290. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  291. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  292. }
  293. func (OtherDrugWarehouseInfo) TableName() string {
  294. return "xt_drug_warehouse_info"
  295. }
  296. type VMDrugSalesReturnInfo struct {
  297. ID int64 `gorm:"column:id" json:"id" form:"id"`
  298. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  299. Count int64 `gorm:"column:count" json:"count" form:"count"`
  300. Status int64 `gorm:"column:status" json:"status" form:"status"`
  301. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  302. }
  303. func (VMDrugSalesReturnInfo) TableName() string {
  304. return "xt_drug_sales_return_info"
  305. }
  306. type VMDrugWarehouseOutInfo struct {
  307. ID int64 `gorm:"column:id" json:"id" form:"id"`
  308. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  309. Count int64 `gorm:"column:count" json:"count" form:"count"`
  310. Status int64 `gorm:"column:status" json:"status" form:"status"`
  311. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  312. }
  313. func (VMDrugWarehouseOutInfo) TableName() string {
  314. return "xt_drug_warehouse_out_info"
  315. }
  316. type VMDrugCancelStockInfo struct {
  317. ID int64 `gorm:"column:id" json:"id" form:"id"`
  318. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  319. Count int64 `gorm:"column:count" json:"count" form:"count"`
  320. Status int64 `gorm:"column:status" json:"status" form:"status"`
  321. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  322. }
  323. func (VMDrugCancelStockInfo) TableName() string {
  324. return "xt_drug_cancel_stock_info"
  325. }
  326. type BaseDrugLib struct {
  327. ID int64 `gorm:"column:id" json:"id" form:"id"`
  328. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  329. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  330. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  331. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  332. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  333. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  334. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  335. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  336. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  337. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  338. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  339. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  340. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  341. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  342. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  343. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  344. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  345. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  346. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  347. Number string `gorm:"column:number" json:"number" form:"number"`
  348. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  349. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  350. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  351. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  352. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  353. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  354. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  355. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  356. Code string `gorm:"column:code" json:"code" form:"code"`
  357. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  358. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  359. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  360. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  361. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  362. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  363. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  364. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  365. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  366. Label int64 `gorm:"column:label" json:"label" form:"label"`
  367. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  368. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  369. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  370. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  371. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  372. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  373. Status int64 `gorm:"column:status" json:"status" form:"status"`
  374. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  375. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  376. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  377. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  378. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  379. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  380. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  381. //MedicineInsurancePercentage []*MedicineInsurancePercentage `gorm:"ForeignKey:PatientId;AssociationForeignKey:PatientId" json:"monitoring_record"`
  382. OtherDrugWarehouseInfo []*OtherDrugWarehouseInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_in"`
  383. VMDrugSalesReturnInfo []*VMDrugSalesReturnInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"sales_return"`
  384. VMDrugWarehouseOutInfo []*VMDrugWarehouseOutInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"stock_out"`
  385. VMDrugCancelStockInfo []*VMDrugCancelStockInfo `gorm:"ForeignKey:DrugId;AssociationForeignKey:ID" json:"cancel_stock"`
  386. }
  387. func (BaseDrugLib) TableName() string {
  388. return "xt_base_drug"
  389. }
  390. func GetAllDrugLibList(org_id int64) (list []*BaseDrugLib, err error) {
  391. err = readDb.Model(&BaseDrugLib{}).Preload("OtherDrugWarehouseInfo", "status = 1 AND org_id = ?", org_id).
  392. Preload("VMDrugSalesReturnInfo", "status = 1 AND org_id = ?", org_id).
  393. Preload("VMDrugWarehouseOutInfo", "status = 1 AND org_id = ?", org_id).
  394. Preload("VMDrugCancelStockInfo", "status = 1 AND org_id = ?", org_id).
  395. Where("org_id = ? AND status = 1", org_id).Find(&list).Error
  396. return
  397. }
  398. func CreateAddtionalCharge(charge *models.HisAdditionalCharge) (err error) {
  399. err = writeDb.Create(&charge).Error
  400. return
  401. }
  402. func FindAllHisAdviceTemplate(org_id int64) (temps []*models.HisDoctorAdviceParentTemplate, err error) {
  403. err = readDb.Model(&models.HisDoctorAdviceParentTemplate{}).Preload("HisDoctorAdviceTemplate", func(db *gorm.DB) *gorm.DB {
  404. 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")
  405. }).Where("org_id = ? AND status=1 ", org_id).Find(&temps).Error
  406. return
  407. }
  408. func GetHisAdminUserDoctors(org_id int64) (doctors []*models.UserAdminRole, err error) {
  409. err = readUserDb.Model(&models.UserAdminRole{}).Preload("XtHisDepartment", func(db *gorm.DB) *gorm.DB {
  410. return readDb.Model(&models.XtHisDepartment{}).Where("status = 1 AND user_org_id = ?", org_id)
  411. }).Where("org_id = ? AND status = 1 AND (user_type = 1 OR user_type = 2)", org_id).Find(&doctors).Error
  412. return
  413. }
  414. func CreateHisDoctorAdvice(s *models.HisDoctorAdviceInfo) (err error) {
  415. err = writeDb.Save(s).Error
  416. return
  417. }
  418. func CreateHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  419. err = writeDb.Save(project).Error
  420. return
  421. }
  422. func SaveHisProjectTwo(project *models.HisPrescriptionProject) (err error) {
  423. 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
  424. return
  425. }
  426. func CreateHisPatientTwo(patient *models.VMHisPatient) error {
  427. err := writeDb.Create(&patient).Error
  428. return err
  429. }
  430. func GetVMHisPatientInfo(org_id int64, patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  431. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  432. return
  433. }
  434. func GetNewVMHisPatientInfo(org_id int64, his_patient_id int64, record_date int64) (info models.VMHisPatient, err error) {
  435. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND id = ?", org_id, record_date, his_patient_id).First(&info).Error
  436. return
  437. }
  438. func GetNewHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  439. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, id).First(&info).Error
  440. return
  441. }
  442. func GetHisPatientRecord(org_id int64, id int64) (info models.VMHisPatient, err error) {
  443. err = readDb.Model(&models.VMHisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  444. return
  445. }
  446. func CreateOrder(order *models.HisOrder) (err error) {
  447. err = writeDb.Create(&order).Error
  448. return
  449. }
  450. func CreateOrderInfo(order *models.HisOrderInfo) (err error) {
  451. err = writeDb.Create(&order).Error
  452. return
  453. }
  454. func FindPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  455. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).First(&info).Error
  456. return
  457. }
  458. func FindHisPatientPrescriptionInfo(org_id int64, his_patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  459. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ?", org_id, record_date, his_patient_id).First(&info).Error
  460. return
  461. }
  462. func FindLastPatientPrescriptionInfo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  463. 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
  464. return
  465. }
  466. func FindLastPatientPrescriptionInfoTwo(org_id int64, patient_id int64, record_date int64) (info models.HisPrescriptionInfo, err error) {
  467. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ?", org_id, patient_id).Last(&info).Error
  468. return
  469. }
  470. func FindLastPatientPrescriptionInfoTwo1(org_id int64, patient_id int64) (info models.HisPrescriptionInfo, err error) {
  471. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? and p_type = 1", org_id, patient_id).Last(&info).Error
  472. return
  473. }
  474. func FindLastPatientPrescriptionInfoTwo2(org_id int64, patient_id int64, start_time string, end_time string) (info []models.HisPrescriptionInfo, err error) {
  475. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? and p_type = 1 and FROM_UNIXTIME(record_date) >= ? and FROM_UNIXTIME(record_date) <= ?", org_id, patient_id, start_time, end_time).Find(&info).Error
  476. return
  477. }
  478. func SavePatientPrescriptionInfo(info models.HisPrescriptionInfo) (err error) {
  479. err = writeDb.Save(&info).Error
  480. return
  481. }
  482. func GetHisOrderList(user_org_id int64, page int64, limit int64, start_time int64, end_time int64, doctor_id int64, keywords string) (order []*models.HisOrder, err error, total int64) {
  483. offset := (page - 1) * limit
  484. db := readDb.Model(&models.HisOrder{})
  485. if doctor_id > 0 {
  486. 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)
  487. }
  488. if len(keywords) > 0 {
  489. keywords = "%" + keywords + "%"
  490. 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)
  491. }
  492. if start_time != 0 {
  493. db = db.Where("his_order.settle_accounts_date>=?", start_time)
  494. }
  495. if end_time != 0 {
  496. db = db.Where("his_order.settle_accounts_date<=?", end_time)
  497. }
  498. db = db.Where("his_order.status = 1 AND his_order.user_org_id = ?", user_org_id)
  499. db = db.Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  500. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  501. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  502. Preload("HisPrescriptionInfo", func(db *gorm.DB) *gorm.DB {
  503. return db.Where("status = 1 AND user_org_id = ?", user_org_id).Preload("XtHisDepartment", "status = 1")
  504. })
  505. db = db.Count(&total)
  506. err = db.Limit(limit).Offset(offset).Order("ctime desc").Find(&order).Error
  507. return
  508. }
  509. func UpDatePrescriptionNumber(user_org_id int64, ids []int64, number string) (err error) {
  510. 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
  511. return
  512. }
  513. func UpDatePrescriptionOrderStatus(user_org_id int64, ids []int64) (err error) {
  514. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id in (?)", user_org_id, ids).Updates(map[string]interface{}{"order_status": 4, "mtime": time.Now().Unix()}).Error
  515. return
  516. }
  517. func UpDatePrescriptionInfoNumber(user_org_id int64, id int64, number string, record_time int64) (err error) {
  518. 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": 2, "mtime": time.Now().Unix()}).Error
  519. return
  520. }
  521. func UpDateHisPrescriptionInfoNumber(user_org_id int64, his_patient_id int64, number string, record_time int64) (err error) {
  522. 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": 2, "mtime": time.Now().Unix()}).Error
  523. return
  524. }
  525. type HisOrder struct {
  526. ID int64 `gorm:"column:id" json:"id" form:"id"`
  527. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  528. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  529. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  530. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  531. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  532. Status int64 `gorm:"column:status" json:"status" form:"status"`
  533. Number string `gorm:"column:number" json:"number" form:"number"`
  534. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  535. MedfeeSumamt float64 `gorm:"column:medfee_sumamt" json:"medfee_sumamt" form:"medfee_sumamt"`
  536. OrderStatus float64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  537. PayWay int64 `gorm:"column:pay_way" json:"pay_way" form:"pay_way"`
  538. PayPrice float64 `gorm:"column:pay_price" json:"pay_price" form:"pay_price"`
  539. PayCardNo string `gorm:"column:pay_card_no" json:"pay_card_no" form:"pay_card_no"`
  540. Certno string `gorm:"column:certno" json:"certno" form:"certno"`
  541. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  542. DiscountPrice float64 `gorm:"column:discount_price" json:"discount_price" form:"discount_price"`
  543. PreferentialPrice float64 `gorm:"column:preferential_price" json:"preferential_price" form:"preferential_price"`
  544. RealityPrice float64 `gorm:"column:reality_price" json:"reality_price" form:"reality_price"`
  545. FoundPrice float64 `gorm:"column:found_price" json:"found_price" form:"found_price"`
  546. MedicalInsurancePrice float64 `gorm:"column:medical_insurance_price" json:"medical_insurance_price" form:"medical_insurance_price"`
  547. PrivatePrice float64 `gorm:"column:private_price" json:"private_price" form:"private_price"`
  548. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  549. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  550. MedType int64 `gorm:"column:med_type" json:"med_type" form:"med_type"`
  551. IsPre int64 `gorm:"column:is_pre" json:"is_pre" form:"is_pre"`
  552. SzChargeInfo string `gorm:"column:sz_charge_info" json:"sz_charge_info" form:"sz_charge_info"`
  553. SzProjectInfo string `gorm:"column:sz_project_info" json:"sz_project_info" form:"sz_project_info"`
  554. SzMedicineInsuranceInfo string `gorm:"column:sz_medicine_insurance_info" json:"sz_medicine_insurance_info" form:"sz_medicine_insurance_info"`
  555. MzNumber string `gorm:"column:mz_number" json:"mz_number" form:"mz_number"`
  556. OrgSetlNumber string `gorm:"column:org_setl_number" json:"org_setl_number" form:"org_setl_number"`
  557. PayWays string `gorm:"column:pay_ways" json:"pay_way" form:"pay_ways"`
  558. OthDesc string `gorm:"column:oth_desc" json:"oth_desc" form:"oth_desc"`
  559. SetlDetail string `gorm:"column:setl_detail" json:"setl_detail" form:"setl_detail"`
  560. FaPiaoSn string `gorm:"column:fa_piao_sn" json:"fa_piao_sn" form:"fa_piao_sn"`
  561. //FaPiaoSn string `gorm:"column:fa_piao_sn" json:"fa_piao_sn" form:"fa_piao_sn"`
  562. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  563. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  564. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  565. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  566. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  567. IsUploadDiagnose int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
  568. IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
  569. IsUploadSuccess int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
  570. }
  571. func (HisOrder) TableName() string {
  572. return "his_order"
  573. }
  574. func GetHisOrder(user_org_id int64, number string, patient_id int64) (order HisOrder, err error) {
  575. err = readDb.Model(&HisOrder{}).Where("status = 1 AND user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  576. Preload("HisOrderInfo", "status = 1 AND user_org_id = ?", user_org_id).
  577. Preload("Patients", "status = 1 AND user_org_id = ?", user_org_id).
  578. Preload("HisPatient", "status = 1 AND user_org_id = ?", user_org_id).
  579. Preload("HisPrescriptionInfo", "status = 1 AND user_org_id = ?", user_org_id).
  580. Order("ctime desc").
  581. Find(&order).Error
  582. return
  583. }
  584. func GetHisPrescriptionThree(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  585. err = readDb.Model(&models.HisPrescription{}).
  586. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  587. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  588. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  589. }).
  590. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  591. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND batch_number=?", org_id, record_date, patient_id, number).
  592. Find(&prescription).Error
  593. return
  594. }
  595. type HisPrescriptionInfo struct {
  596. ID int64 `gorm:"column:id" json:"id" form:"id"`
  597. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  598. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  599. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  600. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  601. Status int64 `gorm:"column:status" json:"status" form:"status"`
  602. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  603. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  604. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  605. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  606. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  607. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  608. Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  609. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  610. SickHistory string `gorm:"column:sick_history" json:"sick_history" form:"sick_history"`
  611. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  612. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId,RecordDate;AssociationForeignKey:ID,RecordDate" json:"his_patient"`
  613. HisPatientCaseHistory models.HisPatientCaseHistory `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,RecordDate" json:"case_history"`
  614. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  615. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  616. PrescriptionStatus int64 `gorm:"column:prescription_status" json:"prescription_status" form:"prescription_status"`
  617. DoctorId int64 `gorm:"column:doctor_id" json:"doctor_id" form:"doctor_id"`
  618. DepartmentId int64 `gorm:"column:department_id" json:"department_id" form:"department_id"`
  619. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  620. }
  621. func (HisPrescriptionInfo) TableName() string {
  622. return "his_prescription_info"
  623. }
  624. func GetHisPrescriptionOrderList(org_id int64) (prescriptionOrder []*HisPrescriptionInfo, err error) {
  625. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ?", org_id).
  626. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  627. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  628. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).
  629. Order("ctime desc").Find(&prescriptionOrder).Error
  630. return
  631. }
  632. func GetHisPrescriptionOrderInfo(id int64, org_id int64) (prescriptionOrder HisPrescriptionInfo, err error) {
  633. err = readDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND id = ? AND user_org_id = ? ", id, org_id).
  634. Preload("Patients", "status = 1 AND user_org_id = ?", org_id).
  635. Preload("HisPatient", "status = 1 AND user_org_id = ?", org_id).
  636. Preload("HisPatientCaseHistory", "status = 1 AND user_org_id = ?", org_id).First(&prescriptionOrder).Error
  637. return
  638. }
  639. func GetHisPrescriptionFour(org_id int64, patient_id int64, record_date int64, number string) (prescription []*models.HisPrescription, err error) {
  640. err = readDb.Model(&models.HisPrescription{}).
  641. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  642. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  643. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  644. }).
  645. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND prescription_number=?", org_id, record_date, patient_id, number).
  646. Find(&prescription).Error
  647. return
  648. }
  649. func GetMedicalInsuranceConfig(org_id int64) (medicalInsuranceConfig models.MedicalInsuranceConfig, err error) {
  650. err = readDb.Model(&models.MedicalInsuranceConfig{}).Where("status = 1 AND user_org_id = ?", org_id).Find(&medicalInsuranceConfig).Error
  651. return
  652. }
  653. func UpdataOrderStatus(id int64, number string, user_org_id int64, log string, result string) (err error) {
  654. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "refund_request_log": log, "refund_log": result, "status": 0}).Error
  655. 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
  656. 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
  657. return
  658. }
  659. func UpdataOrderStatusThree(id int64, number string, user_org_id int64, log string, result string) (err error) {
  660. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND id = ? AND user_org_id = ?", id, user_org_id).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "refund_request_log": log, "refund_log": result, "status": 0}).Error
  661. 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
  662. 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
  663. return
  664. }
  665. func UpdataRegStatus(patient_id int64, record_time int64, org_id int64) {
  666. 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()})
  667. //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
  668. //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
  669. }
  670. func UpdataRegStatusTwo(his_patient_id int64, record_time int64, org_id int64) {
  671. writeDb.Model(&models.HisPatient{}).Where("status = 1 AND record_date =? AND user_org_id = ? AND id = ?", record_time, org_id, his_patient_id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()})
  672. writeDb.Model(&models.HisPrescription{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", org_id, his_patient_id).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  673. writeDb.Model(&models.HisPrescriptionInfo{}).Where("status = 1 AND user_org_id = ? AND his_patient_id = ?", org_id, his_patient_id).Updates(map[string]interface{}{"his_patient_id": 0, "mtime": time.Now().Unix()})
  674. }
  675. func UpdataRegStatus2(id int64) error {
  676. err := writeDb.Model(&models.HisPatient{}).Where("id = ?", id).Updates(map[string]interface{}{"status": 0, "mtime": time.Now().Unix()}).Error
  677. return err
  678. }
  679. func GetAdminUserInfoByID(org_id int64, admin_user_id int64) (role models.UserAdminRole, err error) {
  680. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
  681. return
  682. }
  683. func GetAdminUserInfo(org_id int64) (role models.UserAdminRole, err error) {
  684. err = readUserDb.Model(&models.UserAdminRole{}).Where("org_id = ? AND status = 1", org_id).First(&role).Error
  685. return
  686. }
  687. func GetHisOrderTwo(user_org_id int64, number string, patient_id int64) (order models.HisOrder, err error) {
  688. err = readDb.Model(&HisOrder{}).Where("user_org_id = ? AND patient_id = ? AND number=?", user_org_id, patient_id, number).
  689. First(&order).Error
  690. return
  691. }
  692. func UpDateOrder(order models.HisOrder) (err error) {
  693. err = writeDb.Save(&order).Error
  694. return
  695. }
  696. func UpDateOrderTwo(order *models.HisOrder) (err error) {
  697. err = writeDb.Save(&order).Error
  698. return
  699. }
  700. func UpdataOrderStatusTwo(number string, user_org_id int64) (err error) {
  701. 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
  702. 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
  703. return
  704. }
  705. func CreateErrMsgLog(log *models.HisOrderError) {
  706. writeDb.Model(&models.HisOrderError{}).Create(&log)
  707. }
  708. func FindHisRegisterRecord(record_time int64, patient_id int64, org_id int64) (total int64, err error) {
  709. 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
  710. return
  711. }
  712. func FindMedicalInsuranceInfo(org_id int64) (config models.MedicalInsuranceOrgConfig, err error) {
  713. err = readDb.Model(&models.MedicalInsuranceOrgConfig{}).Where("status = 1 AND user_org_id = ?", org_id).First(&config).Error
  714. return
  715. }
  716. func FindAllSick(orgId int64) (list []*models.OutpatientServiceSick, err error) {
  717. db := readDb.Model(&models.OutpatientServiceSick{})
  718. db = db.Where("user_org_id = ? AND status = 1", orgId)
  719. err = db.Order("ctime desc").Find(&list).Error
  720. return
  721. }
  722. func FindAllDiagnose(orgId int64) (list []*models.HisXtDiagnoseConfig, err error) {
  723. db := readDb.Model(&models.HisXtDiagnoseConfig{})
  724. db = db.Where("user_org_id = ? AND status = 1", orgId)
  725. err = db.Order("ctime desc").Find(&list).Error
  726. return
  727. }
  728. func FindAllAddition(orgId int64) (list []*models.XtHisAddtionConfig, err error) {
  729. db := readDb.Model(&models.XtHisAddtionConfig{})
  730. db = db.Where("user_org_id = ? AND status = 1", orgId)
  731. err = db.Order("ctime desc").Find(&list).Error
  732. return
  733. }
  734. type XtHisOrder struct {
  735. ID int64 `gorm:"column:id" json:"id" form:"id"`
  736. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  737. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  738. SettleAccountsDate int64 `gorm:"column:settle_accounts_date" json:"settle_accounts_date" form:"settle_accounts_date"`
  739. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  740. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  741. Status int64 `gorm:"column:status" json:"status" form:"status"`
  742. Number string `gorm:"column:number" json:"number" form:"number"`
  743. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  744. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  745. Modify int64 `gorm:"column:modify" json:"modify" form:"modify"`
  746. PayWays string `gorm:"column:pay_ways" json:"pay_way" form:"pay_ways"`
  747. OthDesc string `gorm:"column:oth_desc" json:"oth_desc" form:"oth_desc"`
  748. FaPiaoCode string `gorm:"column:fa_piao_code" json:"fa_piao_code" form:"fa_piao_code"`
  749. FaPiaoNumber string `gorm:"column:fa_piao_number" json:"fa_piao_number" form:"fa_piao_number"`
  750. HisOrderInfo models.HisOrderInfo `gorm:"ForeignKey:ID;AssociationForeignKey:OrderId" json:"order_info"`
  751. Patients models.Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  752. HisPatient models.HisPatient `gorm:"ForeignKey:HisPatientId;AssociationForeignKey:ID" json:"his_patient"`
  753. HisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,SettleAccountsDate;AssociationForeignKey:PatientId,RecordDate" json:"p_info"`
  754. HisPrescription []*models.HisPrescription `gorm:"ForeignKey:SettleAccountsDate;AssociationForeignKey:RecordDate" json:"prescriptions"`
  755. IsUploadDiagnose int64 `gorm:"column:is_upload_diagnose" json:"is_upload_diagnose" form:"is_upload_diagnose"`
  756. IsUploadOrderInfo int64 `gorm:"column:is_upload_order_info" json:"is_upload_order_info" form:"is_upload_order_info"`
  757. IsUploadSuccess int64 `gorm:"column:is_upload_success" json:"is_upload_success" form:"is_upload_success"`
  758. }
  759. func (XtHisOrder) TableName() string {
  760. return "his_order"
  761. }
  762. func GetHisPrescriptionNight(org_id int64, patient_id int64, record_date int64, prescription_id int64) (prescription []*models.HisPrescription, err error) {
  763. err = readDb.Model(&models.HisPrescription{}).
  764. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ? and prescription_id =?", org_id, prescription_id).
  765. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  766. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  767. }).
  768. Preload("HisAdditionalCharge", "status = 1 AND user_org_id = ?", org_id).
  769. Where("user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ?", org_id, record_date, patient_id).
  770. Find(&prescription).Error
  771. return
  772. }
  773. func GetAllAdditionCharge(org_id int64, patient_id int64, record_time int64) (addition []*models.HisAdditionalCharge, err error) {
  774. 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
  775. return
  776. }
  777. func DelelteAddition(id int64, user_org_id int64) (err error) {
  778. 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
  779. return
  780. }
  781. func GetHisPatientPrescriptionList(org_id int64, keywords string, record_date int64, page int64, limit int64) (patients []*Schedule, err error, total int64) {
  782. offset := (page - 1) * limit
  783. db := readDb.Model(&Schedule{}).Where("user_org_id = ? AND status = 1 AND schedule_date = ?", org_id, record_date)
  784. if len(keywords) > 0 {
  785. keywords = "%" + keywords + "%"
  786. 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)
  787. 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 ?", org_id, record_date, keywords)
  788. }
  789. db = db.Preload("Patients", "user_org_id = ? AND status = 1", org_id)
  790. db = db.Preload("HisPatient", "user_org_id = ? AND status = 1", org_id)
  791. db = db.Preload("HisPrescription", "user_org_id = ? AND status = 1", org_id).
  792. Preload("VMHisPrescriptionInfo", "user_org_id = ? AND status = 1", org_id)
  793. db = db.Count(&total)
  794. err = db.Limit(limit).Offset(offset).Find(&patients).Error
  795. return
  796. }
  797. func UpdateHisPatientIsReturn(patientid int64, recorddate int64, orgid int64) (models.VMHisPatient, error) {
  798. patient := models.VMHisPatient{}
  799. 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
  800. return patient, err
  801. }
  802. type VMOtherHisPrescriptionInfo struct {
  803. ID int64 `gorm:"column:id" json:"id" form:"id"`
  804. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  805. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  806. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  807. Status int64 `gorm:"column:status" json:"status" form:"status"`
  808. CheckGroup []int64 `gorm:"-" json:"check_group" form:"check_group"`
  809. VMHisPrescription []*VMHisPrescription `gorm:"ForeignKey:RecordDate,PatientId;AssociationForeignKey:RecordDate,PatientId" json:"prescriptions"`
  810. }
  811. func (VMOtherHisPrescriptionInfo) TableName() string {
  812. return "his_prescription_info"
  813. }
  814. type VMHisPrescription struct {
  815. ID int64 `gorm:"column:id" json:"id" form:"id"`
  816. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  817. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  818. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  819. Status int64 `gorm:"column:status" json:"status" form:"status"`
  820. OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  821. BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  822. PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  823. Type int64 `gorm:"column:type" json:"type" form:"type"`
  824. HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"doctor_advice"`
  825. HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  826. }
  827. func (VMHisPrescription) TableName() string {
  828. return "his_prescription"
  829. }
  830. func GetCallHisPrescriptions(start_time int64, end_time int64, org_id int64, patient_id int64) (advice []*VMOtherHisPrescriptionInfo, err error) {
  831. 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).
  832. Preload("VMHisPrescription", func(db *gorm.DB) *gorm.DB {
  833. return db.Where("status = 1 AND user_org_id = ?", org_id).
  834. Preload("HisDoctorAdviceInfo", "status = 1 AND user_org_id = ?", org_id).
  835. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  836. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  837. })
  838. }).Find(&advice).Error
  839. return
  840. }
  841. func GetHisOrderByID(order_id int64) (order models.HisOrder, err error) {
  842. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  843. return
  844. }
  845. func GetFaPiaoHisOrderByID(order_id int64) (order models.HisFaPiaoOrder, err error) {
  846. str := strconv.FormatInt(order_id, 10)
  847. key := "%" + str + "%"
  848. err = readDb.Model(&models.HisFaPiaoOrder{}).Where("order_ids like ? and status = 1", key).First(&order).Error
  849. return
  850. }
  851. func GetHisOrderByIDTwo(order_id int64) (order models.HisOrder, err error) {
  852. err = readDb.Model(&models.HisOrder{}).Preload("HisOrderInfo", "status = 1").Preload("HisPatient", "status = 1").Where("id = ? AND status = 1", order_id).First(&order).Error
  853. return
  854. }
  855. func GetHisOrderInfoByNumber(order_number string) (order []*models.HisOrderInfo, err error) {
  856. db := readDb.Model(&models.HisOrderInfo{}).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  857. return db.Preload("BaseDrugLib", "status = 1").Where("status = 1")
  858. })
  859. err = db.Where("order_number = ? AND status = 1 AND advice_id > 0", order_number).Find(&order).Error
  860. return
  861. }
  862. func GetHisOrderInfoByNumberTwo(order_number string) (order []*models.HisOrderInfo, err error) {
  863. db := readDb.Model(&models.HisOrderInfo{})
  864. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id")
  865. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  866. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  867. })
  868. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  869. return
  870. }
  871. func GetHisOrderInfoByNumberThree(order_number string) (order []*models.HisOrderInfo, err error) {
  872. db := readDb.Model(&models.HisOrderInfo{})
  873. //db = db.Joins("Join his_prescription_project as p On p.id = his_order_info.project_id AND p.team_id > 0")
  874. db = db.Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  875. return db.Preload("XtHisProjectTeam", "status = 1").Preload("HisProject", "status = 1").Preload("GoodInfo", "status = 1").Where("status = 1")
  876. })
  877. err = db.Where("order_number = ? AND status = 1 AND project_id > 0", order_number).Find(&order).Error
  878. return
  879. }
  880. func GetOrderByTime(start_time int64, end_time int64, org_id int64, insutype string, clr_org string, clr_type string, mdtrtareaAdmvs string) (orders []*models.HisOrder, err error) {
  881. db := readDb.Model(&models.HisOrder{})
  882. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype)
  883. if len(clr_org) > 0 {
  884. db = db.Where("clr_optins = ?", clr_org)
  885. }
  886. if len(clr_type) > 0 {
  887. if mdtrtareaAdmvs == "150499" {
  888. if clr_type == "11" {
  889. db = db.Where("clr_type = ?", clr_type)
  890. }
  891. } else {
  892. db = db.Where("clr_type = ?", clr_type)
  893. }
  894. } else {
  895. if len(clr_type) == 0 {
  896. db = db.Where("clr_type = ?", "")
  897. } else {
  898. db = db.Where("clr_type = ?", "9903")
  899. }
  900. }
  901. err = db.Find(&orders).Error
  902. return
  903. }
  904. func GetOrderByTimeFive(start_time int64, end_time int64, org_id int64, insutype string, clr_org string, clr_type string, mdtrtareaAdmvs string) (orders []*models.HisOrder, err error) {
  905. db := readDb.Model(&models.HisOrder{})
  906. db = db.Where("user_org_id = ? AND order_status = 3 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype)
  907. if len(clr_org) > 0 {
  908. db = db.Where("clr_optins = ?", clr_org)
  909. }
  910. if len(clr_type) > 0 {
  911. if mdtrtareaAdmvs == "150499" {
  912. if clr_type == "11" {
  913. db = db.Where("clr_type = ?", clr_type)
  914. }
  915. } else {
  916. db = db.Where("clr_type = ?", clr_type)
  917. }
  918. }
  919. err = db.Find(&orders).Error
  920. return
  921. }
  922. func GetOrderByTimeFour(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  923. db := readDb.Model(&models.HisOrder{})
  924. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? ", org_id, end_time, start_time)
  925. err = db.Find(&orders).Error
  926. return
  927. }
  928. func GetOrderByTimeTenaaa(start_time int64, end_time int64, org_id int64, org string) (orders []*models.HisOrder, err error) {
  929. db := readDb.Model(&models.HisOrder{})
  930. db = db.Where("clr_options = ? and user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? ", org, org_id, end_time, start_time)
  931. err = db.Find(&orders).Error
  932. return
  933. }
  934. func GetOrderByTime11222(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  935. db := readDb.Model(&models.HisOrder{})
  936. db = db.Where("psn_name = '付云芳' and user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ?", org_id, end_time, start_time)
  937. err = db.Find(&orders).Error
  938. return
  939. }
  940. func GetOrderByTimeFourfor11(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  941. db := readDb.Model(&models.HisOrder{})
  942. db = db.Where("user_org_id = ? AND status = 1 AND order_status = 2 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? and med_type = 11", org_id, end_time, start_time)
  943. err = db.Find(&orders).Error
  944. return
  945. }
  946. func GetOrderByTimeThree(start_time int64, end_time int64, org_id int64, insutype string, clr_type string) (orders []*models.HisOrder, err error) {
  947. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ? AND insutype = ?", org_id, end_time, start_time, insutype).Find(&orders).Error
  948. return
  949. }
  950. func GetOrderByTimeTwo(start_time int64, end_time int64, org_id int64) (orders []*models.HisOrder, err error) {
  951. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND is_medicine_insurance = 1 AND UNIX_TIMESTAMP(setl_time) <= ? AND UNIX_TIMESTAMP(setl_time) >= ?", org_id, end_time, start_time).Find(&orders).Error
  952. return
  953. }
  954. func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
  955. var patient models.Patients
  956. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  957. if err != nil {
  958. if err == gorm.ErrRecordNotFound {
  959. return nil, nil
  960. } else {
  961. return nil, err
  962. }
  963. }
  964. return &patient, nil
  965. }
  966. func FindDiagnoseById(id int64) (models.HisXtDiagnoseConfig, error) {
  967. dealer := models.HisXtDiagnoseConfig{}
  968. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? and status = 1", id).First(&dealer).Error
  969. return dealer, err
  970. }
  971. func FindDiagnoseByIdtwo(id string) (models.HisXtDiagnoseConfig, error) {
  972. dealer := models.HisXtDiagnoseConfig{}
  973. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id = ? and status = 1", id).First(&dealer).Error
  974. return dealer, err
  975. }
  976. func FindDiagnoseByIds(ids []string) ([]*models.HisXtDiagnoseConfig, error) {
  977. dealer := []*models.HisXtDiagnoseConfig{}
  978. err := readDb.Model(&models.HisXtDiagnoseConfig{}).Where("id IN (?) AND status = 1", ids).Find(&dealer).Error
  979. return dealer, err
  980. }
  981. func FindSickById(id int64) (*models.OutpatientServiceSick, error) {
  982. outPatient := &models.OutpatientServiceSick{}
  983. err := readDb.Model(&models.OutpatientServiceSick{}).Where("id = ? AND status = 1", id).First(&outPatient).Error
  984. return outPatient, err
  985. }
  986. //
  987. //type MonthHisPrescription struct {
  988. // ID int64 `gorm:"column:id" json:"id" form:"id"`
  989. // UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  990. // RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  991. // PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  992. // HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  993. // Status int64 `gorm:"column:status" json:"status" form:"status"`
  994. // Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  995. // Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  996. // Number string `gorm:"column:number" json:"number" form:"number"`
  997. // Type int64 `gorm:"column:type" json:"type" form:"type"`
  998. // Doctor string `gorm:"column:doctor" json:"doctor" form:"doctor"`
  999. // Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1000. // Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1001. // OrderStatus int64 `gorm:"column:order_status" json:"order_status" form:"order_status"`
  1002. // BatchNumber string `gorm:"column:batch_number" json:"batch_number" form:"batch_number"`
  1003. // PrescriptionNumber string `gorm:"column:prescription_number" json:"prescription_number" form:"prescription_number"`
  1004. // Patients Patients `gorm:"ForeignKey:PatientId;AssociationForeignKey:ID" json:"patient"`
  1005. // HisPatient models.VMHisPatient `gorm:"ForeignKey:PatientId;AssociationForeignKey:patient_id" json:"hisPatient"`
  1006. // HisDoctorAdviceInfo []*models.HisDoctorAdviceInfo `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1007. // HisPrescriptionProject []*models.HisPrescriptionProject `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1008. // HisAdditionalCharge []*models.HisAdditionalCharge `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"addition"`
  1009. // VMHisPrescriptionInfo models.HisPrescriptionInfo `gorm:"ForeignKey:PatientId,RecordDate;AssociationForeignKey:PatientId,ScheduleDate" json:"info"`
  1010. //}
  1011. //
  1012. //func (MonthHisPrescription) TableName() string {
  1013. // return "his_prescription"
  1014. //}
  1015. func GetMonthHisPrescription(org_id int64, patient_id int64, start_time int64, end_time int64, reg_type string) (prescription []*models.HisPrescription, err error) {
  1016. err = readDb.Model(&models.HisPrescription{}).
  1017. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1018. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1019. }).
  1020. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1021. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1022. }).
  1023. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1024. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1025. }).
  1026. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND status = 1 AND p_type <> 1 AND med_type = ?", org_id, start_time, end_time, patient_id, reg_type).
  1027. Find(&prescription).Error
  1028. return
  1029. }
  1030. func GetPatientByNumber(number string, user_org_id int64) (patient Patients, err error) {
  1031. err = readDb.Model(&Patients{}).Where("(health_care_no = ? OR id_card_no = ?) AND user_org_id = ?", number, number, user_org_id).First(&patient).Error
  1032. return
  1033. }
  1034. func GetPatientByIDCard(id_card_no string, user_org_id int64) (patient Patients, err error) {
  1035. err = readDb.Model(&Patients{}).Where("(health_care_no = ? or id_card_no = ?) AND user_org_id = ?", id_card_no, id_card_no, user_org_id).First(&patient).Error
  1036. return
  1037. }
  1038. func GetHisOrderThree(record_time int64, patient_id int64, user_org_id int64) (order models.HisOrder, err error) {
  1039. 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
  1040. return
  1041. }
  1042. func GetAppRole(orgID int64) (models.App_Role, error) {
  1043. var appRole models.App_Role
  1044. err := readUserDb.Model(models.App_Role{}).Where("org_id = ? AND user_type = 2", orgID).First(&appRole).Error
  1045. return appRole, err
  1046. }
  1047. func GetPatientByIDTwo(orgID int64, patientID int64) (Patients, error) {
  1048. var patient Patients
  1049. err := readDb.Model(&Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  1050. return patient, err
  1051. }
  1052. func GetDrugList(orgID int64) (drug []*models.BaseDrugList, err error) {
  1053. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1054. table := XTReadDB().Table("xt_manufacturer as m")
  1055. fmt.Print(table)
  1056. if orgID > 0 {
  1057. db = db.Where("x.org_id = ? and x.id = 397", orgID)
  1058. }
  1059. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&drug).Error
  1060. return drug, err
  1061. }
  1062. func GetDrugDosageForm(orgid int64) (dataconfig []*models.XtDrugDataConfig, err error) {
  1063. err = XTReadDB().Where("(org_id = ? or org_id = 0) and parent_id = 4 and status = 1", orgid).Find(&dataconfig).Error
  1064. return dataconfig, err
  1065. }
  1066. func GetDoctorList(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1067. //err = UserReadDB().Model(&role).Where("org_id = ? and status = 1 and user_type = 2", orgid).Find(&role).Error
  1068. //return role, err
  1069. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1070. table := UserReadDB().Table("sgj_user_admin as a")
  1071. fmt.Println(table)
  1072. err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.age,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1073. return role, err
  1074. }
  1075. func GetPrescriptionByIds(ids []string, org_id int64) (prescription []*models.HisPrescription, err error) {
  1076. err = readDb.Model(&models.HisPrescription{}).
  1077. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1078. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1079. }).
  1080. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1081. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1082. }).
  1083. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1084. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject").Preload("GoodInfo", "status=1")
  1085. }).
  1086. Where("id in (?) AND user_org_id = ? AND status = 1", ids, org_id).
  1087. Find(&prescription).Error
  1088. return
  1089. }
  1090. func GetDoctorListTwo(orgid int64) (role []*models.SgjUserAdminRole, err error) {
  1091. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1 AND x.user_type = 2 AND x.org_id = ?", orgid)
  1092. //table := UserReadDB().Table("sgj_user_admin as a")
  1093. //fmt.Println(table)
  1094. err = db.Select("x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.age,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1095. return role, err
  1096. }
  1097. func GetRoleList(orgid int64) (role []*models.SgjUserRole, err error) {
  1098. err = UserReadDB().Model(&role).Where("org_id = ? and status =1", orgid).Find(&role).Error
  1099. return role, err
  1100. }
  1101. func GetDrugListByDetail(orgID int64, id int64) (drug []*models.BaseDrugList, err error) {
  1102. db := XTReadDB().Table("xt_base_drug as x").Where("x.status = 1")
  1103. table := XTReadDB().Table("xt_manufacturer as m")
  1104. fmt.Print(table)
  1105. if orgID > 0 {
  1106. db = db.Where("x.org_id = ? and x.id = ?", orgID, id)
  1107. }
  1108. err = db.Select("x.id,x.medical_insurance_number,x.code,x.drug_name,x.drug_spec,x.drug_type,x.min_unit,x.last_price,x.retail_price,x.limit_remark,x.drug_dosage_form,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&drug).Error
  1109. return drug, err
  1110. }
  1111. func GetGoodInformationList(orgid int64) (good []*models.GoodInformation, err error) {
  1112. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1113. table := XTReadDB().Table("xt_manufacturer as m")
  1114. fmt.Println(table)
  1115. if orgid > 0 {
  1116. db = db.Where("x.org_id = ?", orgid)
  1117. }
  1118. err = db.Select("x.id,x.social_security_directory_code,x.good_name,x.specification_name,x.production_type,x.special_medical,x.good_unit,x.buy_price,x.sell_price,x.remark,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&good).Error
  1119. return good, err
  1120. }
  1121. func GetGoodListByDetail(orgid int64, id int64) (good []*models.GoodInformation, err error) {
  1122. db := XTReadDB().Table("xt_good_information as x").Where("x.status=1")
  1123. table := XTReadDB().Table("xt_manufacturer as m")
  1124. fmt.Println(table)
  1125. if orgid > 0 {
  1126. db = db.Where("x.org_id = ? and x.id= ?", orgid, id)
  1127. }
  1128. err = db.Select("x.id,x.social_security_directory_code,x.good_name,x.specification_name,x.production_type,x.special_medical,x.good_unit,x.buy_price,x.sell_price,x.remark,m.manufacturer_name").Joins("left join xt_manufacturer as m on m.id = x.manufacturer").Scan(&good).Error
  1129. return good, err
  1130. }
  1131. func GetDoctorListByDetail(orgid int64, id int64) (role []*models.SgjUserAdminRole, err error) {
  1132. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1133. table := UserReadDB().Table("sgj_user_admin as a")
  1134. fmt.Println(table)
  1135. if id > 0 {
  1136. db = db.Where("x.status = 1 and x.admin_user_id = ? and x.org_id = ?", id, orgid)
  1137. }
  1138. err = db.Select("x.age,x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1139. return role, err
  1140. }
  1141. func GetMyPorjecgList(orgid int64) (project []*models.MyHisProject, err error) {
  1142. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1", orgid).Find(&project).Error
  1143. return project, err
  1144. }
  1145. func GetMyPorjecgListDetail(orgid int64, id int64) (project []*models.MyHisProject, err error) {
  1146. err = XTReadDB().Model(&project).Where("user_org_id = ? and status = 1 and id = ?", orgid, id).Find(&project).Error
  1147. return project, err
  1148. }
  1149. func GetBathchMyPorjecgList(idss []int64) (project []*models.MyHisProject, err error) {
  1150. db := XTReadDB().Table("xt_his_project")
  1151. if len(idss) == 1 {
  1152. err = db.Where("status = 1 and id = ?", idss[0]).Find(&project).Error
  1153. } else {
  1154. err = db.Where("status = 1 and id IN(?)", idss).Find(&project).Error
  1155. }
  1156. return project, err
  1157. }
  1158. func GetBathchMyPorjecgListtwo(org_id int64) (project []*models.MyHisProject, err error) {
  1159. db := XTReadDB().Table("xt_his_project")
  1160. err = db.Where("status = 1 and user_org_id = ?", org_id).Find(&project).Error
  1161. return project, err
  1162. }
  1163. func GetBatchDoctorList(idss []int64) (role []*models.SgjUserAdminRole, err error) {
  1164. db := UserReadDB().Table("sgj_user_admin_role as x").Where("x.status =1")
  1165. table := UserReadDB().Table("sgj_user_admin as a")
  1166. fmt.Println(table)
  1167. if len(idss) == 1 {
  1168. db = db.Where("x.status = 1 and x.admin_user_id = ?", idss[0])
  1169. } else {
  1170. db = db.Where("x.status = 1 and x.admin_user_id IN(?)", idss)
  1171. }
  1172. err = db.Select("x.age,x.id,x.admin_user_id,x.org_id,x.app_id,x.role_id,x.user_name,x.avatar,x.user_type,x.user_title,x.intro,x.user_title_name,x.role_ids,x.message,x.sex,x.birthday,x.sort,x.is_sort,x.department,x.department_id,x.nation,x.card_type,x.id_card,x.education,x.study_major_name,x.work_major_name,x.role_type,x.medical_code,x.doctor_code,x.licensing,x.job_number,x.prescription_qualification_identification,x.identification_outpatients,x.start_time,x.medical_range_code,x.medical_level,x.medical_type_job,x.pharmacist_registration_number,x.doctor_range_code,x.doctor_level,x.doctor_type_job,x.doctor_number,x.outpatient_illness_category,x.is_active,x.active_status,a.mobile").Joins("left join sgj_user_admin as a on a.id = x.admin_user_id").Scan(&role).Error
  1173. return role, err
  1174. }
  1175. func GetAllPatient(org_id int64) (patients []*models.Patients, err error) {
  1176. err = readDb.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", org_id).Find(&patients).Error
  1177. return
  1178. }
  1179. func UpdateHisPrescriptionHisID(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  1180. XTWriteDB().Model(&models.HisPrescription{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1181. XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1182. return
  1183. }
  1184. func UpdateHisPrescriptionHisIDTwo(his_patient_id int64, patient_id int64, record_time int64, org_id int64, start_time int64) {
  1185. XTWriteDB().Model(&models.HisPrescription{}).Where("record_date <= ? AND record_date >= ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0 AND order_status <> 2", record_time, start_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1186. XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0 AND order_status <> 2", record_time, start_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1187. return
  1188. }
  1189. func UpdateHisPrescriptionHisID1111(his_patient_id int64, patient_id int64, record_time int64, org_id int64) {
  1190. //XTWriteDB().Model(&models.HisPrescription{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1191. //XTWriteDB().Model(&models.HisPrescriptionInfo{}).Where("record_date = ? AND user_org_id = ? AND patient_id = ? AND his_patient_id = 0", record_time, org_id, patient_id).Updates(map[string]interface{}{"his_patient_id": his_patient_id})
  1192. return
  1193. }
  1194. func GetHisPatientInfoList(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1195. 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
  1196. return
  1197. }
  1198. func GetHisPatientByNumber(number string) (his models.HisPatient, err error) {
  1199. err = readDb.Model(&models.HisPatient{}).Where("number = ? AND status = 1", number).First(&his).Error
  1200. return
  1201. }
  1202. func GetNewHisPrescriptionByNumber(number string) (pre models.HisPrescription, err error) {
  1203. err = readDb.Model(&models.HisPrescription{}).Where("batch_number = ? AND status = 1", number).First(&pre).Error
  1204. return
  1205. }
  1206. func CreateUploadRecord(result *models.HisFundSettleListResult) (err error) {
  1207. err = writeDb.Create(&result).Error
  1208. return
  1209. }
  1210. func GetUploadRecord(order_id int64) (result models.HisFundSettleListResult, err error) {
  1211. err = readDb.Model(&models.HisFundSettleListResult{}).Where("order_id = ? AND status = 1", order_id).First(&result).Error
  1212. return
  1213. }
  1214. func UpdateRecord(result *models.HisFundSettleListResult) (err error) {
  1215. err = writeDb.Save(&result).Error
  1216. return
  1217. }
  1218. func GetDeviceNumberByID(bed_id int64, org_id int64) (device_number models.DeviceNumber, err error) {
  1219. err = readDb.Model(&models.DeviceNumber{}).Where("id = ? AND org_id = ?", bed_id, org_id).First(&device_number).Error
  1220. return
  1221. }
  1222. func UpdateHisPatientStatus(his *models.VMHisPatient) {
  1223. writeDb.Save(&his)
  1224. }
  1225. func UpdateHisPatient123(his *Patients) {
  1226. writeDb.Save(&his)
  1227. }
  1228. func GetLastHisOrder(org_id int64) (his models.HisOrder, err error) {
  1229. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND fa_piao_code <> '' AND fa_piao_number <> ''", org_id).Last(&his).Error
  1230. return
  1231. }
  1232. func GetLastHisOrderTwo(org_id int64) (his models.HisOrder, err error) {
  1233. err = readDb.Model(&models.HisOrder{}).Select("max(convert(fa_piao_number,signed)) as fa_piao_number").Where("user_org_id = ? AND status = 1 AND order_status = 2 ", org_id).Find(&his).Error
  1234. return
  1235. }
  1236. func GetHisPatientInfoTwo(org_id int64, patient_id int64, record_date int64) (info []*models.HisPatient, err error) {
  1237. 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
  1238. return
  1239. }
  1240. func GetNewHisOrderTwo(user_org_id int64, mdtrt_id string, patient_id int64, record_time int64) (order HisOrder, err error) {
  1241. 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).
  1242. Order("ctime desc").
  1243. Find(&order).Error
  1244. return
  1245. }
  1246. func GetNewHisOrderThree(mdtrt_id string) (order HisOrder, err error) {
  1247. err = readDb.Model(&HisOrder{}).Where("status = 1 AND mdtrt_id=? ", mdtrt_id).First(&order).Error
  1248. return
  1249. }
  1250. func UpdateHisPatientThree(his *models.HisPatient) {
  1251. writeDb.Save(&his)
  1252. }
  1253. func GetNewHisPrescriptionTwo(org_id int64, his_patient_id int64, record_date int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1254. err = readDb.Model(&models.HisPrescription{}).
  1255. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1256. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1257. }).
  1258. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1259. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1260. }).
  1261. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1262. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1263. }).
  1264. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND order_status <> 2 AND p_type <> 1 AND med_type = ?", org_id, record_date, his_patient_id, med_type).
  1265. Find(&prescription).Error
  1266. return
  1267. }
  1268. func GetMonthHisPrescriptionTwo(org_id int64, patient_id int64, start_time int64, end_time int64, med_type int64) (prescription []*models.HisPrescription, err error) {
  1269. err = readDb.Model(&models.HisPrescription{}).
  1270. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1271. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1272. }).
  1273. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1274. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1275. }).
  1276. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1277. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1278. }).
  1279. Where("user_org_id = ? AND record_date >= ? AND record_date <= ? AND patient_id = ? AND order_status <> 2 AND status = 1 AND p_type <> 1 AND med_type = ?", org_id, start_time, end_time, patient_id, med_type).
  1280. Find(&prescription).Error
  1281. return
  1282. }
  1283. func GetNewHisPatientInfoFour(org_id int64, id int64) (info models.HisPatient, err error) {
  1284. err = readDb.Model(&models.HisPatient{}).Where("user_org_id = ? AND status = 1 AND id = ?", org_id, id).First(&info).Error
  1285. return
  1286. }
  1287. func GetTodayHisOrder(org_id int64, patient_id int64, record_time int64, number string) (order models.HisOrder, err error) {
  1288. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND patient_id = ? AND settle_accounts_date = ? AND order_status = 1 AND mdtrt_id = ?", org_id, patient_id, record_time, number).First(&order).Error
  1289. return
  1290. }
  1291. func GetLastFundList(org_id int64) (order models.HisFundSettleListResult, err error) {
  1292. err = readDb.Model(&models.HisFundSettleListResult{}).Where("user_org_id = ? AND status = 1 ", org_id).Last(&order).Error
  1293. return
  1294. }
  1295. func GetOrderError(org_id int64) (order []*models.HisOrderError, err error) {
  1296. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = ? AND status = 1 AND stage = 10106 ", org_id).Find(&order).Error
  1297. return
  1298. }
  1299. func GetOrderCountByNumber(org_id int64, patient_id int64, record_time int64, number string) (count int64, err error) {
  1300. 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
  1301. return
  1302. }
  1303. func CreateHisPsn(psn *models.HisPsn) {
  1304. writeDb.Save(&psn)
  1305. }
  1306. func GetPsnByPatientId(patient_id int64) (psn models.HisPsn, err error) {
  1307. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1308. return
  1309. }
  1310. func GetPsnByPatientIdtWO(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1311. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ?", patient_id, record_date).Last(&psn).Error
  1312. return
  1313. }
  1314. func GetHisPatientByPatientId(patient_id int64) (psn models.HisPatient, err error) {
  1315. err = readDb.Model(&models.HisPatient{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1316. return
  1317. }
  1318. //func GetPsnByPatientIdTwo(patient_id int64, record_date int64) (psn models.HisPsn, err error) {
  1319. // err = readDb.Model(&models.HisPsn{}).Where("patient_id = ? AND record_date = ? AND stage = 1", patient_id, record_date).Last(&psn).Error
  1320. // return
  1321. //}
  1322. func GetPsnByPatientIdTwo(patient_id int64) (psn models.HisPsn, err error) {
  1323. err = readDb.Model(&models.HisPsn{}).Where("patient_id = ?", patient_id).Last(&psn).Error
  1324. return
  1325. }
  1326. func GetAllHisOrder(org_id int64) (his []*models.HisOrder, err error) {
  1327. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND setl_time >= '2022-12-15 00:00:00'", org_id).Order("setl_time asc").Find(&his).Error
  1328. fmt.Println(err)
  1329. return
  1330. }
  1331. func GetAllHisOrderTwo(org_id int64) (his []*models.HisOrder, err error) {
  1332. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = ? AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND id >= 247903", org_id).Order("setl_time asc").Find(&his).Error
  1333. fmt.Println(err)
  1334. return
  1335. }
  1336. func GetAllHisOrder10106(org_id int64) (his []*models.HisOrder, err error) {
  1337. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10106 AND status = 1 AND order_status = 2 AND setl_id <> '' AND med_type = '14' AND setl_time >= '2023-08-01 00:00:00' AND setl_time <= '2023-08-31 23:59:00'").Order("setl_time asc").Find(&his).Error
  1338. fmt.Println(err)
  1339. return
  1340. }
  1341. func GetAllHisOrder10138() (his []*models.HisOrder, err error) {
  1342. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10028 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-01-01 00:00:00' and mdtrt_id not like '%out%'").Order("setl_time asc").Find(&his).Error
  1343. fmt.Println(err)
  1344. return
  1345. }
  1346. func GetOrderError10138() (order []*models.HisOrderError, err error) {
  1347. err = readDb.Model(&models.HisOrderError{}).Where("status = 1 AND stage = 10138500").Find(&order).Error
  1348. return
  1349. }
  1350. func GetAllHisOrder10278() (his []*models.HisOrder, err error) {
  1351. err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10537 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-09-01 00:00:00' AND setl_time <= '2024-10-31 23:00:00' and mdtrt_id not like '%out%'").Order("setl_time asc").Find(&his).Error
  1352. fmt.Println(err)
  1353. return
  1354. }
  1355. func GetAllHisOrder10265() (his []*models.HisOrder, err error) {
  1356. err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10265 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-09-01 00:00:00' AND setl_time <= '2024-09-30 23:59:00'").Order("setl_time asc").Find(&his).Error
  1357. fmt.Println(err)
  1358. return
  1359. }
  1360. //func GetAllHisOrder10265() (his []*models.HisOrder, err error) {
  1361. // err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10265 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2023-09-01 00:00:00'").Order("setl_time asc").Find(&his).Error
  1362. // fmt.Println(err)
  1363. // return
  1364. //}
  1365. // func GetAllHisOrder2(org_id int64) (his []models.HisOrder, err error) {
  1366. // err = readDb.Model(&models.HisOrder{}).Where("id = 180753").Order("setl_time asc").First(&his).Error
  1367. // return
  1368. // }
  1369. func GetAllHisOrderErr10278() (his []*models.HisOrderError, err error) {
  1370. err = readDb.Model(&models.HisOrderError{}).Where("user_org_id = 10278 AND status = 1 AND stage = 10276").Find(&his).Error
  1371. return
  1372. }
  1373. func GetHisOrderInfoByNumberFour(order_number string) (order []*models.HisOrderInfo, err error) {
  1374. db := readDb.Model(&models.HisOrderInfo{})
  1375. err = db.Where("order_number = ? AND status = 1", order_number).Find(&order).Error
  1376. return
  1377. }
  1378. func UpdataOrderStatusByNumber(number string) (err error) {
  1379. err = writeDb.Model(&models.HisOrder{}).Where("status = 1 AND number = ?", number).Updates(map[string]interface{}{"order_status": 3, "mtime": time.Now().Unix(), "status": 0}).Error
  1380. return
  1381. }
  1382. func UpdataHospitalOrderStatus(number string, user_org_id int64) (err error) {
  1383. err = writeDb.Model(&models.HisOrderInfo{}).Where("status = 1 AND order_number = ? AND user_org_id = ?", number, user_org_id).Updates(map[string]interface{}{"status": 0}).Error
  1384. 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
  1385. 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
  1386. return
  1387. }
  1388. func GetHisFundSettleListResult(order_id int64) (result models.HisFundSettleListResult, err error) {
  1389. db := readDb.Model(&models.HisFundSettleListResult{})
  1390. err = db.Where("order_id = ? AND status = 1", order_id).First(&result).Error
  1391. return
  1392. }
  1393. func SaveClearRecord(record *models.HisYidiClearRecord) {
  1394. writeDb.Save(&record)
  1395. }
  1396. func GetClearRecordById(id int64) (record models.HisYidiClearRecord, err error) {
  1397. err = readDb.Model(&models.HisYidiClearRecord{}).Where("id = ? AND status = 1").First(&record).Error
  1398. return
  1399. }
  1400. func UpdateOrder(order models.HisOrder) (err error) {
  1401. err = writeDb.Save(&order).Error
  1402. return
  1403. }
  1404. func UpdateOrderTwo(order models.NewHisOrder111) (err error) {
  1405. err = writeDb.Save(&order).Error
  1406. return
  1407. }
  1408. func GetNewHisPrescriptionTen(org_id int64, his_patient_id int64, record_date int64) (prescription []*models.HisPrescriptionTen, err error) {
  1409. err = readDb.Model(&models.HisPrescriptionTen{}).
  1410. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1411. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1412. }).
  1413. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1414. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1415. }).
  1416. Where("user_org_id = ? AND status = 1 AND record_date = ? AND his_patient_id = ? AND p_type <> 1 ", org_id, record_date, his_patient_id).
  1417. Find(&prescription).Error
  1418. return
  1419. }
  1420. func GetHisOrderByIDTwo1111(order_id int64) (order models.NewHisOrder111, err error) {
  1421. err = readDb.Model(&models.HisOrder{}).Where("id = ? AND status = 1", order_id).First(&order).Error
  1422. return
  1423. }
  1424. func GetHisPrescriptionForMedType(org_id int64, patient_id int64, record_date int64) (prescription []*models.HisPrescription, err error) {
  1425. err = readDb.Model(&models.HisPrescription{}).
  1426. Preload("HisAdditionalCharge", func(db *gorm.DB) *gorm.DB {
  1427. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("XtHisAddtionConfig", "status=1")
  1428. }).
  1429. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1430. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("BaseDrugLib", "status=1")
  1431. }).
  1432. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1433. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisProject", "status=1")
  1434. }).
  1435. Where("(user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 and med_type = 148801) or (user_org_id = ? AND status = 1 AND record_date = ? AND patient_id = ? AND order_status <> 2 AND p_type <> 1 and med_type = 118801)", org_id, record_date, patient_id, org_id, record_date, patient_id).
  1436. Find(&prescription).Error
  1437. return
  1438. }
  1439. func GetOrderByTimeTen(start_time string, end_time string, org_id int64) (orders []*models.FixMonRecDetailFileIn, err error) {
  1440. err = readDb.Raw("select CASE WHEN p.`insuplc_admdvs` LIKE '%3209%' THEN CONCAT(his_order.insutype, '99', his_order.med_type, '555555') ELSE CONCAT(his_order.insutype, '99', his_order.med_type, '888888') END AS fund_key, his_order.insutype, '99' as `psn_type` , his_order.`med_type`, COUNT(DISTINCT his_order.`certno`) AS psn_cnt, count(*) as psn_time, sum(his_order.medfee_sumamt) as sumamt, sum(his_order.inscp_scp_amt) as amt, sum(his_order.fund_pay_sumamt) + sum(his_order.acct_pay) as fund FROM his_order join his_patient p on p.number = his_order.mdtrt_id where his_order.user_org_id = ? and his_order.status = 1 and his_order.order_status = 2 and his_order.setl_time >= ? and his_order.setl_time <= ? and his_order.setl_id <> '' GROUP BY fund_key", org_id, start_time+" 00:00:00", end_time+" 23:00:00").Scan(&orders).Error
  1441. return
  1442. }
  1443. func GetOrderByTimeTentwo(start_time string, end_time string, org_id int64) (orders []*models.FixMonRecDetailFileIn, err error) {
  1444. err = readDb.Raw("select CASE WHEN p.`insuplc_admdvs` LIKE '%3209%' THEN CONCAT(his_order.insutype, '99', his_order.med_type, '555555') ELSE CONCAT(his_order.insutype, '99', his_order.med_type, '888888') END AS fund_key, his_order.insutype, '99' as `psn_type` , his_order.`med_type`, COUNT(DISTINCT his_order.`certno`) AS psn_cnt, count(*) as psn_time, sum(his_order.medfee_sumamt) as sumamt, sum(his_order.inscp_scp_amt) as amt, sum(his_order.fund_pay_sumamt) + sum(his_order.acct_pay) as fund FROM his_order join his_patient p on p.number = his_order.mdtrt_id where his_order.user_org_id = ? and his_order.status = 0 and his_order.order_status = 3 and his_order.setl_time >= ? and his_order.setl_time <= ? and his_order.setl_id <> '' GROUP BY fund_key", org_id, start_time+" 00:00:00", end_time+" 23:00:00").Scan(&orders).Error
  1445. return
  1446. }
  1447. func GetOrderDetailByTimeTen(start_time string, end_time string, org_id int64, fund_key string) (fund []models.FundDetail, err error) {
  1448. err = readDb.Raw("SELECT CASE WHEN p.`insuplc_admdvs` LIKE '%3209%' THEN CONCAT(his_order.insutype, '99', his_order.med_type, '555555') ELSE CONCAT(his_order.insutype, '99', his_order.med_type, '888888') end AS fund_key, his_order.`setl_detail` FROM his_order join his_patient p on p.number = his_order.mdtrt_id where his_order.user_org_id = ? and his_order.status = 1 and his_order.order_status = 2 and his_order.setl_time >= ? and his_order.setl_time <= ? and CONCAT(his_order.insutype, '99', his_order.med_type, '555555') = ?", org_id, start_time+" 00:00:00", end_time+" 23:59:00", fund_key).Scan(&fund).Error
  1449. return
  1450. }
  1451. func Saveflow(flow models.HisPrescriptionFlow) {
  1452. writeDb.Save(&flow)
  1453. }
  1454. func Createflow(flow *models.HisPrescriptionFlow) {
  1455. writeDb.Create(&flow)
  1456. }
  1457. func GetNewHisPrescriptionTenone(org_id int64, number string) (prescription []*models.HisPrescriptionTen, err error) {
  1458. err = readDb.Model(&models.HisPrescriptionTen{}).
  1459. Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1460. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("BaseDrugLib", "status=1")
  1461. }).
  1462. Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1463. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("HisOrderInfo", "status = 1").Preload("HisProject", "status=1").Preload("GoodInfo", "status=1")
  1464. }).
  1465. Where("user_org_id = ? AND status = 1 AND batch_number = ? and order_status = 4 ", org_id, number).
  1466. Find(&prescription).Error
  1467. return
  1468. }
  1469. func GetHisOrderByIDThree(start_time string) (his []*models.HisOrder, err error) {
  1470. err = readDb.Model(&models.HisOrder{}).Where(" user_org_id = 10265 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= ?", start_time).Order("setl_time asc").Find(&his).Error
  1471. fmt.Println(err)
  1472. return
  1473. }
  1474. func UpDatePrescriptionNumber111(user_org_id int64, start_time int64, end_time int64, number string, patient_id int64) (err error) {
  1475. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND record_date >= ? and record_date <= ? and patient_id = ? and order_status = 1", user_org_id, start_time, end_time, patient_id).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  1476. return
  1477. }
  1478. func UpDatePrescriptionNumber222(user_org_id int64, id int64, number string, patient_id int64) (err error) {
  1479. err = writeDb.Model(&models.HisPrescription{}).Where("user_org_id = ? AND status = 1 AND id = ? and patient_id = ?", user_org_id, id, patient_id).Updates(map[string]interface{}{"batch_number": number, "mtime": time.Now().Unix()}).Error
  1480. return
  1481. }
  1482. func GetAllHisOrderTwo10485() (his []*models.HisOrder, err error) {
  1483. err = readDb.Model(&models.HisOrder{}).Where("user_org_id = 10485 AND status = 1 AND order_status = 2 AND setl_id <> '' AND setl_time >= '2024-01-01 00:00:00' ").Order("setl_time asc").Find(&his).Error
  1484. fmt.Println(err)
  1485. return
  1486. }
  1487. func GetNewDrugWarehouseInfo(org_id int64, id_arr []string) (newDrugWarehouse []*models.NewDrugWarehouseInfo, err error) {
  1488. readDb.Model(&models.NewDrugWarehouseInfo{}).Where("org_id = ? and status = 1 and id in (?) ", org_id, id_arr).Preload("BaseDrugLib", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&newDrugWarehouse)
  1489. return
  1490. }
  1491. func GetNewDrugWarehouseInfobytime(org_id int64, s_time int64,e_time int64 ) (newDrugWarehouse []*models.NewDrugWarehouseInfo, err error) {
  1492. readDb.Model(&models.NewDrugWarehouseInfo{}).Where("org_id = ? and status = 1 and ctime > ? and ctime < ? and drug_code <> '' ", org_id, s_time,e_time).Preload("BaseDrugLib", "status = 1").Preload("Manufacturers", "status = 1 AND org_id = ?", org_id).Preload("Dealers", "status = 1 AND org_id = ?", org_id).Find(&newDrugWarehouse)
  1493. return
  1494. }
  1495. func GetNewDrugFlowInfo(org_id int64, id_arr []string) (flows []*models.DrugFlow, err error) {
  1496. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = ? and status = 1 and id in (?)", org_id, id_arr).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1497. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1498. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1499. return
  1500. }
  1501. func GetNewDrugFlowInfoByPatient(patient_id int64, drug_id int64, time int64, org_id int64) (flows []*models.DrugFlow, err error) {
  1502. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = ? and status = 1 and id in (?) and patinet_id = ? and drug_id = ? and system_time = ?", org_id, patient_id, drug_id, time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1503. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1504. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1505. return
  1506. }
  1507. func GetNewUploadDrugFlowInfoByPatientTwo(patient_id int64, advice_id int64, time int64, org_id int64) (flows []*models.DrugFlow, err error) {
  1508. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = ? and status = 1 and id in (?) and patinet_id = ? and advice_id = ? and system_time = ? and is_sale = 1 and is_bg = 1", org_id, patient_id, advice_id, time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1509. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1510. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1511. return
  1512. }
  1513. func GetNewDrugFlowInfotwo() (flows []*models.DrugFlow, err error) {
  1514. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = 10188 and status = 1 and id >= ? and consumable_type = 3 and is_sale = 0", 2394762).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1515. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1516. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1517. return
  1518. }
  1519. func GetNewDrugFlowInfothree() (flows []*models.DrugFlow, err error) {
  1520. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = 10217 and status = 1 and id >= ? and consumable_type = 3 and is_sale = 0", 2328112).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1521. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1522. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1523. return
  1524. }
  1525. func GetNewDrugFlowInfothree123() (flows []*models.DrugFlow, err error) {
  1526. err = readDb.Model(&models.DrugFlow{}).Where("user_org_id = 10217 and status = 1 and length(drug_code) > 0 and consumable_type = 3 and is_sale = 0 and id > 2739716").Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1527. return db.Where("status = 1").Preload("BaseDrugLib", "status=1")
  1528. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1529. return
  1530. }
  1531. func GetNewDrugFlowInforTen(system_time int64,org_id int64) (flows []*models.DrugFlow, err error) {
  1532. err = readDb.Model(&models.DrugFlow{}).Joins("join his_doctor_advice_info info on info.patient_id = xt_drug_flow.patient_id and info.drug_id = xt_drug_flow.drug_id and info.record_date = xt_drug_flow.system_time").Where("xt_drug_flow.user_org_id = ? and xt_drug_flow.status = 1 and xt_drug_flow.consumable_type = 3 and xt_drug_flow.is_sale = 0 and xt_drug_flow.system_time = ?", org_id,system_time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1533. return db.Where("status = 1 and drug_code <> ''").Preload("BaseDrugLib", "status=1")
  1534. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1535. return
  1536. }
  1537. func GetNewDrugFlowInforTenone(start_system_time int64,end_system_time int64,org_id int64) (flows []*models.DrugFlow, err error) {
  1538. err = readDb.Model(&models.DrugFlow{}).Joins("join his_doctor_advice_info info on info.patient_id = xt_drug_flow.patient_id and info.drug_id = xt_drug_flow.drug_id and info.record_date = xt_drug_flow.system_time").Where("xt_drug_flow.user_org_id = ? and xt_drug_flow.status = 1 and xt_drug_flow.consumable_type = 3 and xt_drug_flow.is_sale = 0 and xt_drug_flow.system_time >= ? and xt_drug_flow.system_time <= ?", org_id,start_system_time,end_system_time).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1539. return db.Where("status = 1 and drug_code <> ''").Preload("BaseDrugLib", "status=1")
  1540. }).Preload("NewDrugWarehouseInfo", "status = 1").Find(&flows).Error
  1541. return
  1542. }
  1543. func GetHisPrescriptionByID(id int64) (pre models.HisPrescription) {
  1544. err = readDb.Model(&models.HisPrescription{}).Where("id = ? and status = 1", id).Find(&pre).Error
  1545. return
  1546. }
  1547. func GetHisOrderByNumber(number string) (order models.HisOrder) {
  1548. err = readDb.Model(&models.HisOrder{}).Where("number = ? and status = 1", number).First(&order).Error
  1549. return
  1550. }
  1551. func SaveDF(df *models.DrugFlow) (err error) {
  1552. //err = writeDb.(&df).Error
  1553. err = XTWriteDB().Model(&models.DrugFlow{}).Where("id = ? ", df.ID).Updates(map[string]interface{}{
  1554. "is_sale": df.IsSale,
  1555. "sale_date": df.SaleDate,
  1556. "bchno": df.Bchno,
  1557. //"is_change"
  1558. }).Error
  1559. return
  1560. }
  1561. func SaveDF2(df *models.DrugFlow) (err error) {
  1562. //err = writeDb.(&df).Error
  1563. err = XTWriteDB().Model(&models.DrugFlow{}).Where("id = ? ", df.ID).Updates(map[string]interface{}{
  1564. "is_change": df.IsChange,
  1565. "bg_bchno": df.BgBchno,
  1566. //"is_change"
  1567. }).Error
  1568. return
  1569. }
  1570. func GetDrugByID(drug_id int64) (drug models.BaseDrugLib, err error) {
  1571. err = readDb.Model(&models.BaseDrugLib{}).Where("id = ?", drug_id).First(&drug).Error
  1572. return
  1573. }
  1574. func GetBbx01ByTeamID(team_id int64) (team models.XtHisProjectTeam) {
  1575. err = readDb.Model(&models.XtHisProjectTeam{}).Where("id = ?", team_id).First(&team).Error
  1576. return
  1577. }
  1578. func GetHisOrderDetailByNumber(order_number string, org_id int64) (order []*HisOrderInfo, err error) {
  1579. err = readDb.Model(&HisOrderInfo{}).Where("order_number = ? AND status = 1", order_number).Preload("HisPrescriptionProject", func(db *gorm.DB) *gorm.DB {
  1580. return db.Where("status = 1 AND user_org_id = ?", org_id).Preload("VMHisPrescriptionTwo", "status = 1 AND user_org_id = ?", org_id).Preload("VMHisProject", "status = 1 AND user_org_id = ?", org_id).Preload("VMGoodInfo", "status = 1 AND org_id = ?", org_id)
  1581. }).Preload("HisDoctorAdviceInfo", func(db *gorm.DB) *gorm.DB {
  1582. 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)
  1583. }).Find(&order).Error
  1584. return
  1585. }
  1586. type HisOrderInfo struct {
  1587. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1588. OrderNumber string `gorm:"column:order_number" json:"order_number" form:"order_number"`
  1589. UploadDate int64 `gorm:"column:upload_date" json:"upload_date" form:"upload_date"`
  1590. AdviceId int64 `gorm:"column:advice_id" json:"advice_id" form:"advice_id"`
  1591. DetItemFeeSumamt float64 `gorm:"column:det_item_fee_sumamt" json:"det_item_fee_sumamt" form:"det_item_fee_sumamt"`
  1592. Cnt float64 `gorm:"column:cnt" json:"cnt" form:"cnt"`
  1593. Pric float64 `gorm:"column:pric" json:"pric" form:"pric"`
  1594. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1595. MedChrgitmType string `gorm:"column:med_chrgitm_type" json:"med_chrgitm_type" form:"med_chrgitm_type"`
  1596. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1597. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1598. ChldMedcFlag string `gorm:"column:chld_medc_flag" json:"chld_medc_flag" form:"chld_medc_flag"`
  1599. ChrgitmLv string `gorm:"column:chrgitm_lv" json:"chrgitm_lv" form:"chrgitm_lv"`
  1600. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1601. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1602. SelfpayProp float64 `gorm:"column:selfpay_prop" json:"selfpay_prop" form:"selfpay_prop"`
  1603. ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
  1604. FulamtOwnpayAmt float64 `gorm:"column:fulamt_ownpay_amt" json:"fulamt_ownpay_amt" form:"fulamt_ownpay_amt"`
  1605. HisPrescriptionProject HisPrescriptionProject `gorm:"ForeignKey:ID;AssociationForeignKey:ProjectId" json:"project"`
  1606. HisDoctorAdviceInfo HisDoctorAdviceInfo `gorm:"ForeignKey:ID;AssociationForeignKey:AdviceId" json:"advice"`
  1607. }
  1608. func (HisOrderInfo) TableName() string {
  1609. return "his_order_info"
  1610. }
  1611. type HisDoctorAdviceInfo struct {
  1612. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1613. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1614. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1615. AdviceDate int64 `gorm:"column:advice_date" json:"advice_date" form:"advice_date"`
  1616. AdviceName string `gorm:"column:advice_name" json:"advice_name" form:"advice_name"`
  1617. AdviceDesc string `gorm:"column:advice_desc" json:"advice_desc" form:"advice_desc"`
  1618. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1619. SingleDoseUnit string `gorm:"column:single_dose_unit" json:"single_dose_unit" form:"single_dose_unit"`
  1620. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1621. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1622. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1623. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1624. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1625. CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
  1626. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1627. DrugSpec float64 `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1628. DrugSpecUnit string `gorm:"column:drug_spec_unit" json:"drug_spec_unit" form:"drug_spec_unit"`
  1629. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1630. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1631. DrugId int64 `gorm:"column:drug_id" json:"drug_id" form:"drug_id"`
  1632. Drug Drug `gorm:"ForeignKey:ID;AssociationForeignKey:DrugId" json:"drug"`
  1633. IsMedicine int64 `gorm:"column:is_medicine" json:"is_medicine" form:"is_medicine"`
  1634. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1635. IsSelfDrug int64 `gorm:"column:is_self_drug" json:"is_self_drug" form:"is_self_drug"`
  1636. }
  1637. type Drug struct {
  1638. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1639. DrugName string `gorm:"column:drug_name" json:"drug_name" form:"drug_name"`
  1640. Pinyin string `gorm:"column:pinyin" json:"pinyin" form:"pinyin"`
  1641. Wubi string `gorm:"column:wubi" json:"wubi" form:"wubi"`
  1642. DrugAlias string `gorm:"column:drug_alias" json:"drug_alias" form:"drug_alias"`
  1643. DrugAliasPinyin string `gorm:"column:drug_alias_pinyin" json:"drug_alias_pinyin" form:"drug_alias_pinyin"`
  1644. DrugAliasWubi string `gorm:"column:drug_alias_wubi" json:"drug_alias_wubi" form:"drug_alias_wubi"`
  1645. DrugCategory int64 `gorm:"column:drug_category" json:"drug_category" form:"drug_category"`
  1646. DrugSpec string `gorm:"column:drug_spec" json:"drug_spec" form:"drug_spec"`
  1647. DrugType int64 `gorm:"column:drug_type" json:"drug_type" form:"drug_type"`
  1648. DrugStockLimit string `gorm:"column:drug_stock_limit" json:"drug_stock_limit" form:"drug_stock_limit"`
  1649. DrugOriginPlace string `gorm:"column:drug_origin_place" json:"drug_origin_place" form:"drug_origin_place"`
  1650. DrugDosageForm int64 `gorm:"column:drug_dosage_form" json:"drug_dosage_form" form:"drug_dosage_form"`
  1651. MedicalInsuranceLevel int64 `gorm:"column:medical_insurance_level" json:"medical_insurance_level" form:"medical_insurance_level"`
  1652. MaxUnit string `gorm:"column:max_unit" json:"max_unit" form:"max_unit"`
  1653. MinNumber int64 `gorm:"column:min_number" json:"min_number" form:"min_number"`
  1654. MinUnit string `gorm:"column:min_unit" json:"min_unit" form:"min_unit"`
  1655. Dose string `gorm:"column:dose" json:"dose" form:"dose"`
  1656. DoseUnit string `gorm:"column:dose_unit" json:"dose_unit" form:"dose_unit"`
  1657. UnitMatrixing string `gorm:"column:unit_matrixing" json:"unit_matrixing" form:"unit_matrixing"`
  1658. RetailPrice float64 `gorm:"column:retail_price" json:"retail_price" form:"retail_price"`
  1659. MinPrice float64 `gorm:"column:min_price" json:"min_price" form:"min_price"`
  1660. LastPrice float64 `gorm:"column:last_price" json:"last_price" form:"last_price"`
  1661. DrugControl int64 `gorm:"column:drug_control" json:"drug_control" form:"drug_control"`
  1662. Number string `gorm:"column:number" json:"number" form:"number"`
  1663. DrugClassify string `gorm:"column:drug_classify" json:"drug_classify" form:"drug_classify"`
  1664. DrugDose float64 `gorm:"column:drug_dose" json:"drug_dose" form:"drug_dose"`
  1665. DrugDoseUnit int64 `gorm:"column:drug_dose_unit" json:"drug_dose_unit" form:"drug_dose_unit"`
  1666. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  1667. ProvincesCode string `gorm:"column:provinces_code" json:"provinces_code" form:"provinces_code"`
  1668. Manufacturer int64 `gorm:"column:manufacturer" json:"manufacturer" form:"manufacturer"`
  1669. PharmacologyCategory int64 `gorm:"column:pharmacology_category" json:"pharmacology_category" form:"pharmacology_category"`
  1670. StatisticsCategory int64 `gorm:"column:statistics_category" json:"statistics_category" form:"statistics_category"`
  1671. Code string `gorm:"column:code" json:"code" form:"code"`
  1672. IsSpecialDiseases int64 `gorm:"column:is_special_diseases" json:"is_special_diseases" form:"is_special_diseases"`
  1673. IsRecord int64 `gorm:"column:is_record" json:"is_record" form:"is_record"`
  1674. Agent string `gorm:"column:agent" json:"agent" form:"agent"`
  1675. DrugStatus string `gorm:"column:drug_status" json:"drug_status" form:"drug_status"`
  1676. LimitRemark string `gorm:"column:limit_remark" json:"limit_remark" form:"limit_remark"`
  1677. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1678. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1679. SingleDose float64 `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1680. PrescribingNumber float64 `gorm:"column:prescribing_number" json:"prescribing_number" form:"prescribing_number"`
  1681. Label int64 `gorm:"column:label" json:"label" form:"label"`
  1682. Sort int64 `gorm:"column:sort" json:"sort" form:"sort"`
  1683. IsUseDoctorAdvice int64 `gorm:"column:is_use_doctor_advice" json:"is_use_doctor_advice" form:"is_use_doctor_advice"`
  1684. IsDefault int64 `gorm:"column:is_default" json:"is_default" form:"is_default"`
  1685. IsChargePredict int64 `gorm:"column:is_charge_predict" json:"is_charge_predict" form:"is_charge_predict"`
  1686. IsStatisticsWork int64 `gorm:"column:is_statistics_work" json:"is_statistics_work" form:"is_statistics_work"`
  1687. IsChargeUse int64 `gorm:"column:is_charge_use" json:"is_charge_use" form:"is_charge_use"`
  1688. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1689. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1690. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1691. OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
  1692. DrugCode string `gorm:"column:drug_code" json:"drug_code" form:"drug_code"`
  1693. Dealer int64 `gorm:"column:dealer" json:"dealer" form:"dealer"`
  1694. PrescriptionMark int64 `gorm:"column:prescription_mark" json:"prescription_mark" form:"prescription_mark"`
  1695. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1696. DrugRemark string `gorm:"column:drug_remark" json:"drug_remark" form:"drug_remark"`
  1697. SocialSecurityDirectoryCode string `gorm:"column:social_security_directory_code" json:"social_security_directory_code" form:"social_security_directory_code"`
  1698. DoseCode string `gorm:"column:dose_code" json:"dose_code" form:"dose_code"`
  1699. IsMark int64 `gorm:"column:is_mark" json:"is_mark" form:"is_mark"`
  1700. HospApprFlag int64 `gorm:"column:hosp_appr_flag" json:"hosp_appr_flag" form:"hosp_appr_flag"`
  1701. LmtUsedFlag int64 `gorm:"column:lmt_used_flag" json:"lmt_used_flag" form:"lmt_used_flag"`
  1702. Dosage string `gorm:"column:dosage" json:"dosage" form:"dosage"`
  1703. Unval string `gorm:"column:unval" json:"unval" form:"unval"`
  1704. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  1705. PackingPrice float64 `gorm:"column:packing_price" json:"packing_price" form:"packing_price"`
  1706. DrugDay string `gorm:"column:drug_day" json:"drug_day" form:"drug_day"`
  1707. Total float64 `gorm:"column:total" json:"total" form:"total"`
  1708. PrescribingNumberUnit string `gorm:"column:prescribing_number_unit" json:"prescribing_number_unit" form:"prescribing_number_unit"`
  1709. IsUser int64 `gorm:"column:is_user" json:"is_user" form:"is_user"`
  1710. Bck01b string `gorm:"column:bck01b" json:"bck01b" form:"bck01b"`
  1711. Bby01 string `gorm:"column:bby01" json:"bby01" form:"bby01"`
  1712. Bbx01 string `gorm:"column:bbx01" json:"bbx01" form:"bbx01"`
  1713. }
  1714. func (Drug) TableName() string {
  1715. return "xt_base_drug"
  1716. }
  1717. type VMHisProject struct {
  1718. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1719. ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
  1720. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1721. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1722. CostClassify int64 `gorm:"column:cost_classify" json:"cost_classify" form:"cost_classify"`
  1723. StatisticalClassification int64 `gorm:"column:statistical_classification" json:"statistical_classification" form:"statistical_classification"`
  1724. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1725. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1726. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1727. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1728. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1729. NumberDays string `gorm:"column:number_days" json:"number_days" form:"number_days"`
  1730. MedicalCode string `gorm:"column:medical_code" json:"medical_code" form:"medical_code"`
  1731. }
  1732. func (VMHisProject) TableName() string {
  1733. return "xt_his_project"
  1734. }
  1735. type VMGoodInfo struct {
  1736. ID int64 `gorm:"column:id" json:"id"`
  1737. SpecificationName string `gorm:"column:specification_name" json:"specification_name"`
  1738. GoodTypeId int64 `gorm:"column:good_type_id" json:"good_type_id"`
  1739. OrgId int64 `gorm:"column:org_id" json:"org_id"`
  1740. GoodName string `gorm:"column:good_name" json:"good_name" form:"good_name"`
  1741. GoodUnit int64 `gorm:"column:good_unit" json:"good_unit" form:"good_unit"`
  1742. Total float64 `gorm:"column:total" json:"total" form:"total"`
  1743. PackingUnit string `gorm:"column:packing_unit" json:"packing_unit" form:"packing_unit"`
  1744. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  1745. }
  1746. func (VMGoodInfo) TableName() string {
  1747. return "xt_good_information"
  1748. }
  1749. func (HisDoctorAdviceInfo) TableName() string {
  1750. return "his_doctor_advice_info"
  1751. }
  1752. type VMHisPatient struct {
  1753. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1754. BalanceAccountsType int64 `gorm:"column:balance_accounts_type" json:"balance_accounts_type" form:"balance_accounts_type"`
  1755. MedicalInsuranceNumber string `gorm:"column:medical_insurance_number" json:"medical_insurance_number" form:"medical_insurance_number"`
  1756. Name string `gorm:"column:name" json:"name" form:"name"`
  1757. Gender int64 `gorm:"column:gender" json:"gender" form:"gender"`
  1758. IdType int64 `gorm:"column:id_type" json:"id_type" form:"id_type"`
  1759. MedicalTreatmentType int64 `gorm:"column:medical_treatment_type" json:"medical_treatment_type" form:"medical_treatment_type"`
  1760. Birthday int64 `gorm:"column:birthday" json:"birthday" form:"birthday"`
  1761. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1762. Age float64 `gorm:"column:age" json:"age" form:"age"`
  1763. PhoneNumber string `gorm:"column:phone_number" json:"phone_number" form:"phone_number"`
  1764. IdCardNo string `gorm:"column:id_card_no" json:"id_card_no" form:"id_card_no"`
  1765. RegisterType int64 `gorm:"column:register_type" json:"register_type" form:"register_type"`
  1766. AdminUserId int64 `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
  1767. Departments int64 `gorm:"column:departments" json:"departments" form:"departments"`
  1768. IsNeedCostOfProduction int64 `gorm:"column:is_need_cost_of_production" json:"is_need_cost_of_production" form:"is_need_cost_of_production"`
  1769. RegisterCost float64 `gorm:"column:register_cost" json:"register_cost" form:"register_cost"`
  1770. TreatmentCost float64 `gorm:"column:treatment_cost" json:"treatment_cost" form:"treatment_cost"`
  1771. CostOfProduction float64 `gorm:"column:cost_of_production" json:"cost_of_production" form:"cost_of_production"`
  1772. Total float64 `gorm:"column:total" json:"total" form:"total"`
  1773. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1774. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1775. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1776. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1777. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1778. Number string `gorm:"column:number" json:"number" form:"number"`
  1779. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1780. IsReturn int64 `gorm:"column:is_return" json:"is_return" form:"is_return"`
  1781. PsnNo string `gorm:"column:psn_no" json:"psn_no" form:"psn_no"`
  1782. PsnCertType string `gorm:"column:psn_cert_type" json:"psn_cert_type" form:"psn_cert_type"`
  1783. Certno string `gorm:"column:certno" json:"certno" form:"certno"`
  1784. PsnName string `gorm:"column:psn_name" json:"psn_name" form:"psn_name"`
  1785. Gend string `gorm:"column:gend" json:"gend" form:"gend"`
  1786. Naty string `gorm:"column:naty" json:"naty" form:"naty"`
  1787. Brdy string `gorm:"column:brdy" json:"brdy" form:"brdy"`
  1788. Iinfo string `gorm:"column:iinfo" json:"iinfo" form:"iinfo"`
  1789. Idetinfo string `gorm:"column:idetinfo" json:"idetinfo" form:"idetinfo"`
  1790. IptOtpNo string `gorm:"column:ipt_otp_no" json:"ipt_otp_no" form:"ipt_otp_no"`
  1791. PType string `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1792. Diagnosis string `gorm:"column:diagnosis" json:"diagnosis" form:"diagnosis"`
  1793. SickType int64 `gorm:"column:sick_type" json:"sick_type" form:"sick_type"`
  1794. PatientInfo string `gorm:"column:patient_info" json:"patient_info" form:"patient_info"`
  1795. }
  1796. func (VMHisPatient) TableName() string {
  1797. return "his_patient"
  1798. }
  1799. type HisPrescriptionProject struct {
  1800. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1801. ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
  1802. Price float64 `gorm:"column:price" json:"price" form:"price"`
  1803. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1804. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1805. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1806. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1807. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1808. HisPatientId int64 `gorm:"column:his_patient_id" json:"his_patient_id" form:"his_patient_id"`
  1809. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1810. PrescriptionId int64 `gorm:"column:prescription_id" json:"prescription_id" form:"prescription_id"`
  1811. Count string `gorm:"column:count" json:"count" form:"count"`
  1812. FeedetlSn string `gorm:"column:feedetl_sn" json:"feedetl_sn" form:"feedetl_sn"`
  1813. MedListCodg string `gorm:"column:med_list_codg" json:"med_list_codg" form:"med_list_codg"`
  1814. SingleDose string `gorm:"column:single_dose" json:"single_dose" form:"single_dose"`
  1815. DeliveryWay string `gorm:"column:delivery_way" json:"delivery_way" form:"delivery_way"`
  1816. ExecutionFrequency string `gorm:"column:execution_frequency" json:"execution_frequency" form:"execution_frequency"`
  1817. Day string `gorm:"column:day" json:"day" form:"day"`
  1818. VMHisProject VMHisProject `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"project"`
  1819. VMGoodInfo VMGoodInfo `gorm:"ForeignKey:ProjectId;AssociationForeignKey:ID" json:"good_info"`
  1820. Remark string `gorm:"column:remark" json:"remark" form:"remark"`
  1821. Unit string `gorm:"column:unit" json:"unit" form:"unit"`
  1822. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1823. Doctor int64 `gorm:"column:doctor" json:"doctor" form:"doctor"`
  1824. ExecutionTime int64 `gorm:"column:execution_time" json:"execution_time" form:"execution_time"`
  1825. ExecutionStaff int64 `gorm:"column:execution_staff" json:"execution_staff" form:"execution_staff"`
  1826. ExecutionState int64 `gorm:"column:execution_state" json:"execution_state" form:"execution_state"`
  1827. CheckTime int64 `gorm:"column:check_time" json:"check_time" form:"check_time"`
  1828. CheckState int64 `gorm:"column:check_state" json:"check_state" form:"check_state"`
  1829. Checker int64 `gorm:"column:checker" json:"checker" form:"checker"`
  1830. StartTime int64 `gorm:"column:start_time" json:"start_time" form:"start_time"`
  1831. TeamId int64 `gorm:"column:team_id" json:"team_id" form:"team_id"`
  1832. FrequencyType int64 `gorm:"column:frequency_type" json:"frequency_type" form:"frequency_type"`
  1833. DayCount int64 `gorm:"column:day_count" json:"day_count" form:"day_count"`
  1834. WeekDay string `gorm:"column:week_day" json:"week_day" form:"week_day"`
  1835. ExecutionFrequencyId int64 `gorm:"column:execution_frequency_id" json:"execution_frequency_id" form:"execution_frequency_id"`
  1836. }
  1837. func (HisPrescriptionProject) TableName() string {
  1838. return "his_prescription_project"
  1839. }
  1840. func FindeHisAdviceDocAdvice(orgid int64, patient_id int64, stime int64, etime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  1841. db := XTReadDB().Model(&advice).Where("status= 1 and is_medicine = 0 and drug_code <> ''")
  1842. if orgid > 0 {
  1843. db = db.Where("user_org_id = ?", orgid)
  1844. }
  1845. if patient_id > 0 {
  1846. db = db.Where("patient_id = ?", patient_id)
  1847. }
  1848. if stime > 0 {
  1849. db = db.Where("advice_date >=?", stime)
  1850. }
  1851. if etime > 0 {
  1852. db = db.Where("advice_date<=?", etime)
  1853. }
  1854. err = db.Find(&advice).Error
  1855. return advice, err
  1856. }
  1857. func FindUploadHisAdviceDocAdvice(orgid int64, patient_id int64, stime int64, etime int64) (advice []*models.HisDoctorAdviceInfo, err error) {
  1858. db := XTReadDB().Model(&advice).Where("status= 1 and is_medicine = 0")
  1859. if orgid > 0 {
  1860. db = db.Where("user_org_id = ?", orgid)
  1861. }
  1862. if patient_id > 0 {
  1863. db = db.Where("patient_id = ?", patient_id)
  1864. }
  1865. if stime > 0 {
  1866. db = db.Where("advice_date >=?", stime)
  1867. }
  1868. if etime > 0 {
  1869. db = db.Where("advice_date<=?", etime)
  1870. }
  1871. db = db.Where("is_upload = 1")
  1872. err = db.Find(&advice).Error
  1873. return advice, err
  1874. }