package service import ( "time" "XT_New/models" "github.com/jinzhu/gorm" ) func GetPatientByID(orgID int64, patientID int64) (*models.Patients, error) { var patient models.Patients err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1 and lapseto = 1", patientID, orgID).First(&patient).Error if err != nil { if err == gorm.ErrRecordNotFound { return nil, nil } else { return nil, err } } return &patient, nil } func GetPatientByIDOne(orgID int64, patientID int64) (models.Patients, error) { var patient models.Patients err = readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error return patient, err } func GetPatientByIDTwoOne(patientID int64) (models.Patients, error) { var patient models.Patients err = readDb.Model(&models.Patients{}).Where("id = ? and status=1", patientID).First(&patient).Error return patient, err } func GetPatientCourseOfDisease(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.PatientDiseaseCourse, error) { var records []*models.PatientDiseaseCourse 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 if err != nil { return nil, err } return records, nil } func GetPatientSickHistory(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.XtPatientSickHistory, error) { var records []*models.XtPatientSickHistory err := readDb.Model(&models.XtPatientSickHistory{}).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 if err != nil { return nil, err } return records, nil } func GetPatientSickHistoryByIds(orgID int64, patientID int64, ids []string) ([]*models.XtPatientSickHistory, error) { var records []*models.XtPatientSickHistory err := readDb.Model(&models.XtPatientSickHistory{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, ids).Order("record_time desc").Find(&records).Error if err != nil { return nil, err } return records, nil } func GetPatienttPhysiqueByIds(orgID int64, patientID int64, ids []string) ([]*models.XtPatientPhysiqueCheck, error) { var records []*models.XtPatientPhysiqueCheck err := readDb.Model(&models.XtPatientPhysiqueCheck{}).Where("org_id = ? and patient_id = ? and id in (?) and status = 1", orgID, patientID, ids).Order("record_time desc").Find(&records).Error if err != nil { return nil, err } return records, nil } func GetPatientPhysiqueCheck(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.XtPatientPhysiqueCheck, error) { var records []*models.XtPatientPhysiqueCheck err := readDb.Model(&models.XtPatientPhysiqueCheck{}).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 if err != nil { return nil, err } return records, nil } func GetLastPatientPhysiqueCheck(orgID int64, patientID int64, record_date int64) (records models.XtPatientPhysiqueCheck, err error) { err = readDb.Model(&models.XtPatientPhysiqueCheck{}).Where("org_id = ? and patient_id = ? and record_date = ? and status = 1", orgID, patientID, record_date).Order("record_time desc").Last(&records).Error return records, err } func CreatePatientCourseOfDisease(record *models.PatientDiseaseCourse) error { err := writeDb.Model(&models.PatientDiseaseCourse{}).Create(record).Error return err } func CreatePatientSickHistory(record *models.XtPatientSickHistory) error { err := writeDb.Model(&models.XtPatientSickHistory{}).Create(record).Error return err } func CreatePatientPhysiqueCheck(record *models.XtPatientPhysiqueCheck) error { err := writeDb.Model(&models.XtPatientPhysiqueCheck{}).Create(record).Error return err } func GetPatientRescueRecords(orgID int64, patientID int64, startTime int64, endTime int64) ([]*models.PatientRescueRecord, error) { var records []*models.PatientRescueRecord 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 if err != nil { return nil, err } return records, nil } func CreatePatientRescueRecord(record *models.PatientRescueRecord) error { err := writeDb.Model(&models.PatientRescueRecord{}).Create(record).Error return err } func ModifyPatientCourses(record *models.PatientDiseaseCourse) error { 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 return err } func ModifyPatientSickHistory(record *models.XtPatientSickHistory) error { err := writeDb.Save(record).Error //err := writeDb.Model(&models.XtPatientSickHistory{}).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 return err } func ModifyPatientPhysiqueCheck(record *models.XtPatientPhysiqueCheck) error { err := writeDb.Save(record).Error //err := writeDb.Model(&models.XtPatientSickHistory{}).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 return err } func DeletePatientCoursesInBatch(orgID int64, patientID int64, recordIDs []int64) error { 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 return err } func DeletePatientSickHistoryInBatch(orgID int64, patientID int64, recordIDs []int64) error { err := writeDb.Model(&models.XtPatientSickHistory{}).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 return err } func DeletePatientResuceRecordsInBatch(orgID int64, patientID int64, recordIDs []int64) error { 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 return err } func DeletePatientPhysiqueCheckInBatch(orgID int64, patientID int64, recordIDs []int64) error { err := writeDb.Model(&models.XtPatientPhysiqueCheck{}).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 return err } func GetFaPiaoPatientByID(orgID int64, patientID int64) (*models.Patients, error) { var patient models.Patients err := readDb.Model(&models.Patients{}).Where("id = ? and user_org_id=? and status=1", patientID, orgID).First(&patient).Error if err != nil { if err == gorm.ErrRecordNotFound { return nil, nil } else { return nil, err } } return &patient, nil }