Services\DataObject::fromFhir PHP Method

fromFhir() public static method

Convert a FHIR object into a service layer object.
public static fromFhir ( $fhir_object ) : DataObject
return DataObject
    public static function fromFhir($fhir_object)
    {
        $fhir_object = clone $fhir_object;
        $fhir_type = static::getFhirType();
        $schema = \Yii::app()->fhirMarshal->getSchema($fhir_type);
        foreach ($fhir_object as $name => &$value) {
            if ($name == 'resourceType' || $name[0] == '_') {
                continue;
            }
            $valueType = $schema[$name]['type'];
            $class = static::getServiceClass($valueType);
            if (!$class) {
                continue;
            }
            switch (gettype($value)) {
                case 'object':
                    $value = $class::fromFhir($value);
                    break;
                case 'array':
                    foreach ($value as &$v) {
                        $v = $class::fromFhir($v);
                    }
            }
        }
        $values = static::getFhirTemplate()->match($fhir_object, $warnings);
        if (is_null($values)) {
            throw new InvalidStructure("Failed to match object of type '{$fhir_type}': " . implode('; ', $warnings));
        }
        return static::fromFhirValues($values);
    }