import 'package:fis_common/logger/logger.dart';
import 'package:flyinsono/js_platform/methods.dart';
import 'package:flyinsono/pages/remedical/consultation/controller.dart';
import 'package:get/get.dart';

import 'base.dart';

class OnSubmitReportHandler extends MethodHandlerBase {
  OnSubmitReportHandler() : super(TargetMethodName.OnSubmitReport);

  final int pageSize = 10;

  @override
  void execute(List<String> args) {
    try {
      if (args.isEmpty) {
        return;
      }
      var patiendCode = args[0];
      var recordCode = args[1];
      final consultationController = Get.find<ConsultationController>();
      final state = consultationController.state;
      final patientInfo = state.patientInfo;
      if (patientInfo.patientCode == patiendCode) {
        consultationController.getCheckInfo(recordCode);
        int patientIndex = state.selectPatientCardIndex + 1;
        var size = patientIndex < pageSize
            ? pageSize
            : ((patientIndex / pageSize).ceil() * pageSize);
        consultationController.getPatientsInfo(pageSize: size);
      }
    } catch (e) {
      logger.e('OnSubmitReportHandler ex', e);
    }
  }
}
