コード例 #1
0
def merge_json_fhir_string_into_proto(
        raw_json: str,
        target: message.Message,
        *,
        validate: bool = True,
        default_timezone: str = _primitive_time_utils.SIMPLE_ZULU):
    """Merges the provided raw_json string into a target Message.

  Args:
    raw_json: The JSON to parse and merge into target.
    target: The Message instance to merge raw_json into.
    validate: A Boolean value indicating if validation should be performed on
      the resultant Message. Validation takes the form of ensuring that basic
      checks such as cardinality guarantees, required field adherence, etc. are
      met. Defaults to True.
    default_timezone: A string specifying the timezone string to use for time-
      like FHIR data during parsing. Defaults to 'Z'.

  Raises:
    fhir_errors.InvalidFhirError: In the event that validation fails after
    parsing.
  """
    json_value = json.loads(raw_json,
                            parse_float=decimal.Decimal,
                            parse_int=decimal.Decimal)

    parser = _json_parser.JsonParser.json_parser_with_default_timezone(
        _PRIMITIVE_HANDLER, default_timezone=default_timezone)
    parser.merge_value(json_value, target)
    if validate:
        resource_validation.validate_resource(target, _PRIMITIVE_HANDLER)
コード例 #2
0
ファイル: resource_validation.py プロジェクト: anniyanvr/fhir
def validate_resource(resource: message.Message) -> None:
    """Performs basic FHIR constraint validation on the provided resource."""
    resource_validation.validate_resource(resource, _PRIMITIVE_HANDLER)