fromJson static method

EfactInvoice? fromJson(
  1. dynamic value
)

Returns a new EfactInvoice instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static EfactInvoice? fromJson(dynamic value) {
  if (value is EfactInvoice) {
    return value;
  }
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      requiredKeys.forEach((key) {
        assert(json.containsKey(key), 'Required key "EfactInvoice[$key]" is missing from JSON.');
        assert(json[key] != null, 'Required key "EfactInvoice[$key]" has a null value in JSON.');
      });
      return true;
    }());

    return EfactInvoice(
      patient: PatientDto.fromJson(json[r'patient']),
      ioCode: mapValueOfType<String>(json, r'ioCode'),
      items: InvoiceItem.listFromJson(json[r'items'])!,
      reason: EfactInvoiceReasonEnum.fromJson(json[r'reason']),
      invoiceRef: mapValueOfType<String>(json, r'invoiceRef'),
      invoiceNumber: mapValueOfType<int>(json, r'invoiceNumber'),
      ignorePrescriptionDate: mapValueOfType<bool>(json, r'ignorePrescriptionDate')!,
      hospitalisedPatient: mapValueOfType<bool>(json, r'hospitalisedPatient')!,
      creditNote: mapValueOfType<bool>(json, r'creditNote')!,
      relatedInvoiceIoCode: mapValueOfType<String>(json, r'relatedInvoiceIoCode'),
      relatedInvoiceNumber: mapValueOfType<int>(json, r'relatedInvoiceNumber'),
      relatedBatchSendNumber: mapValueOfType<int>(json, r'relatedBatchSendNumber'),
      relatedBatchYearMonth: mapValueOfType<int>(json, r'relatedBatchYearMonth'),
    );
  }
  return null;
}