fromJson static method
Returns a new MedicationDto instance and imports its values from
value
if it's a Map, null otherwise.
Implementation
// ignore: prefer_constructors_over_static_methods
static MedicationDto? fromJson(dynamic value) {
if (value is MedicationDto) {
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 "MedicationDto[$key]" is missing from JSON.');
assert(json[key] != null, 'Required key "MedicationDto[$key]" has a null value in JSON.');
});
return true;
}());
return MedicationDto(
compoundPrescription: mapValueOfType<String>(json, r'compoundPrescription'),
substanceProduct: SubstanceproductDto.fromJson(json[r'substanceProduct']),
medicinalProduct: MedicinalproductDto.fromJson(json[r'medicinalProduct']),
numberOfPackages: mapValueOfType<int>(json, r'numberOfPackages'),
batch: mapValueOfType<String>(json, r'batch'),
instructionForPatient: mapValueOfType<String>(json, r'instructionForPatient'),
commentForDelivery: mapValueOfType<String>(json, r'commentForDelivery'),
drugRoute: mapValueOfType<String>(json, r'drugRoute'),
temporality: mapValueOfType<String>(json, r'temporality'),
frequency: CodeStubDto.fromJson(json[r'frequency']),
reimbursementReason: CodeStubDto.fromJson(json[r'reimbursementReason']),
substitutionAllowed: mapValueOfType<bool>(json, r'substitutionAllowed'),
beginMoment: mapValueOfType<int>(json, r'beginMoment'),
endMoment: mapValueOfType<int>(json, r'endMoment'),
deliveryMoment: mapValueOfType<int>(json, r'deliveryMoment'),
endExecutionMoment: mapValueOfType<int>(json, r'endExecutionMoment'),
duration: DurationDto.fromJson(json[r'duration']),
renewal: RenewalDto.fromJson(json[r'renewal']),
knownUsage: mapValueOfType<bool>(json, r'knownUsage'),
regimen: RegimenItemDto.listFromJson(json[r'regimen']) ?? const [],
posology: mapValueOfType<String>(json, r'posology'),
agreements: mapValueOfType<Map<String, ParagraphAgreementDto>>(json, r'agreements') ?? const {},
medicationSchemeIdOnSafe: mapValueOfType<String>(json, r'medicationSchemeIdOnSafe'),
medicationSchemeSafeVersion: mapValueOfType<int>(json, r'medicationSchemeSafeVersion'),
medicationSchemeTimeStampOnSafe: mapValueOfType<int>(json, r'medicationSchemeTimeStampOnSafe'),
medicationSchemeDocumentId: mapValueOfType<String>(json, r'medicationSchemeDocumentId'),
safeIdName: mapValueOfType<String>(json, r'safeIdName'),
idOnSafes: mapValueOfType<String>(json, r'idOnSafes'),
timestampOnSafe: mapValueOfType<int>(json, r'timestampOnSafe'),
changeValidated: mapValueOfType<bool>(json, r'changeValidated'),
newSafeMedication: mapValueOfType<bool>(json, r'newSafeMedication'),
medicationUse: mapValueOfType<String>(json, r'medicationUse'),
beginCondition: mapValueOfType<String>(json, r'beginCondition'),
endCondition: mapValueOfType<String>(json, r'endCondition'),
origin: mapValueOfType<String>(json, r'origin'),
medicationChanged: mapValueOfType<bool>(json, r'medicationChanged'),
posologyChanged: mapValueOfType<bool>(json, r'posologyChanged'),
suspension: SuspensionDto.listFromJson(json[r'suspension']) ?? const [],
prescriptionRID: mapValueOfType<String>(json, r'prescriptionRID'),
status: mapValueOfType<int>(json, r'status'),
);
}
return null;
}