Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions patient/android/app/src/main/res/values/styles.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ part 'personal_info_entity.mapper.dart';
@MappableClass()
class PersonalInfoEntity with PersonalInfoEntityMappable {

@MappableField(key: 'id')
@MappableField(key: 'patient_id')
final String patientId;

@MappableField(key: 'patient_name')
Expand All @@ -23,7 +23,7 @@ class PersonalInfoEntity with PersonalInfoEntityMappable {
@MappableField(key: 'is_adult')
final bool isAdult;

@MappableField(key: 'phone')
@MappableField(key: 'phone_no')
final String phoneNo;

@MappableField(key: 'email')
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 14 additions & 19 deletions patient/lib/presentation/assessments/assessment_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import 'package:patient/provider/assessment_provider.dart';
import 'package:provider/provider.dart';
import 'package:patient/presentation/result/result.dart';


class AssessmentScreen extends StatefulWidget {
const AssessmentScreen({
super.key,
Expand Down Expand Up @@ -105,9 +104,7 @@ class AssessmentScreenState extends State<AssessmentScreen> {
height: 50,
child: ElevatedButton(
onPressed: () {

context.read<AssessmentProvider>().submitAssessment();

},
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.secondaryColor,
Expand Down Expand Up @@ -152,7 +149,6 @@ class QuestionCard extends StatelessWidget {

@override
Widget build(BuildContext context) {

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
Expand Down Expand Up @@ -195,23 +191,22 @@ class QuestionCard extends StatelessWidget {
side: const BorderSide(
color: Color(0xFF666666),
width: 1.5,

),
Expanded(
child: Text(
optionText,
style: const TextStyle(
fontSize: 14,
color: AppTheme.subtitleColor,
),
),
Expanded(
child: Text(
optionText,
style: const TextStyle(
fontSize: 14,
color: AppTheme.subtitleColor,
),
),
],
),
);
}),
],
),
),
],
),
);
}),
],
);
}
}
}
79 changes: 56 additions & 23 deletions patient/lib/provider/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import 'package:supabase_flutter/supabase_flutter.dart';

import '../core/result/result.dart';


enum AuthNavigationStatus {
unknown,
home,
personalDetails,
error,
}

extension AuthNavigationStatusX on AuthNavigationStatus {
bool get isUnknown => this == AuthNavigationStatus.unknown;
bool get isHome => this == AuthNavigationStatus.home;
Expand All @@ -26,16 +26,15 @@ extension AuthNavigationStatusX on AuthNavigationStatus {
}

class AuthProvider extends ChangeNotifier {

AuthProvider({
required AuthRepository authRepository,
}): _authRepository = authRepository;
}) : _authRepository = authRepository;

final AuthRepository _authRepository;

ApiStatus _apiStatus = ApiStatus.initial;
ApiStatus get apiStatus => _apiStatus;

String _apiErrorMessage = '';
String get apiErrorMessage => _apiErrorMessage;

Expand All @@ -52,6 +51,7 @@ class AuthProvider extends ChangeNotifier {
await _handleMobileSignIn();
}
} catch (error) {
debugPrint('Sign-in failed: $error');
throw Exception('Sign in failed: $error');
}
}
Expand All @@ -69,9 +69,9 @@ class AuthProvider extends ChangeNotifier {

Future<void> _handleMobileSignIn() async {
final webClientId = dotenv.env['GOOGLE_WEB_CLIENT_ID'] ??
(throw Exception("WEB_CLIENT_ID not found in .env"));
(throw Exception("GOOGLE_WEB_CLIENT_ID not found in .env"));
final iosClientId = dotenv.env['GOOGLE_IOS_CLIENT_ID'];

final GoogleSignIn googleSignIn = GoogleSignIn(
clientId: Platform.isIOS ? iosClientId : null,
serverClientId: webClientId,
Expand All @@ -81,7 +81,7 @@ class AuthProvider extends ChangeNotifier {
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
if (googleUser == null) throw 'Sign in cancelled';

final GoogleSignInAuthentication googleAuth =
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;

if (googleAuth.idToken == null) throw 'No ID Token found';
Expand All @@ -96,37 +96,70 @@ class AuthProvider extends ChangeNotifier {

String? getFullName() {
final session = supabase.auth.currentSession;
if (session == null) return null;

if (session == null) {
debugPrint('User not authenticated');
return null;
}

debugPrint('Access Token: ${session.accessToken}');

return session.user.userMetadata?['full_name'] ?? 'User';
}

Future<void> checkIfPatientExists() async {
final ActionResult result = await _authRepository.checkIfPatientExists();
_authNavigationStatus = AuthNavigationStatus.unknown;
notifyListeners();
if(result is ActionResultSuccess) {

final ActionResult result = await _authRepository.checkIfPatientExists();

if (result is ActionResultSuccess) {
final bool patientExists = result.data as bool;
if(patientExists) {
_authNavigationStatus = AuthNavigationStatus.home;
} else {
_authNavigationStatus = AuthNavigationStatus.personalDetails;
}
_authNavigationStatus = patientExists
? AuthNavigationStatus.home
: AuthNavigationStatus.personalDetails;
} else {
debugPrint('Error checking patient existence: ${result.errorMessage}');
_authNavigationStatus = AuthNavigationStatus.error;
}
notifyListeners();
}

void storePatientPersonalInfo(PersonalInfoModel personalInfoModel) async {
_apiStatus = ApiStatus.initial;
_apiErrorMessage = '';
notifyListeners();
final ActionResult result = await _authRepository.storePersonalInfo(personalInfoModel.toEntity());
if(result is ActionResultSuccess) {
_apiStatus = ApiStatus.success;
} else {
try {
_apiStatus = ApiStatus.initial;
_apiErrorMessage = '';
notifyListeners();

final user = supabase.auth.currentUser;
if (user == null) {
debugPrint('User not authenticated');
_apiErrorMessage = 'User not authenticated. Please log in again.';
_apiStatus = ApiStatus.failure;
notifyListeners();
return;
}

// Debugging API request details
debugPrint('Sending Patient Info: ${personalInfoModel.toEntity()}');
debugPrint('Access Token: ${supabase.auth.currentSession?.accessToken}');

final ActionResult result =
await _authRepository.storePersonalInfo(personalInfoModel.toEntity());

if (result is ActionResultSuccess) {
_apiStatus = ApiStatus.success;
} else {
debugPrint('API Error: ${result.errorMessage}');
_apiStatus = ApiStatus.failure;
_apiErrorMessage =
result.errorMessage ?? 'An error occurred. Please try again.';
}
} catch (e, stackTrace) {
debugPrint('Unexpected Error: $e');
debugPrint('Stack Trace: $stackTrace');
_apiStatus = ApiStatus.failure;
_apiErrorMessage = result.errorMessage ?? 'An error occurred. Please try again.';
_apiErrorMessage = 'Something went wrong. Please try again later.';
}
notifyListeners();
}
Expand Down
4 changes: 2 additions & 2 deletions patient/lib/repository/supabase_auth_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SupabaseAuthRepository implements AuthRepository {
try {
final response = await _supabaseClient.from('patient')
.select('*')
.eq('id', _supabaseClient.auth.currentUser!.id)
.eq('patient_id', _supabaseClient.auth.currentUser!.id)
.maybeSingle();

if(response != null) {
Expand All @@ -62,4 +62,4 @@ class SupabaseAuthRepository implements AuthRepository {
}
}

}
}
Loading