patient_dataconfig_service.go 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package service
  2. import (
  3. "Xcx_New/models"
  4. "time"
  5. "github.com/jinzhu/gorm"
  6. )
  7. func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) {
  8. var patient models.Patients
  9. err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error
  10. if err != nil {
  11. if err == gorm.ErrRecordNotFound {
  12. return nil, nil
  13. } else {
  14. return nil, err
  15. }
  16. }
  17. return &patient, nil
  18. }
  19. func GetPatientCourseOfDisease(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.PatientDiseaseCourse, error) {
  20. var records []*models.PatientDiseaseCourse
  21. err := readDb.Model(&models.PatientDiseaseCourse{}).Where("org_id = ? and patient_id = ? and record_time >= ? and record_time <= ? and status = 1", orgID, patientID, startTime, endTime).Order("record_time desc").Find(&records).Error
  22. if err != nil {
  23. return nil, err
  24. }
  25. return records, nil
  26. }
  27. func CreatePatientCourseOfDisease(record *models.PatientDiseaseCourse) error {
  28. err := writeDb.Model(&models.PatientDiseaseCourse{}).Create(record).Error
  29. return err
  30. }
  31. func GetPatientRescueRecords(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.PatientRescueRecord, error) {
  32. var records []*models.PatientRescueRecord
  33. err := readDb.Model(&models.PatientRescueRecord{}).Where("org_id = ? and patient_id = ? and record_time >= ? and record_time <= ? and status = 1", orgID, patientID, startTime, endTime).Order("record_time desc").Find(&records).Error
  34. if err != nil {
  35. return nil, err
  36. }
  37. return records, nil
  38. }
  39. func CreatePatientRescueRecord(record *models.PatientRescueRecord) error {
  40. err := writeDb.Model(&models.PatientRescueRecord{}).Create(record).Error
  41. return err
  42. }
  43. func ModifyPatientCourses(record *models.PatientDiseaseCourse) error {
  44. err := writeDb.Model(&models.PatientDiseaseCourse{}).Where("org_id = ? and patient_id = ? and status = 1 and id = ?", record.OrgID, record.PatientID, record.ID).Updates(map[string]interface{}{"content": record.Content, "record_time": record.RecordTime, "mtime": time.Now().Unix(), "title": record.Title}).Error
  45. return err
  46. }
  47. func DeletePatientCoursesInBatch(orgID int64, patientID int64, recordIDs []int64) error {
  48. err := writeDb.Model(&models.PatientDiseaseCourse{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, recordIDs).Updates(map[string]interface{}{"status": 2, "mtime": time.Now().Unix()}).Error
  49. return err
  50. }
  51. func DeletePatientResuceRecordsInBatch(orgID int64, patientID int64, recordIDs []int64) error {
  52. err := writeDb.Model(&models.PatientRescueRecord{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, recordIDs).Updates(map[string]interface{}{"status": 2, "mtime": time.Now().Unix()}).Error
  53. return err
  54. }