Commit Graph

151 Commits

Author SHA1 Message Date
1be735a7ab fix(voice): say the quadrant is missing instead of "could not be read"
"ترمیم برای دندون دو" set the treatment type but reported the tooth as
unreadable. Nothing was misheard: position 2 arrived intact, with no
quadrant, because none was spoken — four teeth carry position 2 and the
resolver correctly refused to pick one. Only the label was wrong, and it
sent the clinician looking for a transcription fault.

Adds a tooth_missing_quadrant reason that names what is missing and shows
how to say it ("دو بالا راست"), and tells the model explicitly to report a
quadrant-less number with arch and side null rather than guessing.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-23 23:05:30 +03:30
3f97940a16 feat: wire voice entry into the treatment workspace
Makes the feature reachable end to end: availability is fetched alongside the
catalogs, the capture hook drives the segmented control, and confirming the
review sheet appends a new detail.

Confirm always appends — it never edits an existing detail and never calls
onAddDetail. Ticked rows land on top of the seeded defaults, so unticking the
type row leaves the appointment-purpose default rather than a blank. Lab-side
rows ride on a lab case draft keyed by the detail's *client* id, so a brand-new
unsaved detail can carry a lab, due date and per-tooth prosthesis map.

Availability comes from the API rather than a NEXT_PUBLIC_* var, since those are
baked in at build time; a failure fetching it degrades to no microphone rather
than taking the treatment tab down.

From review of this commit:

- Unticking "teeth" while leaving "prosthesis" ticked attached prosthesis rows
  for teeth the detail does not contain. Nothing downstream filters them —
  assertCompleteToothProsthesisMap only checks detail-teeth ⊆ map, never the
  reverse — so they would have reached task generation as lab work for teeth
  nobody is treating. The map is now filtered to the detail's own teeth.
- The microphone was gated on the URL locale while the server resolved
  everything from req.user.language. Those diverge (a bookmarked /fa/ URL, a
  language toggle whose save failed), which would transcribe Persian with an
  English hint and anchor "next Thursday" to a Monday week instead of a Saturday
  one — or 403 from a visibly-enabled button. The client now sends the locale the
  microphone was offered in, so the gate and the request agree by construction.

Also fixed from the previous review: a civil YYYY-MM-DD date rendered a day
early west of Greenwich (parsed as UTC midnight); the missing-teeth list
hardcoded the Arabic comma for all locales; and voiceApply had no ICU plural, so
the common single-field case read "Apply 1 fields".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-23 23:05:30 +03:30
c07f550e00 feat(frontend): split Add detail into a segmented control with voice
The microphone becomes the second segment of the Add detail button, built like
the detail chip's trash affordance in the same file — an overflow-hidden rounded
wrapper holding two raw <button>s divided by border-s — rather than two shared
Buttons, which each hardcode their own rounding and would fight a segmented
control. border-s puts the mic at the logical end: visually right in en/nl,
visually left in fa, on the same side as the chip's trash in both directions.

The two halves share a wrapper and nothing else. Add keeps its exact behaviour.

The control never changes size while recording; the timer and level meter live
in a bar between the header row and the chip strip, because the header is
sm:justify-between and growing the button would shove the row on every start and
stop. The meter exists to prove the microphone is actually hearing something —
silence and a dead mic look identical otherwise.

Voice reaches the editor as one optional `voice` prop, so its absence *is* the
unavailable state and the two cannot disagree.

Fixes from review of this commit:

- mountedRef was set false on unmount and never re-armed, so under StrictMode
  the hook was permanently "unmounted" in dev and recording silently never
  started.
- onStart guarded only on `phase`, which does not change until getUserMedia
  resolves; a second click during the permission prompt orphaned the first
  MediaStream, leaving the mic indicator lit.
- Week start is now per locale. "Next Thursday" is week-relative, and hardcoding
  Saturday put an en/nl clinician's deadline a week out.
- A missing `which` on a weekday intent is read as "this" rather than failing —
  a bare weekday carries no qualifier, and rejecting it discarded a real
  deadline.
- durationMs is client-reported and so is a claim, not enforcement; the cap is
  now also checked against the vendor's own usage.seconds.
- Blob type falls back to the recorder's actual mimeType before webm, so old
  Safari's mp4/aac clips are not mislabelled.

Two review findings were rejected as incorrect, both re-verified against live
sources: google/gemini-3.7-flash does exist on OpenRouter (1M context,
$0.375/$1.875 per M), and base64 JSON input_audio is the documented primary
path for /audio/transcriptions, with multipart as the OpenAI-compatible
alternative. The spec's stale "unverified" note is corrected, and the provider
now has unit tests covering the request shape, usage parsing, and that a vendor
error body never reaches the thrown message.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-23 23:05:30 +03:30
93c6513df6 feat(frontend): voice capture hook, API client and types
MediaRecorder handling and the API call live in lib/, not in ui/, so
TreatmentDetailsEditor can stay presentational and take only a `voice` prop.

