FHIRJSONType

public protocol FHIRJSONType: FHIRType

A protocol to handle FHIRType when working with JSON - which in our case is all FHIR types.

  • Generic initializer to be used on deserialized JSON.

    Declaration

    Swift

    init(json: JSONType, owner: FHIRAbstractBase?, context: inout FHIRInstantiationContext)

    Parameters

    json

    The value in its associated JSONType

    owner

    Optional, the owning element

    context

    An in-out parameter for the instantiation context

  • The JSON element used to deserialize the receiver from and serialize to.

    Declaration

    Swift

    associatedtype JSONType
  • A static/class function that should return the correct (sub)type, depending on information found in json.

    On primitives, simply forwards to init(json:owner:context:).

    Declaration

    Swift

    static func instantiate(from json: JSONType, owner: FHIRAbstractBase?, context: inout FHIRInstantiationContext) -> Self

    Parameters

    json

    A JSONType instance from which to instantiate

    owner

    The FHIRAbstractBase owning the new instance, if appropriate

    context

    An in-out parameter for the instantiation context

    Return Value

    If possible the appropriate FHIRAbstractBase subclass, instantiated from the given JSON dictionary, Self otherwise

  • populateAndFinalize(from:context:) Default implementation

    Populate instance variables - overriding existing ones - with values found in the supplied JSON.

    Default Implementation

    Will populate instance variables - overriding existing ones - with values found in the supplied JSON. Calls populate(json:context:), which is what you should override instead, and then calls finalize() on the context.

    Declaration

    Swift

    mutating func populateAndFinalize(from json: FHIRJSON, context: inout FHIRInstantiationContext)

    Parameters

    json

    The JSON element to use to populate the receiver

    context

    An in-out parameter for the instantiation context

  • populate(from:context:) Default implementation

    The main function to perform the actual JSON parsing, called from within populate(from:strict:) and usually overridden by subclasses.

    This method is expected to only ever encounter FHIRValidationError-type errors, any other errors should not occur and will simply be logged to the console.

    Default Implementation

    This method must populate ivars from data found in the JSON and shoud be overridden by subclasses.

    Declaration

    Swift

    mutating func populate(from json: FHIRJSON, context: inout FHIRInstantiationContext)

    Parameters

    json

    The JSON element to use to populate the receiver

    context

    An in-out parameter for the instantiation context

  • Return the receiver’s representation in JSONType.

    Declaration

    Swift

    func asJSON(errors: inout [FHIRValidationError]) -> JSONType

    Parameters

    errors

    Errors encountered during serialization

    Return Value

    The FHIRJSON reperesentation of the receiver

  • Represent the receiver in the given JSON dictionary.

    Note

    Values that the instance alreay possesses and are not in the JSON should be left alone.

    Declaration

    Swift

    func decorate(json: inout FHIRJSON, withKey: String, errors: inout [FHIRValidationError])

    Parameters

    json

    The FHIRJSON representation to populate

    withKey

    The key to use

    errors

    An in-out array to be stuffed with validation errors encountered along the way