modifyEncryptedPatient method

  1. @override
Future<EncryptedPatient?> modifyEncryptedPatient(
  1. EncryptedPatient modifiedPatient
)
override

Modifies an encrypted patient, ensuring that the modified patient does not include any data which should be encrypted. Similarly to getPatientAndTryDecrypt this method is useful when a patient needs to update is own data before an hcp gave him access to his own encrypted data.

Implementation

@override
Future<EncryptedPatient?> modifyEncryptedPatient(EncryptedPatient modifiedPatient) async {
  final config = patientCryptoConfig(_api.crypto);
  final rawDto = EncryptedPatientMapper(modifiedPatient).toPatientDto();
  final asDecrypted = DecryptedPatientDto.fromJson(rawDto.toJson());
  if (asDecrypted == null || (await config.marshaller(asDecrypted)).item2 != null) {
    throw ArgumentError('Impossible to modify non-decryptable patient if new data requires encryption');
  }
  final modified = await _api.basePatientApi.rawModifyPatient(rawDto);
  if (modified == null) return null;
  return EncryptedPatientDtoMapper(modified).toEncryptedPatient();
}