Container choice is made at record time and needs no transcode: Chrome and
Android give webm/opus, Safari and iPad give mp4/aac, and the transcription
endpoint accepts both. Safari's `audio/mp4` is sent as `m4a`, the name the
vendor's container list actually uses, so iPad recordings do not fail while
Chrome works. Older Safari shipped MediaRecorder without isTypeSupported, so
that path lets the browser choose rather than refusing outright.

From review of this commit:

- The auto-stop at maxMs guaranteed a 413. The client measures the final length
  after the recorder has stopped, so a recording that runs to the cap always
  reports slightly over it, and the server rejected exactly the recording the
  auto-stop existed to save. The server now allows a documented 2s tolerance and
  the client keeps reporting the true length, so telemetry stays honest.
- getUserMedia is async, so a permission granted after unmount installed a live
  stream the cleanup effect had already run past — leaving the browser's
  recording indicator lit with nothing listening. Guarded with a mounted ref.
- Client-side failures are now ApiError-shaped ({code, statusCode}) rather than
  bare Errors, because getUserFacingError only resolves that shape; without it
  errors.VOICE_MIC_DENIED was dead in all three locales.

Cancelling aborts the request, which closes the connection and aborts the
metered vendor call server-side rather than letting it settle unseen. The level
meter is best-effort: a blocked AudioContext costs the meter, not the recording.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-23 23:05:30 +03:30
db9d7d280a feat(backend): voice extraction endpoint
POST /voice/extract behind JwtAuthGuard + ClinicOrgGuard, plus
GET /voice/availability so the frontend can decide whether to render the
microphone — it cannot learn that from NEXT_PUBLIC_*, which are baked in at
build time.

Audio is held in memory for the request only: never written to disk, never a
Prisma row. The transcript goes back to the client and is not persisted. What
is logged is structured and patient-free — clip length, which fields resolved,
unresolved count, vendor cost, outcome — with log lines as the interim sink
until this repo has metrics infrastructure.

On extraction failure the transcript still travels back in the error details,
so the words the clinician already paid for can be salvaged into a note.

v1 ships ungated beyond a configured locale profile; the Plan.features design
is deferred, not dropped.

From review of this commit, four of which were load-bearing:

- Express's 100 kb default body limit rejected any recording past ~20 seconds,
  making the endpoint unusable at its own 2-minute cap. Body parsers are now
  registered explicitly with a 10 MB limit scoped to the voice route only.
  Verified empirically: 600 KB reaches /api/voice/extract, while /api/auth/login
  still 413s.
- ThrottlerGuard keys on req.ip, so behind nginx the whole deployment would
  share one bucket and an abuser rotating IPs would bypass it. VoiceThrottlerGuard
  keys on the user id instead — with no plan gate, this is the only control on
  metered vendor spend.
- ThrottlerException had no 429 fallback and surfaced as INTERNAL_ERROR; the
  guard now throws VOICE_RATE_LIMITED directly.
- durationMs was optional, so omitting it bypassed VOICE_MAX_RECORDING_MS
  entirely. It is required.
- VOICE_UNSUPPORTED_FORMAT was dead code — the DTO's @IsIn already rejects
  unknown containers — so it is gone rather than left unreachable.

ThrottlerModule is deliberately not bound as a global APP_GUARD: a global
ThrottlerGuard rate-limits every route against every named throttler, which
would have capped the whole API at the voice limit.

