updateProfile method Null safety

Future<Patient?> updateProfile(
  1. Patient patient
)

Updates the patient's profile data in the database, which is essentially all personal information except for linked data (such as supporters, interests, conditions).

Implementation

// TODO(tigloo): Remove manual publishing of updates, move to subscription.
Future<Patient?> updateProfile(Patient patient) async {
  final result = await updateUserProfile(patient);

  if (result) {
    final gqlQueryString = '''
      mutation SetPatientOnboarding {
        updatePatient(
          input: {
            where: { id: "${patient.id}" }
            data: {
              onboardingVersionCompleted: ${patient.onBoardingVersionCompleted}
            }
          }
        ) {
          patient {
            onboardingVersionCompleted
          }
        }
      }
    ''';

    try {
      final queryResult = await graphQLClient.mutate<void>(MutationOptions(
        document: gql(gqlQueryString),
        fetchPolicy: FetchPolicy.networkOnly,
      ));

      if (queryResult.hasException) {
        logger?.e(queryResult.exception.toString());
        return null;
      }
    } catch (e, stackTrace) {
      logger?.e('Could not update patient profile data', e, stackTrace);
      return null;
    }

    _sendPatientUpdate(patient: patient);
    return patient;
  }

  return null;
}