Skip to content

Commit

Permalink
gimping dstu1 as it isn't worth the effort.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Jan 30, 2025
1 parent 0c0ec9e commit c0f8347
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 32 deletions.
49 changes: 26 additions & 23 deletions template/core/client/class_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@
$coreFiles = $config->getCoreFiles();
$imports = $coreFile->getImports();

$imports->addCoreFileImportsByName(
PHPFHIR_CLIENT_CLASSNAME_CONFIG,
PHPFHIR_CLIENT_CLASSNAME_REQUEST,
PHPFHIR_CLIENT_CLASSNAME_RESPONSE,
PHPFHIR_CLIENT_ENUM_HTTP_METHOD,
);

$confClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_CONFIG);
$reqClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_REQUEST);
$respClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_RESPONSE);
$htMethodEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_ENUM_HTTP_METHOD);
$clientInterface = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_INTERFACE_CLIENT);
$clientConfigClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_CONFIG);
$clientRequestClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_REQUEST);
$clientResponseClass = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_CLASSNAME_RESPONSE);
$clientHTTPMethodEnum = $coreFiles->getCoreFileByEntityName(PHPFHIR_CLIENT_ENUM_HTTP_METHOD);

$imports->addCoreFileImports(
$clientInterface,
$clientConfigClass,
$clientRequestClass,
$clientResponseClass,
$clientHTTPMethodEnum,
);

ob_start();
echo '<?php ';?>declare(strict_types=1);
Expand All @@ -46,12 +49,12 @@
<?php echo ImportUtils::compileImportStatements($imports); ?>

/**
* Class <?php echo PHPFHIR_CLIENT_CLASSNAME_CLIENT; ?>
* Class <?php echo $coreFile->getEntityName(); ?>

*
* Basic implementation of the <?php echo PHPFHIR_CLIENT_INTERFACE_CLIENT; ?> interface.
* Basic implementation of the <?php echo $clientInterface->getEntityName(); ?> interface.
*/
class <?php echo PHPFHIR_CLIENT_CLASSNAME_CLIENT; ?> implements <?php echo PHPFHIR_CLIENT_INTERFACE_CLIENT; ?>
class <?php echo $coreFile->getEntityName(); ?> implements <?php echo $clientInterface->getEntityName(); ?>

{
private const _PARAM_FORMAT = '_format';
Expand All @@ -64,33 +67,33 @@ class <?php echo PHPFHIR_CLIENT_CLASSNAME_CLIENT; ?> implements <?php echo PHPFH
CURLOPT_USERAGENT => 'php-fhir client (build: <?php echo $config->getStandardDate(); ?>;)',
];

protected <?php echo PHPFHIR_CLIENT_CLASSNAME_CONFIG; ?> $_config;
protected <?php echo $clientConfigClass->getEntityName(); ?> $_config;

/**
* <?php echo PHPFHIR_CLIENT_CLASSNAME_CLIENT; ?> Constructor
* <?php echo $coreFile->getEntityName(); ?> Constructor
*
* @param string|<?php echo $confClass->getFullyQualifiedName(true); ?> $config Fully qualified address of FHIR server, or configuration object.
* @param string|<?php echo $clientConfigClass->getFullyQualifiedName(true); ?> $config Fully qualified address of FHIR server, or configuration object.
*/
public function __construct(string|<?php echo PHPFHIR_CLIENT_CLASSNAME_CONFIG; ?> $config)
public function __construct(string|<?php echo $clientConfigClass->getEntityName(); ?> $config)
{
if (is_string($config)) {
$config = new <?php echo PHPFHIR_CLIENT_CLASSNAME_CONFIG; ?>(address: $config);
$config = new <?php echo $clientConfigClass->getEntityName(); ?>(address: $config);
}
$this->_config = $config;
}

public function getConfig(): <?php echo PHPFHIR_CLIENT_CLASSNAME_CONFIG; ?>
public function getConfig(): <?php echo $clientConfigClass->getEntityName(); ?>

{
return $this->_config;
}

