ConsentController

public class ConsentController

The consent controller helps using a FHIR Contract resource to capture consent.

The controller can read a bundled Contract resource and return view controllers that can be used for eligibility checking (use eligibilityStatusViewController(config:onStartConsent:)) and/or consenting (use consentViewController(onUserDidConsent:onUserDidDecline:)).

  • The contract to be signed; if nil when signing, a new instance will be created.

    Declaration

    Swift

    public final var contract: Contract?
  • Options to consider for the consenting task.

    Declaration

    Swift

    public var options = ConsentTaskOptions()
  • The logger to use, if any.

    Declaration

    Swift

    public var logger: OAuth2Logger?
  • Designated initializer.

    You can optionally supply the name of a bundled JSON file (without extension) that represents a serialized FHIR Contract resource. This uses the main Bundle, so if you’re calling the method from a different bundle (e.g. when unit testing), don’t provide a filename and assign contract manually by using fhir_bundledResource(name:subdirectory:type:).

    Declaration

    Swift

    public init(bundledContract: String? = nil, subdirectory: String? = nil) throws

    Parameters

    bundledContract

    The filename (without “.json” of the Contract resource to read)

    subdirectory

    The subdirectory, if any, the Contract resource is located in

  • Instantiates a controller prompting the user to press “Start Eligibility”. Pressing that button pushes an EligibilityCheckViewController onto the navigation stack, which carries the actual eligibility criteria.

    Declaration

    Swift

    public func eligibilityStatusViewController(_ config: StudyIntroConfiguration? = nil, onStartConsent: ((EligibilityCheckViewController) -> Void)? = nil) -> EligibilityStatusViewController

    Parameters

    config

    An optional StudyIntroConfiguration instance that carries custom eligible/ineligible texts

    onStartConsent

    The block to execute when all eligibility criteria are met and the participant wants to start consent. Leave nil to automatically present (and dismiss) the consent task view controller that will be returned by consentViewController().

  • Resolves the contract’s first subject to a Group. This Group is expected to have characteristics that represent eligibility criteria.

    Declaration

    Swift

    public func eligibilityRequirements(callback: @escaping (([EligibilityRequirement]?) -> Void))

    Parameters

    callback

    The callback that is called when the group is resolved (or resolution fails); may be on any thread but may be called immediately in case of embedded resources.

  • Creates the consent task from the receiver’s contract.

    Throws

    C3Error.ConsentContractNotPresent when the contract is not present

    Declaration

    Swift

    public func createConsentTask() throws -> ConsentTask

    Return Value

    A ConsentTask that can be presented using ResearchKit

  • A consent view controller, preconfigured with the consenting task, that can be presented to have the user go through consent.

    You are given two blocks, one of them will be called when the user finishes or exits consenting, never both. They are deallocated after either has been called.

    Throws

    Re-throws from createConsentTask()

    Declaration

    Swift

    public func consentViewController(onUserDidConsent onConsent: @escaping ((ORKTaskViewController, ConsentResult) -> Void),
    		onUserDidDecline: @escaping ((ORKTaskViewController) -> Void)) throws -> ORKTaskViewController

    Parameters

    onUserDidConsent

    Block executed when the user completes and agrees to consent

    onUserDidDecline

    Block executed when the user cancels or actively declines consent

  • Called when the user successfully completes the consent task and agrees to all the things.

    Declaration

    Swift

    public func userDidConsent(_ taskViewController: ORKTaskViewController, result: ConsentResult)
  • Called when the user aborts consenting or actively declines consent.

    Declaration

    Swift

    public func userDidDeclineConsent(_ taskViewController: ORKTaskViewController)
  • Instantiates a new Contract resource and fills the properties to represent a consent signed by a participant referencing the given patient.

    Throws

    C3Error when referencing the patient resource fails

    Declaration

    Swift

    public func signContract(with patient: Patient, result: ConsentResult) throws -> Contract

    Parameters

    with

    The Patient resource to use to sign

    result

    The date at which the contract was signed

    Return Value

    A signed Contract resource, usually the receiver’s contract ivar

  • Reverse geocodes and de-identifies the patient, then uses the new Patient resource to sign the contract.

    Throws

    C3Error when referencing the patient resource fails

    Declaration

    Swift

    public func deIdentifyAndSignContract(with patient: Patient, result: ConsentResult, callback: @escaping ConsentSigningCallback)

    Parameters

    with

    The Patient resource to use to sign

    result

    The result of the consenting task

    callback

    The callback to call when done or when signing failed

    Return Value

    A signed Contract resource, usually the receiver’s contract ivar

  • URL to the user-signed contract PDF.

    Declaration

    Swift

    public class func signedConsentPDFURL(mustExist: Bool = false) -> URL?

    Parameters

    mustExist

    If true will return nil if no file exists at the expected file URL. If false will return the desired URL, which is pretty sure to return non-nil, so use that exclamation mark!

  • The local URL to the bundled consent; looks for «consent.pdf» in the main bundle.

    Declaration

    Swift

    public class func bundledConsentPDFURL() -> URL?