Booking physical consultation , bugs fixed and Profile picture adding using firebase storage is complete. Co-authored-by: Jipson George <152465898+Jipson-cosq@users.noreply.github.com> Reviewed-on: cosqnet/telemednet#6 Co-authored-by: DhanshCOSQ <dhanshas@cosq.net> Co-committed-by: DhanshCOSQ <dhanshas@cosq.net>
107 lines
3.1 KiB
Dart
107 lines
3.1 KiB
Dart
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
import 'package:firebase_auth/firebase_auth.dart';
|
|
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
|
import 'package:medora/controllers/doctor_controller.dart';
|
|
import 'package:medora/data/models/doctor.dart';
|
|
|
|
class DoctorProfileService {
|
|
static final String doctorProfileCollectionName =
|
|
dotenv.env['DOCTOR_PROFILE_COLLECTION_NAME']!;
|
|
static final FirebaseFirestore db = FirebaseFirestore.instance;
|
|
|
|
static Future<Doctor?> getDoctorProfile() async {
|
|
try {
|
|
final User? user = FirebaseAuth.instance.currentUser;
|
|
if (user == null) {
|
|
print('No user logged in');
|
|
return null;
|
|
}
|
|
|
|
final String uid = user.uid;
|
|
final DocumentSnapshot doc =
|
|
await db.collection(doctorProfileCollectionName).doc(uid).get();
|
|
|
|
if (!doc.exists) {
|
|
print('No patient profile found for this user');
|
|
return null;
|
|
}
|
|
|
|
final data = doc.data() as Map<String, dynamic>;
|
|
return Doctor.fromJson(data);
|
|
} catch (e) {
|
|
print('Error fetching doctor profile: $e');
|
|
return null;
|
|
}
|
|
}
|
|
|
|
static Future saveDoctorProfile(DoctorController controller) async {
|
|
try {
|
|
final User? user = FirebaseAuth.instance.currentUser;
|
|
if (user == null) {
|
|
print('No user logged in');
|
|
return false;
|
|
}
|
|
|
|
final String uid = user.uid;
|
|
final Doctor doctorData = controller.model;
|
|
|
|
final Map<String, dynamic> doctorJson = doctorData.toJson();
|
|
doctorJson['createdAt'] = FieldValue.serverTimestamp();
|
|
doctorJson['updatedAt'] = FieldValue.serverTimestamp();
|
|
doctorJson['uid'] = uid;
|
|
|
|
await db.collection(doctorProfileCollectionName).doc(uid).set(doctorJson);
|
|
print('Doctor profile saved successfully');
|
|
return true;
|
|
} catch (e) {
|
|
print('Error saving doctor profile: $e');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static Future updateDoctorProfile(DoctorController controller) async {
|
|
try {
|
|
final User? user = FirebaseAuth.instance.currentUser;
|
|
if (user == null) {
|
|
print('No user logged in');
|
|
return false;
|
|
}
|
|
|
|
final String uid = user.uid;
|
|
final Doctor doctorData = controller.model;
|
|
|
|
final Map<String, dynamic> doctorJson = doctorData.toJson();
|
|
doctorJson['updatedAt'] = FieldValue.serverTimestamp();
|
|
|
|
await db
|
|
.collection(doctorProfileCollectionName)
|
|
.doc(uid)
|
|
.update(doctorJson);
|
|
print('Doctor profile updated successfully');
|
|
return true;
|
|
} catch (e) {
|
|
print('Error updating doctor profile: $e');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
static Future deleteDoctorProfile() async {
|
|
try {
|
|
final User? user = FirebaseAuth.instance.currentUser;
|
|
if (user == null) {
|
|
print('No user logged in');
|
|
return false;
|
|
}
|
|
|
|
final String uid = user.uid;
|
|
|
|
await db.collection(doctorProfileCollectionName).doc(uid).delete();
|
|
print('Doctor profile deleted successfully');
|
|
return true;
|
|
} catch (e) {
|
|
print('Error deleting doctor profile: $e');
|
|
return false;
|
|
}
|
|
}
|
|
}
|