Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wound treatment and surgery form edit #58

Merged
merged 24 commits into from
Feb 21, 2025
Merged

Conversation

david-roper
Copy link
Collaborator

@david-roper david-roper commented Feb 12, 2025

Added the suggestions from issues #44 and #45

intracerebral injection questions moved from injection form to here as suggested in #43

Form can be viewed here

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Expanded treatment options by adding "Re-stitching" and "Intracerebral injection".
    • Introduced new fields for capturing anesthesia details (usage, type, volume), hydration information, and treatment/surgery duration.
    • Enhanced conditional data collection and validation to support a broader range of surgical and treatment scenarios.
  • Chores

    • Added "Intraperitoneal" to the custom spellings in the spell checker settings.

@david-roper david-roper self-assigned this Feb 12, 2025
Copy link
Contributor

coderabbitai bot commented Feb 12, 2025

Walkthrough

The pull request updates the mouse surgery form by expanding the treatment types to include "Re-stitching" and "Intracerebral injection." It modifies the logic for dependent fields to accommodate these new treatment scenarios and introduces additional fields related to anesthesia management, hydration, and treatment durations. The validation schema has been revised to ensure proper input validation for the newly added fields and treatment types.

Changes

File Change Summary
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts - Expanded TreatmentType to include "Re-stitching" and "Intracerebral injection".
- Updated logic for analgesiaUsed, analgesiaChemicalName, and analgesiaVolume fields.
- Added new fields: anesthesiaUsed, anesthesiaVolume, anesthesiaChemicalName, anesthesiaDuration, anesthesiaRecoveryTime, hydrationProvided, hydrationVolume, treatmentStartDate, and surgeryDuration.
- Updated validation schema for the new treatment types and fields.
.vscode/settings.json - Added "Intraperitoneal" to the cSpell.words array.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant F as SurgeryForm
    participant V as Validator

    U->>F: Select treatment type
    alt Treatment requires extra details
        F->>F: Check treatment type conditions
        F->>U: Render additional fields (anesthesia, hydration, durations)
    else Standard treatment
        F->>U: Render default fields
    end
    U->>F: Fill in form data
    F->>V: Validate inputs based on updated schema
    V-->>F: Return validation result
    F->>U: Confirm form submission
Loading

Possibly related PRs

  • Injection form edit #60: The changes in the main PR are related to the modifications of the createDependentField function and the handling of injection types, specifically regarding the addition of "Intracerebral injection" in the main PR and its removal in the retrieved PR.

Suggested reviewers

  • tulste

Poem

Hopping through the code so green,
New fields and types now can be seen.
Anesthesia, hydration join the fun,
With each re-stitch, the updates run.
I’m a rabbit skipping with a cheerful spin! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (4)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (4)

24-24: Update tags to include all treatment types.

The tags array should be updated to include the new treatment types "Re-stitching" and "Intracerebral injection" for consistency and better categorization.

-  tags: ['Surgery', 'Vet Care', 'Wound Treatment', 'Ovariectomy'],
+  tags: ['Surgery', 'Vet Care', 'Wound Treatment', 'Ovariectomy', 'Re-stitching', 'Intracerebral injection'],

284-288: Add integer validation to number input.

The validation schema requires an integer for treatment duration, but the form field allows any number. Consider adding a step attribute to ensure integer input.

     kind: "number",
     variant: "input",
+    step: 1,
     label: "Treatment duration (days)"

290-294: Add integer validation to timing fields.

Similar to treatment duration, surgery duration and days until recovery should enforce integer input to match their validation schema.

     kind: "number",
     variant: "input",
+    step: 1,
     label: "Surgery duration (minutes)"
     kind: "number",
     variant: "input",
+    step: 1,
     label: "Expected number of days until recovery"

Also applies to: 296-300


426-426: Add maximum volume validation.

Consider adding maximum volume validation for analgesia, anesthesia, and hydration to prevent unrealistic values.