/**
* @param <?php echo $reqClass->getFullyQualifiedName(true); ?> $request
* @return <?php echo $respClass->getFullyQualifiedName(true); ?>
* @param <?php echo $clientRequestClass->getFullyQualifiedName(true); ?> $request
* @return <?php echo $clientResponseClass->getFullyQualifiedName(true); ?>

*/
public function exec(<?php echo PHPFHIR_CLIENT_CLASSNAME_REQUEST; ?> $request): <?php echo PHPFHIR_CLIENT_CLASSNAME_RESPONSE; ?>
public function exec(<?php echo $clientRequestClass->getEntityName(); ?> $request): <?php echo $clientResponseClass->getEntityName(); ?>

{
$queryParams = array_merge($this->_config->getQueryParams(), $request->queryParams ?? []);
Expand All @@ -106,7 +109,7 @@ public function exec(<?php echo PHPFHIR_CLIENT_CLASSNAME_REQUEST; ?> $request):
$queryParams[self::_PARAM_COUNT] = $request->count;
}

$rc = new <?php echo PHPFHIR_CLIENT_CLASSNAME_RESPONSE; ?>();
$rc = new <?php echo $clientResponseClass->getEntityName(); ?>();

$url = "{$this->_config->getAddress()}{$request->path}?" . http_build_query($queryParams, '', '&', PHP_QUERY_RFC3986);

Expand Down
11 changes: 7 additions & 4 deletions template/tests/versions/types/class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@

if ($type->isResourceType()) {
$imports
->addVersionTypeImports(
$bundleType
)
->addCoreFileImportsByName(
PHPFHIR_CLIENT_CLASSNAME_CONFIG,
PHPFHIR_CLIENT_CLASSNAME_CLIENT,
Expand All @@ -61,6 +58,12 @@
PHPFHIR_VERSION_CLASSNAME_VERSION_CLIENT,
PHPFHIR_VERSION_ENUM_VERSION_TYPES,
);

if (!$version->getSourceMetadata()->isDSTU1()) {
$imports->addVersionTypeImports(
$bundleType
);
}
}

$typeKind = $type->getKind();
Expand Down Expand Up @@ -145,7 +148,7 @@ public function testCanSetValueFromString()
$this->assertEquals('<?php echo $strVal; ?>', (string)$n);
<?php endforeach; ?>
}
<?php elseif ($type->isResourceType() && !$type->getKind()->isResourceContainer($version)) : ?>
<?php elseif (!$version->getSourceMetadata()->isDSTU1() && $type->isResourceType() && !$type->getKind()->isResourceContainer($version)) : ?>

public function testCanTranscodeBundleJSON()
{
Expand Down
22 changes: 17 additions & 5 deletions template/versions/core/class_version_client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
/** @var \DCarbone\PHPFHIR\Version $version */
/** @var \DCarbone\PHPFHIR\CoreFile $coreFile */

$sourceMeta = $version->getSourceMetadata();

$types = $version->getDefinition()->getTypes();

$idType = $types->getTypeByName('id');
Expand All @@ -46,7 +48,7 @@
);

