123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480 |
- import 'base_form_value.dart';
- import 'form_info.dart';
- class MaternalHealthFormValue extends BaseFormValueChange {
- static MaternalHealthFormValue? _maternalHealthManagementForm;
- MaternalHealthFormValue._internal();
- ///第 1 次产前检查服务记录表的值
- static MaternalHealthFormValue get instance {
- _maternalHealthManagementForm ??= MaternalHealthFormValue._internal();
- return _maternalHealthManagementForm!;
- }
- void initListener() {
- FormInfo.instance.onValueChange.addListener(_onValueChange);
- }
- void dispose() {
- FormInfo.instance.onValueChange.removeListener(_onValueChange);
- }
- void _onValueChange(Object sender, UpdateFormArgs e) {
- String sourceKey = e.sourceKey;
- UpdateFormType type = e.type;
- switch (sourceKey) {
- //末次月经
- case "Last_Period":
- changeLastPeriodDate(e);
- break;
- //既往史
- case "Past_History":
- //既往史选择无
- changePastHistory(e);
- break;
- //家族史
- case "Family_History":
- changeFamilyHistory(e);
- break;
- //妇产科手术史
- case "Operation_History":
- changeOperationHistory(e);
- break;
- //升高、体重计算BMI
- case "Weight":
- case "Height":
- super.onHeightOrWeightChange(e);
- break;
- //心脏
- case "Heart_Abnormal":
- changeHeartAbnormal(e);
- break;
- //肺部
- case "Lung_Abnormal":
- changeLungAbnormal(e);
- break;
- //外阴
- case "Vulvar":
- changeVulvar(e);
- break;
- //阴道
- case "Vagina":
- onValueChange(e, "Vagina_1", "Vagina_Abnormality");
- break;
- //宫颈
- case "Cervical":
- onValueChange(e, "Cervical_1", "Cervical_Abnormality");
- break;
- //子宫
- case "Uteri_Body":
- onValueChange(e, "Uteri_Body_1", "Uteri_Body_Abnormality");
- break;
- //附件
- case "Uteri_Adnexa":
- onValueChange(e, "Uteri_Adnexa_1", "Uteri_Adnexa_Abnormality");
- break;
- //阴道分泌物
- case "Vaginal_Discharge":
- onVaginalDischargeChange(e);
- break;
- case "MaternalHealthManagement_Overall_Assessment":
- onValueChange(e, "M_O_A_No_Abnormality_Detected", "M_O_A_Abnormality");
- break;
- case "Referral":
- onReferralChange(e);
- break;
- case "Last_Period_Date":
- onLastPeriodDateChange(e);
- break;
- case "Health_History":
- onHealthHistoryChange(e);
- break;
- }
- }
- void changeLastPeriodDate(UpdateFormArgs e) {
- UpdateFormType type = e.type;
- if (type == UpdateFormType.Add) {
- if (FormInfo.instance.formValue.containsKey("Last_Period_Date")) {
- FormInfo.instance.formValue.remove("Last_Period_Date");
- }
- ///选中了末次月经的不详,则禁用日期选择器
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Last_Period_Date",
- isDisabledValue: true,
- ),
- );
- } else if (type == UpdateFormType.Remove) {
- ///取消选中了末次月经的不详,则取消禁用日期选择器
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Last_Period_Date",
- isDisabledValue: false,
- ),
- );
- }
- }
- void changePastHistory(UpdateFormArgs e) {
- UpdateFormType type = e.type;
- bool isDisabledValue = false;
- if (type == UpdateFormType.Add && e.sourceValue == "Past_History_1") {
- ///选中了无,则禁用其他选项
- isDisabledValue = true;
- } else if (type == UpdateFormType.Remove &&
- e.sourceValue == "Past_History_1") {
- ///取消选中无,则取消禁用其他选项
- isDisabledValue = false;
- } else {
- return;
- }
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Past_History_2",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Past_History_3",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Past_History_4",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Past_History_5",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Past_History_6",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Past_History_7",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Past_History_Other",
- isDisabledValue: isDisabledValue,
- ),
- );
- }
- void changeFamilyHistory(UpdateFormArgs e) {
- UpdateFormType type = e.type;
- bool isDisabledValue = false;
- if (type == UpdateFormType.Add && e.sourceValue == "Family_History_1") {
- ///选中了无,则禁用其他选项
- isDisabledValue = true;
- } else if (type == UpdateFormType.Remove &&
- e.sourceValue == "Family_History_1") {
- ///取消选中无,则取消禁用其他选项
- isDisabledValue = false;
- } else if (type == UpdateFormType.Add &&
- e.sourceValue == "Family_History_2") {
- //选中了遗传性病史,则显示遗传性病史详情
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Family_History_2_Detail",
- isHidden: false,
- ),
- );
- return;
- } else if (type == UpdateFormType.Remove &&
- e.sourceValue == "Family_History_2") {
- //取消选中了遗传性病史,则隐藏遗传性病史详情
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Family_History_2_Detail",
- isHidden: true,
- ),
- );
- return;
- } else if (type == UpdateFormType.Add &&
- e.sourceValue == "Family_History_3") {
- //选中了精神疾病史,则显示精神疾病史详情
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Family_History_3_Detail",
- isHidden: false,
- ),
- );
- return;
- } else if (type == UpdateFormType.Remove &&
- e.sourceValue == "Family_History_3") {
- //取消选中了精神疾病史
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Family_History_3_Detail",
- isHidden: true,
- ),
- );
- return;
- } else {
- return;
- }
- if (isDisabledValue) {
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Family_History_3_Detail",
- isHidden: true,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Family_History_2_Detail",
- isHidden: true,
- ),
- );
- }
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Family_History_2",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Family_History_3",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Family_History_Other",
- isDisabledValue: isDisabledValue,
- ),
- );
- }
- void changeOperationHistory(UpdateFormArgs e) {
- UpdateFormType type = e.type;
- if (e.sourceValue == "Operation_History_null") {
- if (type == UpdateFormType.Add) {
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Operation_History_True",
- targetValue: "cancelSelection",
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Operation_History_True_Detail",
- isHidden: true,
- ),
- );
- }
- FormInfo.instance.formValue[e.sourceKey] = [e.sourceValue];
- } else if (e.sourceValue == "Operation_History_True") {
- FormInfo.instance.formValue[e.sourceKey] = [e.sourceValue];
- if (type == UpdateFormType.Add) {
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Operation_History_null",
- targetValue: "cancelSelection",
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Operation_History_True_Detail",
- isHidden: false,
- ),
- );
- } else if (type == UpdateFormType.Remove) {
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Operation_History_True_Detail",
- isHidden: true,
- ),
- );
- }
- }
- }
- void changeHeartAbnormal(UpdateFormArgs e) {
- onValueChange(e, "Heart_Abnormal_1", "Heart_Abnormal_Abnormality");
- }
- void changeLungAbnormal(UpdateFormArgs e) {
- onValueChange(e, "Lung_Abnormal_1", "Lung_Abnormal_Abnormality");
- }
- void changeVulvar(UpdateFormArgs e) {
- onValueChange(e, "Vulvar_1", "Vulvar_Abnormality");
- }
- void onVaginalDischargeChange(UpdateFormArgs e) {
- UpdateFormType type = e.type;
- bool isDisabledValue = false;
- if (type == UpdateFormType.Add && e.sourceValue == "Vaginal_Discharge_1") {
- ///选中了无,则禁用其他选项
- isDisabledValue = true;
- } else if (type == UpdateFormType.Remove &&
- e.sourceValue == "Vaginal_Discharge_1") {
- ///取消选中无,则取消禁用其他选项
- isDisabledValue = false;
- }
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Vaginal_Discharge_2",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Vaginal_Discharge_3",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Vaginal_Discharge_4",
- isDisabledValue: isDisabledValue,
- ),
- );
- }
- void onLastPeriodDateChange(UpdateFormArgs e) {
- var targetValue = calculateDueDateString(e.sourceValue);
- FormInfo.instance.formValue["EstimatedDeliveryDate"] = targetValue;
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "EstimatedDeliveryDate",
- isDisabledValue: false,
- targetValue: targetValue,
- ),
- );
- }
- String calculateDueDateString(String lastMenstrualPeriodStr) {
- // 首先将输入字符串转换为DateTime对象
- DateTime lastMenstrualPeriod = DateTime.parse(lastMenstrualPeriodStr);
- // 计算预产期
- DateTime dueDate = DateTime(
- lastMenstrualPeriod.year,
- lastMenstrualPeriod.month + 9,
- lastMenstrualPeriod.day + 6,
- );
- dueDate = DateTime(
- dueDate.year + (dueDate.month > 12 ? 1 : 0), // 如果月份大于12,年份加一
- dueDate.month > 12
- ? dueDate.month - 12
- : dueDate.month, // 如果月份大于12,月份减去12
- dueDate.day, // 日子不变
- );
- dueDate = DateTime(
- dueDate.year,
- dueDate.month,
- dueDate.day > DateTime(dueDate.year, dueDate.month + 1, 0).day
- ? DateTime(dueDate.year, dueDate.month + 1, 0).day
- : dueDate.day,
- );
- // 将预产期DateTime对象转换回字符串格式
- String dueDateString =
- "${dueDate.year}-${dueDate.month.toString().padLeft(2, '0')}-${dueDate.day.toString().padLeft(2, '0')}";
- return dueDateString;
- }
- void onHealthHistoryChange(UpdateFormArgs e) {
- UpdateFormType type = e.type;
- bool isDisabledValue = false;
- if (type == UpdateFormType.Add && e.sourceValue == "Health_History_1") {
- ///选中了无,则禁用其他选项
- isDisabledValue = true;
- } else if (type == UpdateFormType.Remove &&
- e.sourceValue == "Health_History_1") {
- ///取消选中无,则取消禁用其他选项
- isDisabledValue = false;
- }
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Health_History_2",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Health_History_3",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Health_History_4",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Health_History_5",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Health_History_6",
- isDisabledValue: isDisabledValue,
- ),
- );
- FormInfo.instance.onChangeTargetValue.emit(
- this,
- TargetFormArgs(
- "Health_History_7",
- isDisabledValue: isDisabledValue,
- ),
- );
- }
- }
|