-      analgesiaVolume: z.number().min(0).optional(),
+      analgesiaVolume: z.number().min(0).max(10).optional(), // Adjust max value based on requirements
-      anesthesiaVolume: z.number().min(0).optional(),
+      anesthesiaVolume: z.number().min(0).max(10).optional(), // Adjust max value based on requirements
-      hydrationVolume:  z.number().min(0).optional(),
+      hydrationVolume:  z.number().min(0).max(50).optional(), // Adjust max value based on requirements

Also applies to: 429-429, 431-431

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5773abc and 7e63148.

📒 Files selected for processing (1)
  • lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (9 hunks)
🔇 Additional comments (1)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (1)

445-445: Verify surgery duration precision requirements.

Unlike treatment duration and recovery days which require integers, surgery duration allows decimal values. Please confirm if this is intentional, as it might affect data consistency.

Copy link

@tulste tulste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix typos: Analgesia not Analglesia
for Anesthesia volume (ml), this doesnt make sense for all type of anesthesia. After Anesthesia true or false, you should next ask both Anesthesia type (chemical name) and route of administration (drop down of inhalation, intraperitoneal, etc.) and if the route is anything other than inhalation then ask for Anesthesia volume (ml) else ask for time under anesthesia. Next, I would remove Treatment duration (days) in the restitching part of the form, it is not applicable here. Instead, if treatment is needed after restitching then the user should next fill out the wound treatment part of the form. Finally, as per my previous comment, remove "Expected number of days until recovery" from the intracerebral injection section, the user should record how long it took the mouse to recover from the anaesthesia -- this is part of the normal postop tracking we need to provide to the animal facility.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (2)

77-112: Consider extracting common field patterns into reusable functions.

The anesthesia fields follow the same pattern as analgesia fields. Consider creating a helper function to generate these related field sets to reduce code duplication and improve maintainability.

Example helper function:

function createMedicationFields(prefix: string, dependentTypes: TreatmentType[]) {
  return {
    [`${prefix}Used`]: createDependentField({
      kind: "boolean",
      variant: "radio",
      label: `${prefix.charAt(0).toUpperCase() + prefix.slice(1)} used`
    }, (type) => dependentTypes.includes(type)),
    [`${prefix}Volume`]: {
      kind: "dynamic",
      deps: [`${prefix}Used`],
      render: (data) => data[`${prefix}Used`] ? {
        kind: "number",
        variant: "input",
        label: `${prefix.charAt(0).toUpperCase() + prefix.slice(1)} volume (ml)`
      } : null
    },
    [`${prefix}Type`]: {
      kind: "dynamic",
      deps: [`${prefix}Used`],
      render: (data) => data[`${prefix}Used`] ? {
        kind: "string",
        variant: "input",
        label: `${prefix.charAt(0).toUpperCase() + prefix.slice(1)} type`
      } : null
    }
  }
}

284-300: Consider adding maximum bounds for duration fields.

While the validation schema ensures minimum values of 0, consider adding maximum bounds to prevent unrealistic values:

  • Treatment duration: Typically shouldn't exceed 30-60 days
  • Surgery duration: Typically shouldn't exceed 8-12 hours
  • Recovery days: Typically shouldn't exceed 30-60 days

Update the validation schema with reasonable maximum bounds:

-      treatmentDuration: z.number().min(0).int().optional(),
-      surgeryDuration: z.number().min(0).optional(),
-      daysUntilRecovery: z.number().min(0).int().optional(),
+      treatmentDuration: z.number().min(0).max(60).int().optional(),
+      surgeryDuration: z.number().min(0).max(720).optional(), // 12 hours in minutes
+      daysUntilRecovery: z.number().min(0).max(60).int().optional(),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e63148 and f6b03c7.

📒 Files selected for processing (1)
  • lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (7 hunks)
🔇 Additional comments (4)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (4)

6-6: LGTM! Treatment types expanded appropriately.

The new treatment types "Re-stitching" and "Intracerebral injection" are consistently added to both the type definition and the form options.

Also applies to: 36-38


41-75: LGTM! Analgesia fields updated correctly.

The analgesia fields are properly configured with:

  • Correct dependency logic for new treatment types
  • Clear labeling
  • Appropriate input types and units

136-156: LGTM! Verify hydration requirements for Re-stitching.

