File: C:/github_repos/casibase_customer_0022/object/consultation_util.go
// Copyright 2025 The Casibase Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package object
import (
"github.com/casdoor/casdoor-go-sdk/casdoorsdk"
)
func FilterConsultationsByUser(user *casdoorsdk.User, consultations []*Consultation) []*Consultation {
if user == nil {
return []*Consultation{}
}
// Admins can view all consultations
if IsAdmin(user) {
return consultations
}
// Patients can only view their own consultations
if IsPatient(user) {
filtered := []*Consultation{}
for _, consultation := range consultations {
if consultation.PatientName == user.Name {
filtered = append(filtered, consultation)
}
}
return filtered
}
// Doctors can view consultations where they are one of the doctors
if IsDoctor(user) {
filtered := []*Consultation{}
for _, consultation := range consultations {
for _, doctorName := range consultation.DoctorNames {
if doctorName == user.Name {
filtered = append(filtered, consultation)
break
}
}
}
return filtered
}
return []*Consultation{}
}