feat: replace patient messages tab with pinnable notes
Port the tauri AddNoteModal notes feature into the admin patient case-file,
replacing the mislabeled «پیامها» (SMS log) tab with «یادداشتها».
Backend (src/Patient):
- PatientNote entity + repository (record-scoped, pinned-first ordering)
- CRUD endpoints on PatientController: GET /notes, POST /note,
PATCH /note/{uuid} (edit body + toggle pin), DELETE /note/{uuid}
- author display name captured server-side from the current user
- migration for patient_notes; docs/api/patient.md updated
Frontend (assets/admin):
- NotesTab: compose box, newest/oldest sort, pinned-first list with
accent rail + pin/edit/delete, edit modal, confirm-delete, empty state
- tab key/label/icon messages -> notes; onAddNote deep-links the notes tab
Tests: PatientNoteTest (create/list-order/edit/pin/delete/validation/ownership),
PatientDetailPage notes cases (render/empty/pin/create).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace App\Patient\Entity;
|
||||
|
||||
use App\Auth\Entity\User;
|
||||
use App\Patient\Repository\PatientNoteRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
/**
|
||||
* A personal, pinnable staff note attached to a patient record (the «یادداشتها» tab).
|
||||
* Shared across the staff who own the record; the author's display name is denormalised
|
||||
* so the note survives the author being deleted.
|
||||
*/
|
||||
#[ORM\Entity(repositoryClass: PatientNoteRepository::class)]
|
||||
#[ORM\Table(name: 'patient_notes')]
|
||||
#[ORM\Index(columns: ['record_id'], name: 'idx_patient_notes_record')]
|
||||
class PatientNote
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column(type: 'integer')]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 36, unique: true)]
|
||||
private string $uuid;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: PatientRecord::class)]
|
||||
#[ORM\JoinColumn(name: 'record_id', nullable: false, onDelete: 'CASCADE')]
|
||||
private PatientRecord $record;
|
||||
|
||||
/** متن یادداشت — free-text body. */
|
||||
#[ORM\Column(type: 'text')]
|
||||
private string $body;
|
||||
|
||||
/** یادداشتهای پینشده بالای لیست نشان داده میشوند. */
|
||||
#[ORM\Column(type: 'boolean')]
|
||||
private bool $pinned = false;
|
||||
|
||||
/** The staff user who wrote the note; kept for possible audit, nulled if they are removed. */
|
||||
#[ORM\ManyToOne(targetEntity: User::class)]
|
||||
#[ORM\JoinColumn(name: 'created_by', nullable: true, onDelete: 'SET NULL')]
|
||||
private ?User $createdBy = null;
|
||||
|
||||
/** Denormalised author display name (survives user deletion). */
|
||||
#[ORM\Column(name: 'author_name', type: 'string', length: 120, nullable: true)]
|
||||
private ?string $authorName = null;
|
||||
|
||||
#[ORM\Column(name: 'created_at', type: 'integer')]
|
||||
private int $createdAt;
|
||||
|
||||
#[ORM\Column(name: 'updated_at', type: 'integer', nullable: true)]
|
||||
private ?int $updatedAt = null;
|
||||
|
||||
public function __construct(PatientRecord $record, string $body, bool $pinned = false)
|
||||
{
|
||||
$this->uuid = Uuid::v4()->toRfc4122();
|
||||
$this->record = $record;
|
||||
$this->body = $body;
|
||||
$this->pinned = $pinned;
|
||||
$this->createdAt = time();
|
||||
}
|
||||
|
||||
public function getId(): ?int { return $this->id; }
|
||||
public function getUuid(): string { return $this->uuid; }
|
||||
public function getRecord(): PatientRecord { return $this->record; }
|
||||
public function isPinned(): bool { return $this->pinned; }
|
||||
|
||||
public function setBody(string $body): self { $this->body = $body; $this->touch(); return $this; }
|
||||
public function setPinned(bool $pinned): self { $this->pinned = $pinned; $this->touch(); return $this; }
|
||||
|
||||
public function setAuthor(?User $user, ?string $name): self
|
||||
{
|
||||
$this->createdBy = $user;
|
||||
$this->authorName = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function touch(): void { $this->updatedAt = time(); }
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'uuid' => $this->uuid,
|
||||
'body' => $this->body,
|
||||
'pinned' => $this->pinned,
|
||||
'author' => $this->authorName,
|
||||
'created_at' => $this->createdAt,
|
||||
'updated_at' => $this->updatedAt,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user