Resource.fromJson constructor

Resource.fromJson(
  1. JsonObject json
)

Implementation

factory Resource.fromJson(
  JsonObject json,
) {
  final resourceTypeString = json['resourceType'].stringValue;

  if (resourceTypeString == null) {
    return OperationOutcome<String>(
      text: Narrative(status: NarrativeStatus.empty),
    );
  }

  return switch (ResourceType.fromCode(resourceTypeString)) {
    (ResourceType.appointment) => Appointment.fromJson(json),
    (ResourceType.bundle) => Bundle.fromJson(json),
    (ResourceType.encounter) => Encounter.fromJson(json),
    (ResourceType.observation) => Observation.fromJson(json),
    (ResourceType.organization) => Organization.fromJson(json),
    (ResourceType.operationOutcome) =>
      OperationOutcome<String>.fromJson(json),
    (ResourceType.patient) => Patient.fromJson(json),
    (ResourceType.practitioner) => Practitioner.fromJson(json),
    (ResourceType.practitionerRole) => PractitionerRole.fromJson(json),
    (ResourceType.schedule) => Schedule.fromJson(json),
    (ResourceType.slot) => Slot.fromJson(json),
  };
}