OEModule\PatientTicketing\components\Substitution::replace PHP Method

replace() public static method

public static replace ( $text, $patient ) : mixed
$text
$patient
return mixed
    public static function replace($text, $patient)
    {
        preg_match_all('/\\[([a-z]{3})\\]/is', $text, $m);
        foreach ($m[1] as $el) {
            $count = \PatientShortcode::model()->count('code=?', array(strtolower($el)));
            if ($count == 1) {
                if ($code = \PatientShortcode::model()->find('code=?', array(strtolower($el)))) {
                    $text = $code->replaceText($text, $patient, (bool) preg_match('/^[A-Z]/', $el));
                }
            } elseif ($count > 1) {
                throw new \Exception("Multiple shortcode definitions for {$el}");
            }
        }
        return $text;
    }

Usage Example

 public function generateReportText()
 {
     $this->report = \OEModule\PatientTicketing\components\Substitution::replace($this->replaceAssignmentCodes($this->queue->report_definition), $this->ticket->patient);
 }
Substitution