PHP code example of yannelli / schematic
1. Go to this page and download the library: Download yannelli/schematic library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yannelli / schematic example snippets
use Yannelli\Schematic\Facades\Schematic;
$template = Schematic::create(
slug: 'psychiatric-evaluation',
name: 'Psychiatric Evaluation Note',
description: 'Standard psychiatric evaluation template for initial patient encounters',
);
$template->addSection(
slug: 'chief-complaint',
name: 'Chief Complaint',
description: 'The primary reason the patient is seeking treatment',
content: 'Chief Complaint: {{ complaint }}',
fields: [
[
'name' => 'complaint',
'type' => 'string',
'description' => 'The patient\'s primary complaint in their own words',
'
$template->addSection(
slug: 'mental-status-exam',
name: 'Mental Status Exam',
description: 'Structured mental status examination findings',
content: <<<'TPL'
## Mental Status Exam
- Appearance: {{ appearance }}
- Mood: {{ mood }}
- Affect: {{ affect }}
- Thought Process: {{ thought_process }}
@if(suicidal_ideation)
- **Suicidal Ideation: {{ suicidal_ideation }}**
@endif
TPL,
fields: [
['name' => 'appearance', 'type' => 'string', 'description' => 'General appearance and grooming'],
['name' => 'mood', 'type' => 'string', 'description' => 'Patient\'s self-reported mood'],
['name' => 'affect', 'type' => 'enum', 'description' => 'Observed affect', 'enum' => ['flat', 'blunted', 'constricted', 'full', 'labile']],
['name' => 'thought_process', 'type' => 'string', 'description' => 'Organization and flow of thoughts'],
['name' => 'suicidal_ideation', 'type' => 'string', 'description' => 'Details of suicidal ideation if present', '
$template->addSection(
slug: 'diagnoses',
name: 'Diagnoses',
content: <<<'TPL'
## Diagnoses
@foreach(diagnoses as dx)
- {{ dx.code }}: {{ dx.description }}
@endforeach
TPL,
fields: [
[
'name' => 'diagnoses',
'type' => 'array',
'description' => 'List of ICD-10 diagnoses',
'items' => [
'type' => 'object',
'properties' => [
'code' => ['type' => 'string', 'description' => 'ICD-10 code'],
'description' => ['type' => 'string', 'description' => 'Diagnosis description'],
],
'
use Yannelli\Schematic\Facades\Schematic;
$template = Schematic::ephemeral(
slug: 'intake-form',
name: 'Patient Intake Form',
description: 'A quick intake form built on the fly',
);
$template->addSection(
slug: 'demographics',
name: 'Demographics',
content: '{{ patient_name }}, Age: {{ age }}',
fields: [
['name' => 'patient_name', 'type' => 'string', 'description' => 'Full name'],
['name' => 'age', 'type' => 'integer', 'description' => 'Patient age'],
],
examples: ['patient_name' => 'Jane Doe', 'age' => 34],
);
use Yannelli\Schematic\Ephemeral\EphemeralTemplate;
$template = EphemeralTemplate::make('quick-note', 'Quick Note');
$section = $template->addSection('body', 'Body', content: '{{ note }}');
$section->addField('note', 'string', 'The note content');
// JSON Schema generation
$schema = $template->toJsonSchema();
$doc = $template->toJsonSchemaDocument();
$sectionSchema = $template->sectionSchema('demographics');
// Rendering with data
$output = $template->render([
'demographics' => ['patient_name' => 'Alice Smith', 'age' => 28],
]);
// Preview using example data
$preview = $template->preview();
$template->section('demographics')->disable();
$template->reorderSections(['body', 'demographics']);
foreach ($template->iterateSections() as $section) {
// Only enabled sections
}
use Yannelli\Schematic\Facades\Schematic;
// Schema object
$schema = $template->toJsonSchema();
// Full document with $schema header
$doc = $template->toJsonSchemaDocument();
// Via facade
$schema = Schematic::schema('psychiatric-evaluation');
$doc = Schematic::schemaDocument('psychiatric-evaluation');
$mseSchema = $template->sectionSchema('mental-status-exam');
// Via facade
$sectionSchema = Schematic::sectionSchema('psychiatric-evaluation', 'chief-complaint');
use Anthropic\Anthropic;
use Yannelli\Schematic\Facades\Schematic;
$schema = Schematic::schema('psychiatric-evaluation');
$response = Anthropic::messages()->create([
'model' => 'claude-sonnet-4-20250514',
'max_tokens' => 4096,
'messages' => [
['role' => 'user', 'content' => $transcriptText],
],
'tools' => [
[
'name' => 'generate_note',
'description' => 'Generate a structured psychiatric evaluation note',
'input_schema' => $schema,
],
],
'tool_choice' => ['type' => 'tool', 'name' => 'generate_note'],
]);
use OpenAI\Laravel\Facades\OpenAI;
use Yannelli\Schematic\Facades\Schematic;
$schema = Schematic::schemaDocument('psychiatric-evaluation');
$response = OpenAI::chat()->create([
'model' => 'gpt-4o',
'messages' => [
['role' => 'user', 'content' => $transcriptText],
],
'response_format' => [
'type' => 'json_schema',
'json_schema' => [
'name' => 'psychiatric_evaluation',
'strict' => true,
'schema' => $schema,
],
],
]);
$template->section('diagnoses')->disable();
// Only enabled sections are
$template->section('diagnoses')->enable();
$template->reorderSections([
'chief-complaint',
'diagnoses',
'mental-status-exam',
]);
foreach ($template->iterateSections() as $section) {
echo "{$section->name}: " . ($section->is_enabled ? 'ON' : 'OFF') . "\n";
echo json_encode($section->toJsonSchema(), JSON_PRETTY_PRINT) . "\n\n";
}
foreach ($template->iterateAllSections() as $section) {
// ...
}
$section = $template->section('chief-complaint');
$section->addField(
name: 'onset',
type: 'string',
description: 'When symptoms first appeared',
$data = [
'chief-complaint' => [
'complaint' => 'Increasing anxiety and panic attacks',
],
'mental-status-exam' => [
'appearance' => 'Casually dressed, fidgeting',
'mood' => 'Anxious',
'affect' => 'constricted',
'thought_process' => 'Circumstantial at times',
],
'diagnoses' => [
'diagnoses' => [
['code' => 'F41.0', 'description' => 'Panic disorder'],
],
],
];
echo $template->render($data);
// Via facade
echo Schematic::render('psychiatric-evaluation', $data);
$template->section('chief-complaint')->setExamples([
'complaint' => 'Patient reports difficulty sleeping for the past 2 weeks',
]);
// Preview a single section
echo $template->section('chief-complaint')->preview();
// Preview the entire template
echo $template->preview();
// Via facade
echo Schematic::preview('psychiatric-evaluation');
use Yannelli\Schematic\Facades\Schematic;
public function boot(): void
{
Schematic::macro('component', fn (string $name) => view("components.{$name}")->render());
Schematic::macro('timestamp', fn () => now()->toDateTimeString());
Schematic::macro('badge', fn (string $label, string $color) => "<span class=\"badge badge-{$color}\">{$label}</span>");
}
// config/schematic.php
'models' => [
'template' => App\Models\CustomTemplate::class,
'section' => App\Models\CustomSection::class,
],
use Yannelli\Schematic\Models\Template;
class CustomTemplate extends Template
{
// Add your custom logic
}
bash
php artisan vendor:publish --tag=schematic-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=schematic-config