Skip to content

Commit

Permalink
ok, primitive and value container type differences in place, need to …
Browse files Browse the repository at this point in the history
…update rest of generator...
  • Loading branch information
dcarbone committed Jan 31, 2025
1 parent 70c7868 commit 555b8b1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/Version/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Version/Definition/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
48 changes: 21 additions & 27 deletions src/Version/Definition/TypeDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(),
Expand All @@ -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();
Expand Down Expand Up @@ -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.
Expand All @@ -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;
}

Expand All @@ -315,50 +318,41 @@ 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
// cases does) conflict with a top level Element or Resource. Because of this, they are treated differently
// 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/**
* @param <?php if ($type->isResourceType() || $type->hasResourceTypeParent()) : ?>null|<?php endif; echo $xmlWriterClass->getFullyQualifiedName(true); ?> $xw
* @param <?php if ($type->isResourceType() || $type->hasResourceTypeParent()) : ?>null|<?php endif; echo $serializeConfigClass->getFullyQualifiedName(true); ?> $config
<?php if ($type->isValueContainer() || $type->hasValueContainerParent()) : ?>
<?php if ($type->isPrimitiveContainer() || $type->hasPrimitiveContainerParent() || $type->isValueContainer() || $type->hasValueContainerParent()) : ?>
* @param null|<?php echo $xmlLocationEnum->getFullyQualifiedName(true); ?> $valueLocation
<?php endif; ?>
<?php if ($type->isResourceType() || $type->hasResourceTypeParent()) : ?>
Expand All @@ -45,7 +45,7 @@
*/
public function xmlSerialize(<?php if ($type->isResourceType() || $type->hasResourceTypeParent()) : ?>null|<?php endif; echo $xmlWriterClass->getEntityName(); ?> $xw<?php if ($type->isResourceType() || $type->hasResourceTypeParent()) : ?> = null<?php endif; ?>,
<?php if ($type->isResourceType() || $type->hasResourceTypeParent()) : ?>null|<?php endif; echo $serializeConfigClass->getEntityName(); ?> $config<?php if ($type->isResourceType() || $type->hasResourceTypeParent()) : ?> = null<?php endif;
if ($type->isValueContainer() || $type->hasValueContainerParent()) : ?>,
if ($type->isPrimitiveContainer() || $type->hasPrimitiveContainerParent() || $type->isValueContainer() || $type->hasValueContainerParent()) : ?>,
null|<?php echo $xmlLocationEnum->getEntityName(); ?> $valueLocation = null<?php endif; ?>): <?php if ($type->isResourceType() || $type->hasResourceTypeParent()) : echo $xmlWriterClass->getEntityName(); else : ?>void<?php endif; ?>

{
Expand All @@ -67,7 +67,7 @@ public function xmlSerialize(<?php if ($type->isResourceType() || $type->hasReso
$rootOpened = true;
$xw->openRootNode('<?php echo NameUtils::getTypeXMLElementName($type); ?>', $this->_getSourceXMLNS());
}
<?php elseif ($type->isValueContainer() || $type->hasValueContainerParent()) : ?>
<?php elseif ($type->isPrimitiveContainer() || $type->hasPrimitiveContainerParent() || $type->isValueContainer() || $type->hasValueContainerParent()) : ?>
$valueLocation = $valueLocation ?? $this->_valueXMLLocations[self::FIELD_VALUE];
<?php endif;

Expand Down

0 comments on commit 555b8b1

Please sign in to comment.