APP_NEW/lib/Class/Diagnosis/diagnosis.dart
2025-03-11 21:17:14 +08:00

178 lines
6.0 KiB
Dart

import 'package:lamiter/Class/Result/constitution_result.dart';
import 'package:lamiter/Class/Result/health_index_result.dart';
import 'package:lamiter/Class/Result/physical_index_result.dart';
import 'package:lamiter/Class/Result/posture_issue_result.dart';
import 'package:lamiter/Class/Result/sleep_well_index_result.dart';
import 'package:lamiter/Class/Result/stress_index_result.dart';
import 'package:lamiter/Class/Result/urban_disease_result.dart';
import 'package:lamiter/Class/Result/zong_fu_index_result.dart';
import 'package:lamiter/Page/Diagnosis/diagnosis_report_page.dart';
enum DiagnosisType {
healthIndex,
physicalIndex,
urbanDisease,
stressIndex,
sleepWellIndex,
constitution,
zongFuIndex,
postureIssue,
}
class Diagnosis {
String? id;
String managerId;
String? managerName;
String? clientId;
DateTime startTime;
DateTime? endTime;
HealthIndexResult? healthIndexResult;
PhysicalIndexResult? physicalIndexResult;
UrbanDiseaseResult? urbanDiseaseResult;
StressIndexResult? stressIndexResult;
SleepWellIndexResult? sleepWellIndexResult;
ConstitutionResult? constitutionResult;
ZongFuIndexResult? zongFuIndexResult;
PostureIssueResult? postureIssueResult;
Diagnosis({
this.id,
required this.managerId,
this.managerName,
this.clientId,
this.endTime,
this.healthIndexResult,
this.physicalIndexResult,
this.urbanDiseaseResult,
this.stressIndexResult,
this.sleepWellIndexResult,
this.constitutionResult,
this.zongFuIndexResult,
this.postureIssueResult,
}) : startTime = DateTime.now();
Diagnosis.fromJson(Map<String, dynamic> json)
: id = json['_id'] as String?,
managerId = json['managerId'] as String,
managerName = json['managerName'] as String?,
clientId = json['clientId'] as String?,
startTime = DateTime.parse(json['startTime'] as String).toLocal(),
healthIndexResult = json["healthIndexResult"] != null
? HealthIndexResult.fromJson(json["healthIndexResult"])
: null,
physicalIndexResult = json["physicalIndexResult"] != null
? PhysicalIndexResult.fromJson(json["physicalIndexResult"])
: null,
urbanDiseaseResult = json["urbanDiseaseResult"] != null
? UrbanDiseaseResult.fromJson(json["urbanDiseaseResult"])
: null,
stressIndexResult = json["stressIndexResult"] != null
? StressIndexResult.fromJson(json["stressIndexResult"])
: null,
sleepWellIndexResult = json["sleepWellIndexResult"] != null
? SleepWellIndexResult.fromJson(json["sleepWellIndexResult"])
: null,
constitutionResult = json["constitutionResult"] != null
? ConstitutionResult.fromJson(json["constitutionResult"])
: null,
zongFuIndexResult = json["zongFuIndexResult"] != null
? ZongFuIndexResult.fromJson(json["zongFuIndexResult"])
: null,
postureIssueResult = json["postureIssueResult"] != null
? PostureIssueResult.fromJson(json["postureIssueResult"])
: null;
Map<String, dynamic> toJson() => {
'_id': id,
'managerId': managerId,
'clientId': clientId,
'startTime': startTime.toUtc().toIso8601String(),
'endTime': endTime!.toUtc().toIso8601String(),
'healthIndexResult': healthIndexResult?.toJson(),
'physicalIndexResult': physicalIndexResult?.toJson(),
'urbanDiseaseResult': urbanDiseaseResult?.toJson(),
'stressIndexResult': stressIndexResult?.toJson(),
'sleepWellIndexResult': sleepWellIndexResult?.toJson(),
'constitutionResult': constitutionResult?.toJson(),
'zongFuIndexResult': zongFuIndexResult?.toJson(),
'postureIssueResult': postureIssueResult?.toJson(),
};
void update(DiagnosisType type, dynamic result) {
switch (type) {
case DiagnosisType.healthIndex:
try {
result as HealthIndexResult;
healthIndexResult = result;
} catch (e) {}
break;
case DiagnosisType.physicalIndex:
try {
result as PhysicalIndexResult;
physicalIndexResult = result;
} catch (e) {}
break;
case DiagnosisType.urbanDisease:
try {
result as UrbanDiseaseResult;
urbanDiseaseResult = result;
} catch (e) {}
break;
case DiagnosisType.stressIndex:
try {
result as StressIndexResult;
stressIndexResult = result;
} catch (e) {}
break;
case DiagnosisType.sleepWellIndex:
try {
result as SleepWellIndexResult;
sleepWellIndexResult = result;
} catch (e) {}
break;
case DiagnosisType.constitution:
try {
result as ConstitutionResult;
constitutionResult = result;
} catch (e) {}
break;
case DiagnosisType.zongFuIndex:
try {
result as ZongFuIndexResult;
zongFuIndexResult = result;
} catch (e) {}
break;
case DiagnosisType.postureIssue:
try {
result as PostureIssueResult;
postureIssueResult = result;
} catch (e) {}
}
}
bool isReadyToSubmit() {
return healthIndexResult != null ||
physicalIndexResult != null ||
urbanDiseaseResult != null ||
stressIndexResult != null ||
sleepWellIndexResult != null ||
constitutionResult != null ||
postureIssueResult != null;
}
bool hasReport(DiagnosisReportType type) {
switch (type) {
case DiagnosisReportType.basicHealth:
return (healthIndexResult != null ||
physicalIndexResult != null ||
urbanDiseaseResult != null ||
stressIndexResult != null ||
sleepWellIndexResult != null);
case DiagnosisReportType.constitution:
return constitutionResult != null;
case DiagnosisReportType.postureIssue:
return postureIssueResult != null;
}
}
}