SmartFhirClient.fromLaunchParameters constructor

SmartFhirClient.fromLaunchParameters(
  1. Uri base,
  2. Map<String, String> queryParameters, {
  3. FhirUri? fhirUri,
  4. String? clientId,
  5. FhirUri? redirectUri,
  6. String? customUriScheme,
  7. List<String>? scopes,
  8. String? authorizeUrl,
  9. String? tokenUrl,
  10. String? launch,
  11. String? secret,
  12. String redirectPath = '/redirect.html',
})

Constructor to assist in building a client from Launch parameters that may be present in the launch URL

Implementation

factory SmartFhirClient.fromLaunchParameters(
  Uri base,
  Map<String, String> queryParameters, {
  FhirUri? fhirUri,
  String? clientId,
  FhirUri? redirectUri,
  String? customUriScheme,
  List<String>? scopes,
  String? authorizeUrl,
  String? tokenUrl,
  String? launch,
  String? secret,
  String redirectPath = '/redirect.html',
}) {
  fhirUri ??= queryParameters['iss'] == null
      ? throw Exception('no fhirUri was passed for SMART launch')
      : FhirUri(queryParameters['iss']);
  launch ??= queryParameters['launch'];
  clientId ??= queryParameters['clientId'];
  redirectUri ??= FhirUri(Uri(
    host: base.host,
    scheme: base.scheme,
    port: base.port,
    path: redirectPath,
  ));
  if (clientId == null) {
    throw Exception('no clientId was passed for SMART launch');
  }
  return SmartFhirClient(
    fhirUri: fhirUri,
    clientId: clientId,
    redirectUri: redirectUri,
    customUriScheme: customUriScheme,
    scopes: scopes,
    authorizeUrl: authorizeUrl == null ? null : FhirUri(authorizeUrl),
    tokenUrl: tokenUrl == null ? null : FhirUri(tokenUrl),
    launch: launch,
    secret: secret,
    isDemo: queryParameters['demo'] == 'true',
  );
}