import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/core/model/vital_sign/vital_sign_res_model.dart';

import '../base_service.dart';

class VitalSignService extends BaseService {
  List<VitalSignResModel> vitalSignResModelList =[];

  String weightKg = "";
  String heightCm = "";
  String bloadType = "";

  Future getPatientRadOrders({ int? appointmentNo,  int? projectID}) async {
    hasError = false;
    Map<String, dynamic> body = Map();
    if (appointmentNo != null && projectID != null) {
      body['TransNo'] = appointmentNo;
      body['ProjectID'] = projectID;
    }

    await baseAppClient.post(GET_PATIENT_VITAL_SIGN,
        onSuccess: (dynamic response, int statusCode) {
      vitalSignResModelList.clear();
      response['List_DoctorPatientVitalSign'].forEach((vital) {
        vitalSignResModelList.add(VitalSignResModel.fromJson(vital));
      });
      bool isHaveWeight = false;
      bool isHaveHeight = false;
      vitalSignResModelList.forEach((element) {
        if (element.weightKg != 0 && !isHaveWeight) {
          weightKg = '${element.weightKg}';
          isHaveWeight = true;
        }
        if (element.heightCm != 0 && !isHaveHeight) {
          heightCm = '${element.heightCm}';
          isHaveHeight = true;
        }
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }
}