The hydration fields are properly implemented. However, verify if hydration should also be tracked for "Re-stitching" procedures, as it's currently only enabled for "Surgery" and "Intracerebral injection".

Please confirm with the veterinary team if hydration monitoring is necessary for re-stitching procedures.


423-447: LGTM! Validation schema updated comprehensively.

The validation schema properly includes all new fields with appropriate types, constraints, and optionality.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (2)

41-75: Consider extracting treatment type conditions for better maintainability.

The treatment type conditions are repeated across multiple fields. Consider extracting these conditions into a helper function.

+const requiresAnalgesia = (type: TreatmentType) => 
+  type === "Surgery" || type === "Re-stitching" || type === "Intracerebral injection";

-    analgesiaUsed: createDependentField({
-      kind: "boolean",
-      variant: "radio",
-      label: "Analgesia used"
-    }, (type) => type === "Surgery" || type === "Re-stitching" || type === "Intracerebral injection"),
+    analgesiaUsed: createDependentField({
+      kind: "boolean",
+      variant: "radio",
+      label: "Analgesia used"
+    }, requiresAnalgesia),

77-112: Consider creating a reusable field factory for medication inputs.

The anesthesia fields follow the same pattern as analgesia fields. Consider creating a factory function to reduce code duplication.

+const createMedicationFields = (name: string, dependencyFn: (type: TreatmentType) => boolean) => ({
+  [`${name}Used`]: createDependentField({
+    kind: "boolean",
+    variant: "radio",
+    label: `${name} used`
+  }, dependencyFn),
+  [`${name}Volume`]: {
+    kind: "dynamic",
+    deps: [`${name}Used`],
+    render(data: Record<string, any>) {
+      if(data[`${name}Used`]){
+        return {
+          kind: "number",
+          variant: "input",
+          label: `${name} volume (ml)`
+        }
+      }
+      return null
+    }
+  },
+  [`${name}Type`]: {
+    kind: "dynamic",
+    deps: [`${name}Used`],
+    render(data: Record<string, any>) {
+      if(data[`${name}Used`]){
+        return {
+          kind: "string",
+          variant: "input",
+          label: `${name} type`
+        }
+      }
+      return null
+    }
+  }
+});

+const medicationFields = {
+  ...createMedicationFields('analgesia', requiresAnalgesia),
+  ...createMedicationFields('anesthesia', requiresAnalgesia)
+};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f6b03c7 and 73d730b.

📒 Files selected for processing (1)
  • lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (7 hunks)
🔇 Additional comments (4)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (4)

6-6: LGTM! Treatment types expanded as requested.

The addition of "Re-stitching" and "Intracerebral injection" addresses the previous feedback about including injections in the form.

Also applies to: 34-39


136-156: LGTM! Hydration tracking appropriately scoped.

The hydration fields are correctly implemented and appropriately shown only for procedures that typically require hydration monitoring.


284-294: Consider consistent duration validation rules.

The validation rules differ between treatment and surgery durations:

  • Treatment duration requires integers (z.number().min(0).int())
  • Surgery duration allows decimals (z.number().min(0))

Consider if this difference is intentional or if both should follow the same validation rules.

Also applies to: 434-435


412-438: LGTM! Comprehensive validation schema.

The validation schema has been properly updated to include all new fields with appropriate validation rules.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (2)

122-122: Fix typo in label: "Anethesia" should be "Anesthesia".

-            label: "Time until recovery from Anethesia (minutes)"
+            label: "Time until recovery from Anesthesia (minutes)"

456-456: Update validation for surgery duration.

Surgery duration should be an integer value since partial minutes are typically not recorded.

-      surgeryDuration: z.number().min(0).optional(),
+      surgeryDuration: z.number().min(0).int().optional(),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73d730b and 713bc51.

📒 Files selected for processing (1)
  • lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (7 hunks)
🔇 Additional comments (3)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (3)

129-134: LGTM! Good extension of stereotax fields.

The stereotax fields are now correctly available for all relevant treatment types.


173-182: Surgery types have been previously reviewed and confirmed.


432-459: LGTM! Validation schema is comprehensive.

All fields are properly validated with appropriate constraints.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (1)

385-385: ⚠️ Potential issue

Fix typo in anesthesia recovery time reference.

