import 'dart:convert';

import '../models/patient_model.dart';

class DetailWorkModel {
  String? id;
  String? tipeid;
  String? tipe;
  String? noSuratJalan;
  String? nama;
  String? distance;
  String? cdate;
  String? alamatPengambilan;
  String? petugasPenyerahan;
  String? alamatPengantaran;
  String? penerima;
  String? lokasiPengambilanAwal;
  String? latPengambilanAwal;
  String? lngPengambilanAwal;
  String? lokasiPengambilanAkhir;
  String? latPengambilanAkhir;
  String? lngPengambilanAkhir;
  String? lokasiPengantaranAwal;
  String? latPengantaranAwal;
  String? lngPengantaranAwal;
  String? lokasiPengantaranAkhir;
  String? latPengantaranAkhir;
  String? lngPengantaranAkhir;
  String? notePenyerahan;
  String? notePenerimaan;
  List<PatientModel>? patients;
  // TAMBAHAN INPUTAN INFO
  String? suhuBox;
  String? suhuSample;
  String? totalPasien;
  String? totalEdta;
  String? totalCitras;
  String? totalSerum;
  String? totalUrine;
  String? totalPleura;
  String? otherSample;
  String? totalOther;
  String? foNote;
  String? adminNote;
  String? branchID;

  DetailWorkModel(
      {this.id,
      this.tipeid,
      this.tipe,
      this.noSuratJalan,
      this.nama,
      this.distance,
      this.cdate,
      this.alamatPengambilan,
      this.petugasPenyerahan,
      this.alamatPengantaran,
      this.penerima,
      this.lokasiPengambilanAwal,
      this.latPengambilanAwal,
      this.lngPengambilanAwal,
      this.lokasiPengambilanAkhir,
      this.latPengambilanAkhir,
      this.lngPengambilanAkhir,
      this.lokasiPengantaranAwal,
      this.latPengantaranAwal,
      this.lngPengantaranAwal,
      this.lokasiPengantaranAkhir,
      this.latPengantaranAkhir,
      this.lngPengantaranAkhir,
      this.notePenerimaan,
      this.notePenyerahan,
      this.patients,
      // TAMBAHAN INPUTAN INFO
      this.suhuBox,
      this.suhuSample,
      this.totalPasien,
      this.totalEdta,
      this.totalCitras,
      this.totalSerum,
      this.totalUrine,
      this.totalPleura,
      this.otherSample,
      this.totalOther,
      this.foNote,
      this.adminNote,
      this.branchID});

  DetailWorkModel.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    tipeid = json['tipeid'];
    tipe = json['tipe'];
    noSuratJalan = json['no_surat_jalan'];
    nama = json['nama'];
    distance = json['distance'];
    cdate = json['cdate'];
    alamatPengambilan = json['alamat_pengambilan'];
    petugasPenyerahan = json['petugas_penyerahan'];
    alamatPengantaran = json['alamat_pengantaran'];
    penerima = json['penerima'];
    lokasiPengambilanAwal = json['lokasi_pengambilan_awal'];
    latPengambilanAwal = json['lat_pengambilan_awal'];
    lngPengambilanAwal = json['lng_pengambilan_awal'];
    lokasiPengambilanAkhir = json['lokasi_pengambilan_akhir'];
    latPengambilanAkhir = json['lat_pengambilan_akhir'];
    lngPengambilanAkhir = json['lng_pengambilan_akhir'];
    lokasiPengantaranAwal = json['lokasi_pengantaran_awal'];
    latPengantaranAwal = json['lat_pengantaran_awal'];
    lngPengantaranAwal = json['lng_pengantaran_awal'];
    lokasiPengantaranAkhir = json['lokasi_pengantaran_akhir'];
    latPengantaranAkhir = json['lat_pengantaran_akhir'];
    lngPengantaranAkhir = json['lng_pengantaran_akhir'];
    notePenerimaan = json['note_penerima'];
    notePenyerahan = json['note_penyerahan'];
    // patients = json['patients'];
    if (json['patients'].toString().isNotEmpty) {
      var data = <PatientModel>[];
      // print("hasil json decode");
      // print(jsonDecode(json['patients']));
      // print("end");
      try {
        jsonDecode(json['patients']).forEach((v) {
          data.add(PatientModel.fromJson(v));
        });
      } catch (e) {
        print(e);
      }
      patients = data;
    }

    // TAMBAHAN INPUTAN INFO
    suhuBox = json['suhu_box'];
    suhuSample = json['suhu_sample'];
    totalPasien = json['total_pasien'];
    totalEdta = json['total_edta'];
    totalCitras = json['total_citras'];
    totalSerum = json['total_serum'];
    totalUrine = json['total_urine'];
    totalPleura = json['total_pleura'];
    otherSample = json['other_sample'];
    totalOther = json['total_other'];
    foNote = json['fo_note'];
    adminNote = json['admin_note'];
    branchID = json['branchid'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id'] = this.id;
    data['tipeid'] = this.tipeid;
    data['tipe'] = this.tipe;
    data['no_surat_jalan'] = this.noSuratJalan;
    data['nama'] = this.nama;
    data['distance'] = this.distance;
    data['cdate'] = this.cdate;
    data['alamat_pengambilan'] = this.alamatPengambilan;
    data['petugas_penyerahan'] = this.petugasPenyerahan;
    data['alamat_pengantaran'] = this.alamatPengantaran;
    data['penerima'] = this.penerima;
    data['lokasi_pengambilan_awal'] = this.lokasiPengambilanAwal;
    data['lat_pengambilan_awal'] = this.latPengambilanAwal;
    data['lng_pengambilan_awal'] = this.lngPengambilanAwal;
    data['lokasi_pengambilan_akhir'] = this.lokasiPengambilanAkhir;
    data['lat_pengambilan_akhir'] = this.latPengambilanAkhir;
    data['lng_pengambilan_akhir'] = this.lngPengambilanAkhir;
    data['lokasi_pengantaran_awal'] = this.lokasiPengantaranAwal;
    data['lat_pengantaran_awal'] = this.latPengantaranAwal;
    data['lng_pengantaran_awal'] = this.lngPengantaranAwal;
    data['lokasi_pengantaran_akhir'] = this.lokasiPengantaranAkhir;
    data['lat_pengantaran_akhir'] = this.latPengantaranAkhir;
    data['lng_pengantaran_akhir'] = this.lngPengantaranAkhir;
    data['note_penyerahan'] = this.notePenyerahan;
    data['note_penerima'] = this.notePenerimaan;
    // data['patients'] = this.patients;
    if (this.patients != null || this.patients != "") {
      data['patients'] = this.patients!.map((v) => v.toJson()).toList();
    }

    // TAMBAHAN INPUTAN INFO
    data['suhu_box'] = this.suhuBox;
    data['suhu_sample'] = this.suhuSample;
    data['total_pasien'] = this.totalPasien;
    data['total_edta'] = this.totalEdta;
    data['total_citras'] = this.totalCitras;
    data['total_serum'] = this.totalSerum;
    data['total_urine'] = this.totalUrine;
    data['total_pleura'] = this.totalPleura;
    data['other_sample'] = this.otherSample;
    data['total_other'] = this.totalOther;
    data['fo_note'] = this.foNote;
    data['admin_note'] = this.adminNote;
    data['branchid'] = this.branchID;
    return data;
  }
}
