parseRequestResult function

ReturnResults<Resource> parseRequestResult(
  1. Resource result
)

There are usually 3 types of responses from a RESTful request made to a FHIR server. It can be a single Resource, it can be a Bundle, or it can be an OperationOutcome (usually indicating an error). The functions below return an object called ReturnResults. It contains 3 lists.

resources: the desired type of resource, or all resources if no type is specified. It does look through Bundle entries to find resources.

otherResources: if a specific type of resource is included, but other types are returned, they are included here

informationOperationOutcomes: this will include all OperationOutcomes that are for informational purposes and not errors. This will also include if, for instance, a Bundle is POSTed, and there are numerous Bundle entries returned with information about what was posted

errorOperationOutcomes: all other operationOutcomes are included here. This turns whatever was returned into a lsit of Resources.

Implementation

/// This turns whatever was returned into a lsit of Resources.
ReturnResults<Resource> parseRequestResult(Resource result) => result is Bundle
    ? parseBundle(result)
    : result is OperationOutcome
        ? isInformational(result)
            ? ReturnResults<OperationOutcome>(
                informationOperationOutcomes: <OperationOutcome>[result])
            : ReturnResults<OperationOutcome>(
                errorOperationOutcomes: <OperationOutcome>[result])
        : ReturnResults<Resource>(resources: <Resource>[result]);