All seven remaining VOICE_* codes have errors.* keys in en, fa and nl.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-23 23:05:30 +03:30
8d34def001 improvement: the last flow improved a little. 2026-08-22 20:33:11 +03:30
7f02a84ebf improvement: a flow added to create treatment plan for searched patients with no treatment history. 2026-08-22 20:25:11 +03:30
b1405b22b1 improvement: patient search moved to the top of treatment feature. 2026-08-22 20:11:43 +03:30
50725b7b3f bugfix: no-detail treatment ui made some confusion. it is improved. at least to a degree. 2026-08-22 19:36:37 +03:30
f52ad6b84a bugfix: Treatment detail auto-fill bug fixed. 2026-08-22 18:51:57 +03:30
de46da216f bugfix: FDI tooth chart is now compatible with RTL direction. 2026-08-22 17:49:38 +03:30
d2f07c0ed3 improvement: treatments UI/UX updated again to minimize clicking and scrolling. 2026-08-19 23:59:37 +03:30
29c639f5a1 improvement: logo and name svgs updated and replaced. 2026-08-19 19:39:27 +03:30
96f698be98 improvement: UI/UX improved for v1 standalone treatments/cases feature. 2026-08-19 16:07:32 +03:30
8bfa8c88fe improvement: v1 standalone treatment/case creation made possible. 2026-08-19 15:05:58 +03:30
e5c39c6b7e bugfix: site renamed. Name component created. 2026-08-19 02:41:05 +03:30
80167c622c bugfix: appointment hours now use the client timezone on UTC servers.
Logical API errors throw stable codes so users see translated messages instead of a generic bad request.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-19 01:43:50 +03:30
d6958b2e48 bugfix: the flow for trial and accept invitation (org + staff)is now unified. all navigate to dshboard if succesfull. 2026-08-19 00:39:31 +03:30
6d90787c13 improvement: FDI tooth chart overhauled. 2026-08-19 00:06:21 +03:30
245a238d1a improvement: DockerFiles updated to avoid some deployment issues. 2026-07-20 21:11:08 +03:30
db515f9630 improvement: time period dropdown added to appropriate dashboard charts. 2026-07-19 00:37:59 +03:30
538121d653 improvement: pdf generation added to cases feature. 2026-07-18 22:00:44 +03:30
408b2c3329 improvement: task assignment notif added to notifications feature. 2026-07-18 17:23:47 +03:30
9941dca849 improvement: notification feature polished. feature tabs following the same notification socket emmited data to be updated. 2026-07-18 16:57:13 +03:30
9f6ec193d2 feature: version one notification feature implemented. 2026-07-18 01:09:54 +03:30
0740493384 improvement: fdi tooth chart selection modes polished. bugs related to teeth selecyion fixed. 2026-07-18 00:02:40 +03:30
4b2349228a improvement: treatment preview wizard optimized. comments component updated and unified accross the app. 2026-07-17 12:30:43 +03:30
58676f702e improvement: FDI chart tool selection modes updated. shift+ and crtl+ both are assigned with a selection mode. 2026-07-17 11:36:02 +03:30
1b63bfff00 improvement: some improvement done for appointment and treatment shared components. 2026-07-17 11:21:08 +03:30
d2ad1fd7b6 improvement: loading state added to buttons who interact with backend. 2026-07-17 10:58:04 +03:30
68fc9d5d6d improvement: treatment plan turned into a wizard. shift+click control added to FDI tooth chart for cunnected prosthesises. 2026-07-17 00:39:32 +03:30
cf07b4d8a8 improvement: delete action added for unsent treatment details. some edit controls added to details and shipments. 2026-07-16 22:45:37 +03:30
334b7841ae improvement: treatment exits contoll adde to appoinment remove action. 2026-07-16 22:35:02 +03:30
08df2f71ea improvement: QRcode and shared link added to cases inorder to make it possible for staff users to share a case info with other staffs or other clinics. 2026-07-14 21:07:05 +03:30
953e609fb8 fix(ui): restore native date panel selects with wider compact layout.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-14 15:09:11 +03:30
b7682a2d1c fix(treatment): show only past plans in history rail and refresh after lab send.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-14 15:09:10 +03:30
8de15ecdb5 improvement: billing and report tabs turned invisible. removed from permissions dialog too. this is temporary. 2026-07-14 03:17:57 +03:30
d383a4abc3 improvement: some new gadgets added to dashboard. some new functionality added to existed gadgets. 2026-07-14 03:06:56 +03:30
ec2b23f4b1 improvement: rtl direction, solar calendar and persian formatting added for persian users. 2026-07-14 01:27:11 +03:30
27eae25f61 improvement: lab/clinic commiunication flow completely overhauled. no more shit. 2026-07-13 22:53:23 +03:30
2ad572f4c8 improvement: notify counter badge added to treatment and tasks tabs for upadted and edited cases. 2026-07-13 17:44:44 +03:30
547457d637 improvement: tasks UI responsivness improved for mobile devices. 2026-07-13 16:49:24 +03:30
08a1f34c4f improvement: duedate added for shipped cases. cases and tasks ui and ux updated accordingly. 2026-07-13 16:30:36 +03:30
a391eee15f improvement: task assignment flow added. cases and tasks feature updated accordingly. 2026-07-13 15:47:32 +03:30
0d073f1ec0 improvement: sorts and filters updated for tasks feature. 2026-07-13 13:22:38 +03:30
4e6ed75844 improvement: tasks feature UX fully overhauled. 2026-07-13 02:09:49 +03:30
f28cd06615 improvement: treatment UX fully overhauled. 2026-07-13 01:03:26 +03:30
abf0371a5b improvement: appointment dialog UX improved. 2026-07-12 22:07:11 +03:30
53b43f2cdb improvement: updated toasts. no invisible toast anymore. 2026-07-12 21:30:28 +03:30
540a339723 improvement: today toogle added to ScheduleDatePicker component. 2026-07-12 21:16:38 +03:30