validateOnServer method

ValidationResult validateOnServer(
  1. FhirNode? vs,
  2. Map<String, dynamic> pin,
  3. ValidationOptions options
)

Prepares pin (Parameters JSON) for a server validation of vs. The server call itself is not yet implemented.

Implementation

ValidationResult validateOnServer(
  FhirNode? vs,
  Map<String, dynamic> pin,
  ValidationOptions options,
) {
  var cache = false;
  if (vs != null) {
    final compose = vs.getChildByName('compose');
    for (final part in ['include', 'exclude']) {
      for (final inc
          in compose?.getChildrenByName(part) ?? const <FhirNode>[]) {
        final system = _s(inc, 'system');
        if (system != null) codeSystemsUsed.add(system);
      }
    }
    final url = _s(vs, 'url');
    final version = _s(vs, 'version');
    if (isTxCaching &&
        cacheId != null &&
        url != null &&
        cached.contains('$url|$version')) {
      _params(pin).add({
        'name': 'url',
        'valueUri': '$url${version != null ? '|$version' : ''}',
      });
    } else if (options.vsAsUrl) {
      _params(pin).add({'name': 'url', if (url != null) 'valueString': url});
    } else {
      _params(pin).add({'name': 'valueSet', 'resource': binding.toJson(vs)});
      if (url != null) cached.add('$url|$version');
    }
    cache = true;
    unawaited(addDependentResources(pin, vs));
  }
  if (cache) {
    _params(pin).add({'name': 'cache-id', 'valueString': cacheId});
  }
  for (final pp in _params(pin)) {
    if ((pp as Map<String, dynamic>)['name'] == 'profile') {
      throw ArgumentError(
        formatMessage('CAN_ONLY_SPECIFY_PROFILE_IN_THE_CONTEXT', []),
      );
    }
  }
  if (expParameters == null) {
    throw ArgumentError(formatMessage('NO_EXPANSIONPROFILE_PROVIDED', []));
  }
  _params(pin).add({'name': 'profile', 'resource': expParameters});
  txLog.clearLastId();
  if (txClient == null) {
    throw ArgumentError(
      formatMessage(
        // ignore: lines_longer_than_80_chars
        'ATTEMPT_TO_USE_TERMINOLOGY_SERVER_WHEN_NO_TERMINOLOGY_SERVER_IS_AVAILABLE',
        [],
      ),
    );
  }
  return ValidationResult.error(message: 'Not yet Implemented');
  // TODO(Dokotela): Implement actual server validation:
  // final pOut = vs == null
  //     ? await txClient!.validateCS(pin)
  //     : await txClient!.validateVS(pin);
  // return processValidationResult(pOut);
}