convertToDailyRecordModel method

  1. @override
DailyRecordModel convertToDailyRecordModel(
  1. {required DailyMeasurementRecord dailyRecord}
)
override

Implementation

@override
DailyRecordModel convertToDailyRecordModel({
  required DailyMeasurementRecord dailyRecord,
}) {
  if (dailyRecord.morningBloodPressure?.max != null &&
      dailyRecord.morningBloodPressure?.min != null) {
    if (dailyRecord.morningBloodPressure!.max! ==
        dailyRecord.morningBloodPressure!.min!) {
      throw Exception('朝の最高血圧と最低血圧が同じです');
    }

    if (dailyRecord.morningBloodPressure!.max! <
        dailyRecord.morningBloodPressure!.min!) {
      throw Exception('朝の最高血圧が最低血圧より低いです');
    }
  }

  final morningBloodPressureAndHeartRate = [
    dailyRecord.morningBloodPressure?.max,
    dailyRecord.morningBloodPressure?.min,
    dailyRecord.morningHeartRate,
  ];

  if (morningBloodPressureAndHeartRate.contains(null)) {
    if (morningBloodPressureAndHeartRate.any((element) => element != null)) {
      throw Exception('朝の血圧または心拍数が不正です');
    }
  }

  if (dailyRecord.eveningBloodPressure?.max != null &&
      dailyRecord.eveningBloodPressure?.min != null) {
    if (dailyRecord.eveningBloodPressure!.max! ==
        dailyRecord.eveningBloodPressure!.min!) {
      throw Exception('夜の最高血圧と最低血圧が同じです');
    }

    if (dailyRecord.eveningBloodPressure!.max! <
        dailyRecord.eveningBloodPressure!.min!) {
      throw Exception('夜の最高血圧が最低血圧より低いです');
    }
  }

  final eveningBloodPressureAndHeartRate = [
    dailyRecord.eveningBloodPressure?.max,
    dailyRecord.eveningBloodPressure?.min,
    dailyRecord.eveningHeartRate,
  ];

  if (eveningBloodPressureAndHeartRate.contains(null)) {
    if (eveningBloodPressureAndHeartRate.any((element) => element != null)) {
      throw Exception('夜の血圧または心拍数が不正です');
    }
  }

  return DailyRecordModel(
    date: dailyRecord.date,
    weight: dailyRecord.weight,
    morningBloodPressureMax: dailyRecord.morningBloodPressure?.max,
    morningBloodPressureMin: dailyRecord.morningBloodPressure?.min,
    morningHeartRate: dailyRecord.morningHeartRate,
    eveningBloodPressureMax: dailyRecord.eveningBloodPressure?.max,
    eveningBloodPressureMin: dailyRecord.eveningBloodPressure?.min,
    eveningHeartRate: dailyRecord.eveningHeartRate,
    symptomShortnessOfBreath: dailyRecord.symptomShortnessOfBreath,
    symptomSwelling: dailyRecord.symptomSwelling,
    symptomFatigue: dailyRecord.symptomFatigue,
    symptomLossOfAppetite: dailyRecord.symptomLossOfAppetite,
    symptomInsomnia: dailyRecord.symptomInsomnia,
    medicationCheckMorning: dailyRecord.medicationCheckMorning ?? false,
    medicationCheckAfternoon: dailyRecord.medicationCheckAfternoon ?? false,
    medicationCheckEvening: dailyRecord.medicationCheckEvening ?? false,
  );
}