This is a duplicate of a previous comment. The typo in "anethesiaRecoveryTime" will cause runtime issues.

-      ref: "anethesiaRecoveryTime"
+      ref: "anesthesiaRecoveryTime"
🧹 Nitpick comments (1)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (1)

480-481: Ensure consistent integer validation for duration fields.

treatmentDuration is validated as an integer but surgeryDuration isn't. Both should be integers for consistency.

       treatmentDuration: z.number().min(0).int().optional(),
-      surgeryDuration: z.number().min(0).optional(),
+      surgeryDuration: z.number().min(0).int().optional(),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 713bc51 and cb1df93.

📒 Files selected for processing (2)
  • .vscode/settings.json (1 hunks)
  • lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (7 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .vscode/settings.json
🔇 Additional comments (2)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (2)

6-6: LGTM! Treatment types expanded as requested.

The addition of "Re-stitching" and "Intracerebral injection" aligns with the feedback from issues #44 and #45.

Also applies to: 36-38


41-45: LGTM! Analgesia fields updated for new treatment types.

The analgesia fields are now correctly configured for all relevant treatment types including "Re-stitching" and "Intracerebral injection".

@david-roper david-roper requested a review from tulste February 14, 2025 21:05
david-roper and others added 2 commits February 14, 2025 16:05
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (1)

457-482: 🛠️ Refactor suggestion

Strengthen validation for anesthesia fields.

The anesthesia fields should be required when anesthesiaUsed is true.

Apply this diff to strengthen the validation:

-      anesthesiaChemicalName: z.string().optional(),
-      anesthesiaVolume: z.number().min(0).optional(),
+      anesthesiaChemicalName: z.string().optional().refine(
+        (val) => !data.anesthesiaUsed || (data.anesthesiaUsed && val),
+        "Anesthesia chemical name is required when anesthesia is used"
+      ),
+      anesthesiaVolume: z.number().min(0).optional().refine(
+        (val) => !data.anesthesiaUsed || (data.anesthesiaUsed && val && data.anesthesiaAdministrationType !== "Inhalation"),
+        "Anesthesia volume is required when anesthesia is used and not administered via inhalation"
+      ),
♻️ Duplicate comments (1)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (1)

171-191: 🛠️ Refactor suggestion

Strengthen validation for hydration fields.

The hydration volume should be required when hydrationProvided is true.

Apply this diff to strengthen the validation:

-      hydrationVolume: z.number().min(0).optional(),
+      hydrationVolume: z.number().min(0).optional().refine(
+        (val) => !data.hydrationProvided || (data.hydrationProvided && val),
+        "Hydration volume is required when hydration is provided"
+      ),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b42851 and 95c4ea7.

📒 Files selected for processing (1)
  • lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (7 hunks)
🔇 Additional comments (2)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (2)

6-6: LGTM! Treatment types have been expanded as requested.

The addition of "Re-stitching" and "Intracerebral injection" addresses the previous feedback about surgery types being too restricted.

Also applies to: 36-38


319-330: LGTM! Duration tracking fields have been added.

The addition of treatmentDuration and surgeryDuration fields will help track the time spent on procedures.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (2)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (2)

171-191: 🛠️ Refactor suggestion

Strengthen validation for hydration fields.

When hydrationProvided is true, hydrationVolume should be required.


41-45: 🛠️ Refactor suggestion

Strengthen validation for analgesia fields.

When analgesiaUsed is true, analgesiaChemicalName and analgesiaVolume should be required.

Apply this diff to strengthen the validation:

-      analgesiaUsed: z.boolean().optional(),
-      analgesiaChemicalName: z.string().optional(),
-      analgesiaVolume: z.number().min(0).optional(),
+      analgesiaUsed: z.boolean().optional(),
+      analgesiaChemicalName: z.string().optional().refine(
+        (val) => !data.analgesiaUsed || (data.analgesiaUsed && val),
+        "Analgesia chemical name is required when analgesia is used"
+      ),
+      analgesiaVolume: z.number().min(0).optional().refine(
+        (val) => !data.analgesiaUsed || (data.analgesiaUsed && val),
+        "Analgesia volume is required when analgesia is used"
+      ),
🧹 Nitpick comments (1)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (1)

457-482: Verify validation ranges for surgery duration.

The validation for surgeryDuration allows any non-negative number. Consider adding a reasonable maximum limit to catch potential data entry errors.

Apply this diff to add a maximum limit:

-      surgeryDuration: z.number().min(0).optional(),
+      surgeryDuration: z.number().min(0).max(480).optional(), // Max 8 hours
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95c4ea7 and 935f20b.

📒 Files selected for processing (1)
  • lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (7 hunks)
🔇 Additional comments (2)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (2)

6-6: LGTM! Treatment types have been expanded as requested.

Based on the past review comments and discussion, the addition of "Re-stitching" and "Intracerebral injection" addresses the concern about restricted surgery types.

Also applies to: 36-38


319-330: LGTM! Duration tracking fields have been added.

The addition of treatmentDuration and surgeryDuration fields will help track the time spent on procedures.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (3)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (3)

41-75: 🛠️ Refactor suggestion

Strengthen validation for analgesia fields.

The validation schema should enforce that when analgesiaUsed is true, both analgesiaChemicalName and analgesiaVolume must be provided.

Apply this diff to strengthen the validation:

-      analgesiaChemicalName: z.string().optional(),
-      analgesiaVolume: z.number().min(0).optional(),
+      analgesiaChemicalName: z.string().optional().refine(
+        (val) => !data.analgesiaUsed || (data.analgesiaUsed && val),
+        "Analgesia chemical name is required when analgesia is used"
+      ),
+      analgesiaVolume: z.number().min(0).optional().refine(
+        (val) => !data.analgesiaUsed || (data.analgesiaUsed && val),
+        "Analgesia volume is required when analgesia is used"
+      ),

77-147: 🛠️ Refactor suggestion

Strengthen validation for anesthesia fields.

The validation schema should enforce that when anesthesiaUsed is true:

  1. anesthesiaChemicalName and anesthesiaRecoveryTime must be provided
  2. anesthesiaVolume must be provided for non-inhalation types

Apply this diff to strengthen the validation:

-      anesthesiaChemicalName: z.string().optional(),
-      anesthesiaVolume: z.number().min(0).optional(),
-      anesthesiaRecoveryTime: z.number().min(0).int().optional(),
+      anesthesiaChemicalName: z.string().optional().refine(
+        (val) => !data.anesthesiaUsed || (data.anesthesiaUsed && val),
+        "Anesthesia chemical name is required when anesthesia is used"
+      ),
+      anesthesiaVolume: z.number().min(0).optional().refine(
+        (val) => !data.anesthesiaUsed || (data.anesthesiaUsed && data.anesthesiaAdministrationType !== "Inhalation" && val),
+        "Anesthesia volume is required when anesthesia is used (except for inhalation)"
+      ),
+      anesthesiaRecoveryTime: z.number().min(0).int().optional().refine(
+        (val) => !data.anesthesiaUsed || (data.anesthesiaUsed && val),
+        "Recovery time is required when anesthesia is used"
+      ),

171-191: 🛠️ Refactor suggestion

Strengthen validation for hydration fields.

The validation schema should enforce that when hydrationProvided is true, hydrationVolume must be provided.

Apply this diff to strengthen the validation:

-      hydrationProvided: z.boolean().optional(),
-      hydrationVolume:  z.number().min(0).optional(),
+      hydrationProvided: z.boolean().optional(),
+      hydrationVolume: z.number().min(0).optional().refine(
+        (val) => !data.hydrationProvided || (data.hydrationProvided && val),
+        "Hydration volume is required when hydration is provided"
+      ),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 935f20b and a809eee.

📒 Files selected for processing (1)
  • lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (7 hunks)
🔇 Additional comments (1)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (1)

6-6: LGTM! Treatment types have been expanded as requested.

The addition of "Re-stitching" and "Intracerebral injection" aligns with the feedback from issue #44 and #45, addressing the previous concern about restricted surgery types.

Also applies to: 34-39

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (1)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (1)

503-513: 🛠️ Refactor suggestion

Strengthen validation for analgesia, anesthesia, and hydration fields.

The validation schema should enforce that:

  1. When analgesiaUsed is true, analgesiaChemicalName and analgesiaVolume should be required
  2. When anesthesiaUsed is true, anesthesiaChemicalName, anesthesiaAdministrationType, and anesthesiaRecoveryTime should be required
  3. When hydrationProvided is true, hydrationVolume should be required
🧹 Nitpick comments (1)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (1)

344-344: Fix typo in clinical condition label.

There's a typo in "Clincal" which should be "Clinical".

-      label: "Clincal condition"
+      label: "Clinical condition"

Also applies to: 344-344

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61b9f11 and 183f653.

📒 Files selected for processing (1)
  • lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (8 hunks)
🔇 Additional comments (1)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (1)

6-6: LGTM! Treatment types are properly defined and validated.

The treatment types are consistently defined in both the type definition and validation schema.

Also applies to: 502-502

@david-roper david-roper mentioned this pull request Feb 19, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (2)

12-12: Improve type safety by using a more specific type.

The data parameter type could be more specific to better leverage TypeScript's type checking.

-    render: (data: { treatmentType?: TreatmentType }) => {
+    render: (data: Record<'treatmentType', TreatmentType | undefined>) => {

344-344: Fix typo in label.

There's a typo in "Clincal" which should be "Clinical".

-      label: "Clincal condition"
+      label: "Clinical condition"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 183f653 and 05f3f0d.

📒 Files selected for processing (1)
  • lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (9 hunks)
🔇 Additional comments (3)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (3)

42-58: Strengthen validation for intracerebral injection fields.

When treatment type is "Intracerebral injection", both fields should be required.


502-515: Strengthen validation for dependent fields.

The validation schema should enforce that:

  1. When anesthesiaUsed is true, anesthesiaType, anesthesiaVolume (for non-inhalation types), and anesthesiaRecoveryTime should be required
  2. When hydrationProvided is true, hydrationVolume should be required
  3. When treatment type is "Intracerebral injection", both intracerebralInjectionType and intracerebralInjectionBatchType should be required

528-529: Strengthen validation for treatment timing fields.

The validation schema should enforce that:

  1. treatmentStartDate must be required for wound treatment
  2. surgeryDuration must be required for surgery and intracerebral injection

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (1)

8-19: Improve type safety in createDependentField function.

The function parameter type could be more specific to improve type safety.

-function createDependentField<const T>(field: T, fn: (treatmentType?: TreatmentType) => boolean) {
+function createDependentField<const T>(field: T, fn: (treatmentType: TreatmentType | undefined) => boolean) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3eb8913 and fedb694.

📒 Files selected for processing (1)
  • lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (8 hunks)
🔇 Additional comments (5)
lib/forms/CoBrALab-Mouse-Surgery-Form/index.ts (5)

42-58: Strengthen validation for intracerebral injection fields.

When treatment type is "Intracerebral injection", both fields should be required.


175-175: Fix typo in anesthesia recovery time label.

There's a typo in "Anesthesia" in the label.


204-224: Strengthen validation for hydration fields.

When hydrationProvided is true, hydrationVolume should be required.


353-362: Strengthen validation for treatment timing fields.

The validation schema should enforce that:

  1. treatmentStartDate must be required for wound treatment
  2. surgeryDuration must be required for surgery and intracerebral injection

530-561: Strengthen validation schema for dependent fields.

The validation schema should enforce that:

  1. When analgesiaUsed is true, analgesiaChemicalName and analgesiaVolume should be required
  2. When anesthesiaUsed is true, anesthesiaChemicalName, anesthesiaVolume (for non-inhalation types), and anesthesiaRecoveryTime should be required
  3. When hydrationProvided is true, hydrationVolume should be required
  4. When treatment type is "Intracerebral injection", both intracerebralInjectionType and intracerebralInjectionBatchType should be required
  5. treatmentStartDate must be required for wound treatment
  6. surgeryDuration must be required for surgery and intracerebral injection

@david-roper david-roper merged commit c3b96e3 into main Feb 21, 2025
1 check passed
@david-roper david-roper deleted the wound-treatment-edit branch March 3, 2025 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants