Replies: 3 comments 2 replies
-
Can you elaborate a little, or give an example? |
Beta Was this translation helpful? Give feedback.
-
Sure. My idea : <?php
namespace App\Service\HL7;
/**
*
*/
class DataType
{
protected $fields;
public function __construct(array $fields = null)
{
$this->fields = [];
if (\is_array($fields)) {
foreach ($fields as $i => $value) {
$this->setField($i + 1, $value);
}
}
}
public function setField(int $index, $value = ''): bool
{
if ($this->isValueEmpty($value)) {
return false;
}
// Fill in the blanks...
for ($i = \count($this->fields); $i < $index; $i++) {
$this->fields[$i] = '';
}
$this->fields[$index] = $value;
return true;
}
private function isValueEmpty($value): bool
{
if (is_array($value)) {
return empty($value);
}
if ((string) $value === '0') { // Allow 0
return false;
}
return ! $value;
}
/**
* Remove any existing value from the field
*
* @param int $index Field index
* @return void
*/
public function clearField(int $index): void
{
$this->fields[$index] = null;
}
public function getField(int $index)
{
return $this->fields[$index] ?? null;
}
public function size(): int
{
return \count($this->fields) ;
}
public function getFields(int $from = 0, int $to = null): array
{
if (!$to) {
$to = \count($this->fields);
}
return \array_slice($this->fields, $from, $to - $from + 1);
}
} This way, the developer has just to extend DataType and add one to the parent segment by using : $rol = new ROL();
// XCN extends Datatype
$xcn = new XCN();
$xcn->setFamilyName('Cloooonaye');
$xcn->setGivenName('Djorge');
$rol->setRolePerson($xcn->getFields()); |
Beta Was this translation helpful? Give feedback.
-
Thank you for the explanation. This looks quite interesting. If it can be implemented without any changes to the existing code or functionality then feel free to take it up. Please don't forget to add tests. Otherwise I can get to it if you can wait for a few more weeks |
Beta Was this translation helpful? Give feedback.
-
What about DataTypes support, in a way looking like the Segments support ?
Beta Was this translation helpful? Give feedback.
All reactions