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
7 changes: 5 additions & 2 deletions patient/lib/repository/supabase_patient_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,16 @@ class SupabasePatientRepository implements PatientRepository {
.gte('performed_on', startDate.toIso8601String())
.lte('performed_on', endDate.toIso8601String());

final Set<String> seenRegressions = {};
List<String> regressions = [];
for(var i = 0; i < regresstionResponse.length; i++) {
final regression = regresstionResponse[i]['regressions'];
Comment on lines 242 to 244
for(var j = 0; j < regression.length; j++) {
final regressionItem = regression[j] is String ? jsonDecode(regression[j]) : regression[j];

regressions.add(regressionItem['name']);
final String regressionName = regressionItem['name'];
if (seenRegressions.add(regressionName)) {
regressions.add(regressionName);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class _TherapyGoalsScreenState extends State<TherapyGoalsScreen> {
padding: const EdgeInsets.symmetric(horizontal: 22, vertical: 25),
child: SaveTherapyButton(
text: 'Save Therapy Details',
isLoading: therapyProvider.saveTherapyStatus.isLoading,
onPressed: _onSaveTherapyDetails,
),
Comment on lines 116 to 120
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,44 @@ class SaveTherapyButton extends StatelessWidget {
super.key,
required this.text,
required this.onPressed,
this.isLoading = false,
});

final String text;
final VoidCallback onPressed;

final VoidCallback? onPressed;
final bool isLoading;

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onPressed,
child: Container(
width: double.infinity,
height: 50,
decoration: BoxDecoration(
color: AppTheme.primaryColor,
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: Text(
text,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w700,
),
onTap: isLoading ? null : onPressed,
child: Opacity(
opacity: isLoading ? 0.6 : 1.0,
child: Container(
width: double.infinity,
height: 50,
decoration: BoxDecoration(
color: AppTheme.primaryColor,
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: isLoading
? const SizedBox(
height: 24,
width: 24,
child: CircularProgressIndicator(
color: Colors.white,
strokeWidth: 2.5,
),
)
: Text(
text,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w700,
),
),
Comment on lines +20 to +46
),
),
),
Expand Down
45 changes: 27 additions & 18 deletions therapist/lib/provider/therapy_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,27 +219,36 @@ class TherapyProvider extends ChangeNotifier {
notifyListeners();
}

void saveTherapyDetails() async {
Future<void> saveTherapyDetails() async {
if (_saveTherapyStatus.isLoading) return;

_saveTherapyStatus = SaveTherapyStatus.loading;
final therapyGoalModel = TherapyGoalModel(
performedOn: _selectedDateTime ?? DateTime.now(),
therapyTypeId: _getTherapyIdFromSelectedTherapy(),
goals: _selectedTherapyGoals,
observations: _selectedTherapyObservations,
regressions: _selectedTherapyRegressions,
activities: _selectedTherapyActivities,
patientId: _patientId,
);

final ActionResult result = await _therapyRepository.saveTherapyGoals(therapyGoalModel.toEntity());
notifyListeners();

if(result is ActionResultSuccess) {
_saveTherapyStatus = SaveTherapyStatus.success;
_saveTherapyErrorMessage = '';
notifyListeners();
} else {
try {
final therapyGoalModel = TherapyGoalModel(
performedOn: _selectedDateTime ?? DateTime.now(),
therapyTypeId: _getTherapyIdFromSelectedTherapy(),
goals: _selectedTherapyGoals,
observations: _selectedTherapyObservations,
regressions: _selectedTherapyRegressions,
activities: _selectedTherapyActivities,
patientId: _patientId,
);

final ActionResult result = await _therapyRepository.saveTherapyGoals(therapyGoalModel.toEntity());

if (result is ActionResultSuccess) {
_saveTherapyStatus = SaveTherapyStatus.success;
_saveTherapyErrorMessage = '';
} else {
_saveTherapyStatus = SaveTherapyStatus.failure;
_saveTherapyErrorMessage = result.errorMessage.toString();
}
Comment on lines +244 to +247
} catch (e) {
_saveTherapyStatus = SaveTherapyStatus.failure;
_saveTherapyErrorMessage = result.errorMessage.toString();
_saveTherapyErrorMessage = e.toString();
} finally {
notifyListeners();
}
}
Expand Down
Loading