foreach($types->getIterator() as $type) {
if ($type->isResourceType() && !$type->isAbstract() && !$type->getKind()->isResourceContainer($version)) {
if (($type->isResourceType() || $type->hasResourceTypeParent()) && !$type->isAbstract() && !$type->getKind()->isResourceContainer($version)) {
$imports->addVersionTypeImports($type);
}
}
Expand Down Expand Up @@ -98,12 +100,12 @@ public function __construct(<?php echo PHPFHIR_CLIENT_INTERFACE_CLIENT; ?> $clie
}

/**
* Queries for one or more resources of a given type, returning the raw response fromm the server.
* Queries for one <?php if ($sourceMeta->isDSTU1()) : ?>resource<?php else : ?>or more resources<?php endif; ?> of a given type, returning the raw response fromm the server.
*
* @see https://www.hl7.org/fhir/http.html#read
*
* @param <?php echo $versionTypeEnum->getFullyQualifiedName(true); ?> $resourceType
* @param null|string|<?php echo $idType->getFullyQualifiedClassName(true); ?>|<?php echo $idPrimitiveType->getFullyQualifiedClassName(true); ?> $resourceID
* @param <?php if (!$sourceMeta->isDSTU1()) : ?>null|<?php endif; ?>string|<?php echo $idType->getFullyQualifiedClassName(true); ?>|<?php echo $idPrimitiveType->getFullyQualifiedClassName(true); ?> $resourceID
* @param null|int $count
* @param null|string|<?php echo $clientSortEnum->getFullyQualifiedName(true); ?> $sort May be a string value if your server supports non-standard sorting methods
* @param null|<?php echo $clientResponseFormatEnum->getFullyQualifiedName(true); ?> $format
Expand All @@ -114,7 +116,7 @@ public function __construct(<?php echo PHPFHIR_CLIENT_INTERFACE_CLIENT; ?> $clie
* @throws \Exception
*/
public function readRaw(<?php echo PHPFHIR_VERSION_ENUM_VERSION_TYPES; ?> $resourceType,
null|string|<?php echo $idType->getClassName(); ?>|<?php echo $idPrimitiveType->getClassName(); ?> $resourceID = null,
<?php if (!$sourceMeta->isDSTU1()) : ?>null|<?php endif; ?>string|<?php echo $idType->getClassName(); ?>|<?php echo $idPrimitiveType->getClassName(); ?> $resourceID<?php if (!$sourceMeta->isDSTU1()) : ?> = null<?php endif; ?>,
null|int $count = null,
null|string|<?php echo PHPFHIR_CLIENT_ENUM_SORT_DIRECTION; ?> $sort = null,
null|<?php echo PHPFHIR_CLIENT_ENUM_RESPONSE_FORMAT; ?> $format = null,
Expand All @@ -124,13 +126,21 @@ public function readRaw(<?php echo PHPFHIR_VERSION_ENUM_VERSION_TYPES; ?> $resou
{

$path = "/{$resourceType->value}";
<?php if ($sourceMeta->isDSTU1()) : ?>
$resourceID = trim((string)$resourceID);
if ('' === $resourceID) {
throw new \InvalidArgumentException('Resource ID must be null or valued.');
}
$path .= "/{$resourceID}";
<?php else : ?>
if (null !== $resourceID) {
$resourceID = trim((string)$resourceID);
if ('' === $resourceID) {
throw new \InvalidArgumentException('Resource ID must be null or valued.');
}
$path .= "/{$resourceID}";
}
<?php endif; ?>
$req = new <?php echo PHPFHIR_CLIENT_CLASSNAME_REQUEST; ?>(
method: <?php echo PHPFHIR_CLIENT_ENUM_HTTP_METHOD; ?>::GET,
path: $path,
Expand All @@ -153,6 +163,7 @@ public function readRaw(<?php echo PHPFHIR_VERSION_ENUM_VERSION_TYPES; ?> $resou
return $this->_client->exec($req);
}

<?php if (!$sourceMeta->isDSTU1()) : ?>
/**
* Queries for one or more resources of a given type, returning the unserialized response from the server.
*
Expand Down Expand Up @@ -183,6 +194,7 @@ public function read(<?php echo PHPFHIR_VERSION_ENUM_VERSION_TYPES; ?> $resource
return <?php echo PHPFHIR_CLASSNAME_RESPONSE_PARSER; ?>::parse($this->_version, $rc->resp);
}

<?php endif; ?>
/**
* @param <?php echo $clientResponseClass->getFullyQualifiedName(true); ?> $rc
* @throws <?php echo $clientErrorException->getFullyQualifiedName(true); ?>
Expand All @@ -200,7 +212,7 @@ protected function _requireOK(<?php echo PHPFHIR_CLIENT_CLASSNAME_RESPONSE; ?> $
}
}
<?php foreach($version->getDefinition()->getTypes()->getNameSortedIterator() as $rsc) :
if (!$rsc->isResourceType() || $rsc->isAbstract() || $rsc->getKind()->isResourceContainer($version)) {
if (!($rsc->isResourceType() || $rsc->hasResourceTypeParent()) || $rsc->isAbstract() || $rsc->getKind()->isResourceContainer($version)) {
continue;
}

Expand Down

0 comments on commit c0f8347

Please sign in to comment.