diff --git a/src/Version/Definition.php b/src/Version/Definition.php index 32da36d7..2a015722 100644 --- a/src/Version/Definition.php +++ b/src/Version/Definition.php @@ -93,7 +93,7 @@ public function buildDefinition(): void // TODO: order of operations issue here, ideally this would be first... $log->info('Determining type kinds'); - TypeDecorator::determineParsedTypeKinds($this->_config, $this->_version, $this->_types); + TypeDecorator::determineParsedTypeKinds($this->_version, $this->_types); $log->info('Determining Primitive Type kinds'); TypeDecorator::determinePrimitiveTypes($this->_config, $this->_types); diff --git a/src/Version/Definition/Type.php b/src/Version/Definition/Type.php index 4e0781d6..228d9d13 100644 --- a/src/Version/Definition/Type.php +++ b/src/Version/Definition/Type.php @@ -903,7 +903,7 @@ public function getDirectlyImplementedInterfaces(): array } } else if ($this->isPrimitiveContainer()) { if (!$this->hasPrimitiveContainerParent()) { - $interfaces[PHPFHIR_TYPES_INTERFACE_PRIMITIVE_TYPE] = $coreFiles + $interfaces[PHPFHIR_TYPES_INTERFACE_PRIMITIVE_CONTAINER_TYPE] = $coreFiles ->getCoreFileByEntityName(PHPFHIR_TYPES_INTERFACE_PRIMITIVE_CONTAINER_TYPE) ->getFullyQualifiedNamespace(false); } diff --git a/src/Version/Definition/TypeDecorator.php b/src/Version/Definition/TypeDecorator.php index ff62fec8..2b6b1445 100644 --- a/src/Version/Definition/TypeDecorator.php +++ b/src/Version/Definition/TypeDecorator.php @@ -216,10 +216,6 @@ public static function determinePrimitiveTypes(Config $config, Types $types): vo continue; } - if (!str_ends_with($ptn, '-primitive')) { - continue; - } - $logger->debug(sprintf('Setting assumed primitive Type "%s" kind to "%s"', $type->getFHIRName(), $ptn)); $ptn = str_replace('-primitive', '', $ptn); $pt = PrimitiveTypeEnum::from($ptn); @@ -235,18 +231,18 @@ public static function determinePrimitiveTypes(Config $config, Types $types): vo } /** - * @param \DCarbone\PHPFHIR\Config $config + * @param \DCarbone\PHPFHIR\Version $version * @param \DCarbone\PHPFHIR\Version\Definition\Types $types * @param \DCarbone\PHPFHIR\Version\Definition\Type $type * @param TypeKindEnum|string $kind */ - private static function setTypeKind(Config $config, Types $types, Type $type, TypeKindEnum|string $kind): void + private static function setTypeKind(Version $version, Types $types, Type $type, TypeKindEnum|string $kind): void { if (is_string($kind)) { $kind = TypeKindEnum::from($kind); } $type->setKind($kind); - $config->getLogger()->info( + $version->getConfig()->getLogger()->info( sprintf( 'Setting Type "%s" to Kind "%s"', $type->getFHIRName(), @@ -256,12 +252,11 @@ private static function setTypeKind(Config $config, Types $types, Type $type, Ty } /** - * @param \DCarbone\PHPFHIR\Config $config * @param \DCarbone\PHPFHIR\Version $version * @param \DCarbone\PHPFHIR\Version\Definition\Types $types * @param \DCarbone\PHPFHIR\Version\Definition\Type $type */ - private static function determineParsedTypeKind(Config $config, Version $version, Types $types, Type $type): void + private static function determineParsedTypeKind(Version $version, Types $types, Type $type): void { $logger = $version->getConfig()->getLogger(); $fhirName = $type->getFHIRName(); @@ -290,14 +285,22 @@ private static function determineParsedTypeKind(Config $config, Version $version // check if type is primitive... if (str_ends_with($fhirName, PHPFHIR_PRIMITIVE_SUFFIX)) { $logger->debug(sprintf('Type "%s" has primitive suffix, setting kind to "%s"', $type->getFHIRName(), TypeKindEnum::PRIMITIVE->value)); - self::setTypeKind($config, $types, $type, TypeKindEnum::PRIMITIVE); + self::setTypeKind($version, $types, $type, TypeKindEnum::PRIMITIVE); + return; + } + + // check if type is list... + if (str_ends_with($fhirName, PHPFHIR_LIST_SUFFIX)) { + // for all intents and purposes, a List type is a multiple choice primitive type + $logger->debug(sprintf('Type "%s" has list suffix, setting kind to "%s"', $type->getFHIRName(), TypeKindEnum::LIST->value)); + self::setTypeKind($version, $types, $type, TypeKindEnum::LIST); return; } // if this is a root type, i.e. it has no parents, set its kind to itself if ($type->isRootType()) { $logger->debug(sprintf('Type "%s" has no parent, setting kind to itself...', $type->getFHIRName())); - self::setTypeKind($config, $types, $type, $fhirName); + self::setTypeKind($version, $types, $type, $fhirName); } // otherise, localize root type. @@ -306,7 +309,7 @@ private static function determineParsedTypeKind(Config $config, Version $version // if this is the "container" type for this FHIR version if (TypeKindEnum::isContainerTypeName($version, $fhirName)) { $logger->debug(sprintf('Type "%s" is a container type, setting kind to "%s"', $type->getFHIRName(), $fhirName)); - self::setTypeKind($config, $types, $type, $fhirName); + self::setTypeKind($version, $types, $type, $fhirName); return; } @@ -315,15 +318,7 @@ private static function determineParsedTypeKind(Config $config, Version $version // than just fhir-all or something. if ($rootType !== $type && null === $rootType->getKind()) { $logger->debug(sprintf('Type "%s" has root Type "%s" with undefined Kind, determining now', $type->getFHIRName(), $rootType->getFHIRName())); - self::determineParsedTypeKind($config, $version, $types, $rootType); - } - - // check if type is list... - if (str_ends_with($fhirName, PHPFHIR_LIST_SUFFIX)) { - // for all intents and purposes, a List type is a multiple choice primitive type - $logger->debug(sprintf('Type "%s" has list suffix, setting kind to "%s"', $type->getFHIRName(), TypeKindEnum::LIST->value)); - self::setTypeKind($config, $types, $type, TypeKindEnum::LIST); - return; + self::determineParsedTypeKind($version, $types, $rootType); } // This block indicates the type is only present as the child of a Resource. Its name may (and in many @@ -331,34 +326,33 @@ private static function determineParsedTypeKind(Config $config, Version $version // and must be marked as such. if (str_contains($fhirName, '.') && !$sourceMeta->isDSTU1() && TypeKindEnum::RESOURCE_INLINE->value !== $fhirName) { $logger->debug(sprintf('Type "%s" is not "%s" but has dot in name, setting kind to "%s"', $type->getFHIRName(), TypeKindEnum::RESOURCE_INLINE->value, TypeKindEnum::RESOURCE_COMPONENT->value)); - self::setTypeKind($config, $types, $type, TypeKindEnum::RESOURCE_COMPONENT); + self::setTypeKind($version, $types, $type, TypeKindEnum::RESOURCE_COMPONENT); return; } // special block for xhtml type if (PHPFHIR_XHTML_TYPE_NAME === $type->getFHIRName()) { $logger->debug(sprintf('Setting Type "%s" kind to itself ("%s")', $type->getFHIRName(), TypeKindEnum::PHPFHIR_XHTML->value)); - self::setTypeKind($config, $types, $type, TypeKindEnum::PHPFHIR_XHTML); + self::setTypeKind($version, $types, $type, TypeKindEnum::PHPFHIR_XHTML); return; } // otherwise, set kind to that of its parent $logger->debug(sprintf('Setting Type "%s" kind to it parent ("%s")', $type->getFHIRName(), $rootType->getKind()->value)); - self::setTypeKind($config, $types, $type, $rootType->getKind()); + self::setTypeKind($version, $types, $type, $rootType->getKind()); } /** * This method is specifically designed to determine the "kind" of every type that was successfully * parsed from the provided xsd's. It does NOT handle value or undefined types. * - * @param \DCarbone\PHPFHIR\Config $config * @param \DCarbone\PHPFHIR\Version $version * @param \DCarbone\PHPFHIR\Version\Definition\Types $types */ - public static function determineParsedTypeKinds(Config $config, Version $version, Types $types): void + public static function determineParsedTypeKinds(Version $version, Types $types): void { foreach ($types->getIterator() as $type) { - self::determineParsedTypeKind($config, $version, $types, $type); + self::determineParsedTypeKind($version, $types, $type); } } diff --git a/template/versions/types/serialization/xml/serialize/header.php b/template/versions/types/serialization/xml/serialize/header.php index 26fd4f8c..07fccd3a 100644 --- a/template/versions/types/serialization/xml/serialize/header.php +++ b/template/versions/types/serialization/xml/serialize/header.php @@ -35,7 +35,7 @@ /** * @param isResourceType() || $type->hasResourceTypeParent()) : ?>null|getFullyQualifiedName(true); ?> $xw * @param isResourceType() || $type->hasResourceTypeParent()) : ?>null|getFullyQualifiedName(true); ?> $config -isValueContainer() || $type->hasValueContainerParent()) : ?> +isPrimitiveContainer() || $type->hasPrimitiveContainerParent() || $type->isValueContainer() || $type->hasValueContainerParent()) : ?> * @param null|getFullyQualifiedName(true); ?> $valueLocation isResourceType() || $type->hasResourceTypeParent()) : ?> @@ -45,7 +45,7 @@ */ public function xmlSerialize(isResourceType() || $type->hasResourceTypeParent()) : ?>null|getEntityName(); ?> $xwisResourceType() || $type->hasResourceTypeParent()) : ?> = null, isResourceType() || $type->hasResourceTypeParent()) : ?>null|getEntityName(); ?> $configisResourceType() || $type->hasResourceTypeParent()) : ?> = nullisValueContainer() || $type->hasValueContainerParent()) : ?>, + if ($type->isPrimitiveContainer() || $type->hasPrimitiveContainerParent() || $type->isValueContainer() || $type->hasValueContainerParent()) : ?>, null|getEntityName(); ?> $valueLocation = null): isResourceType() || $type->hasResourceTypeParent()) : echo $xmlWriterClass->getEntityName(); else : ?>void { @@ -67,7 +67,7 @@ public function xmlSerialize(isResourceType() || $type->hasReso $rootOpened = true; $xw->openRootNode('', $this->_getSourceXMLNS()); } -isValueContainer() || $type->hasValueContainerParent()) : ?> +isPrimitiveContainer() || $type->hasPrimitiveContainerParent() || $type->isValueContainer() || $type->hasValueContainerParent()) : ?> $valueLocation = $valueLocation ?? $this->_valueXMLLocations[self::FIELD_VALUE];