Skip to content

11399 phone number validation for sale for cashier #11587

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

Merged

Conversation

ChinthakaPrasad
Copy link
Collaborator

@ChinthakaPrasad ChinthakaPrasad commented Apr 4, 2025

add option to edit and delete AMP from pharmacy administration.
fixed - #11399, #11408 #11255

Summary by CodeRabbit

  • Bug Fixes

    • Clarified error messages to guide users when selections or required information (e.g., names and phone numbers) are missing.
    • Strengthened validations to ensure only authorized edits are permitted.
  • New Features

    • Introduced real-time validation for patient contact details during sales.
    • Updated transaction buttons to streamline navigation.
    • Conditionally enabled deletion actions based on system settings.

Copy link
Contributor

coderabbitai bot commented Apr 4, 2025

Walkthrough

This pull request modifies the error handling and validation logic in two Java controller classes and updates associated JSF pages. In the Java layer, the AmpController save method now provides clearer error messages and enforces privilege checks before allowing AMP modifications, while the PharmacySaleController settlePreBill method includes new validations for patient phone numbers. The web pages are updated to conditionally disable a delete button based on configuration settings and to modify sale button navigation and controller references. No public API or exported entity declarations were changed.

Changes

Files Change Summary
src/main/java/com/divudi/bean/pharmacy/AmpController.java
src/main/java/com/divudi/bean/pharmacy/PharmacySaleController.java
AmpController: Updated error messages and added privilege checks in the save method.
PharmacySaleController: Added validation for patient phone numbers in settlePreBill.
src/main/webapp/pharmacy/admin/amp.xhtml
src/main/webapp/pharmacy/pharmacy_bill_retail_sale_1.xhtml
amp.xhtml: Added a disabled attribute on the btnDelete button based on a configuration option.
pharmacy_bill_retail_sale_1.xhtml: Updated sale button action paths and action listeners.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant AC as AmpController
    participant Config as ConfigOptionService
    U->>AC: Trigger save action
    AC->>AC: Check if current AMP is null
    alt Current is null
        AC->>U: "No AMP is selected" error message
    else Current exists
        AC->>AC: Verify current.getId() is not null
        AC->>Config: Validate edit privileges
        alt Insufficient privilege
            AC->>U: "You have no privilage to edit AMPs." error message
        else
            AC->>AC: Check if AMP name is provided
            alt Name missing
                AC->>U: "Please add a name to AMP" error message
            else
                AC->>AC: Proceed with saving AMP
            end
        end
    end
Loading
sequenceDiagram
    participant U as User
    participant PSC as PharmacySaleController
    participant Config as ConfigOptionService
    U->>PSC: Trigger settle pre bill action
    PSC->>Config: Check if patient's phone is required
    alt Phone requirement enabled
        PSC->>PSC: Validate PatientPhoneNumber and PatientMobileNumber
        alt Both numbers are missing
            PSC->>U: Prompt: "Enter a phone number"
        else if patient ID is missing
            alt Phone number length < 10
                PSC->>U: "Valid phone number must be entered" error message
            else
                PSC->>PSC: Continue pre bill settlement
            end
        end
    else
        PSC->>PSC: Continue pre bill settlement
    end
Loading

Possibly related PRs

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.31.1)
src/main/java/com/divudi/bean/pharmacy/PharmacySaleController.java
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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 (1)
src/main/java/com/divudi/bean/pharmacy/PharmacySaleController.java (1)

2070-2083: Enhance phone number validation for stronger input checking.

The validation logic correctly checks for phone number presence when required by configuration, but it has a hardcoded minimum length of 10 digits that could be configurable instead.

Consider these improvements:

  1. Extract the minimum phone length (10) as a configurable parameter
  2. Add pattern validation for phone numbers beyond just length
  3. Apply consistent validation for both new and existing patients
-        if (configOptionApplicationController.getBooleanValueByKey("Patient Phone number is mandotary in sale for cashier", true)) {
-            if (getPatient().getPatientPhoneNumber() == null && getPatient().getPatientMobileNumber() == null) {
-                JsfUtil.addErrorMessage("Please enter phone number of the patient");
-                return;
-            } else if (getPatient().getId() == null) {
-                if (getPatient().getPatientPhoneNumber() != null && !(String.valueOf(getPatient().getPatientPhoneNumber()).length() >= 10)) {
-                    JsfUtil.addErrorMessage("Please enter valid phone number with more than 10 digits of the patient");
-                    return;
-                } else if (getPatient().getPatientMobileNumber() != null && !(String.valueOf(getPatient().getPatientMobileNumber()).length() >= 10)) {
-                    JsfUtil.addErrorMessage("Please enter valid mobile number with more than 10 digits of the patient");
-                    return;
-                }
-            }
-        }
+        if (configOptionApplicationController.getBooleanValueByKey("Patient Phone number is mandotary in sale for cashier", true)) {
+            // Extract minimum length to a constant or configuration
+            int minPhoneLength = configOptionApplicationController.getIntValueByKey("Minimum phone number length", 10);
+            
+            if (getPatient().getPatientPhoneNumber() == null && getPatient().getPatientMobileNumber() == null) {
+                JsfUtil.addErrorMessage("Please enter phone number of the patient");
+                return;
+            }
+            
+            // Validate phone number format regardless of patient being new or existing
+            if (getPatient().getPatientPhoneNumber() != null && 
+                !(String.valueOf(getPatient().getPatientPhoneNumber()).length() >= minPhoneLength)) {
+                JsfUtil.addErrorMessage("Please enter valid phone number with at least " + minPhoneLength + " digits");
+                return;
+            } else if (getPatient().getPatientMobileNumber() != null && 
+                       !(String.valueOf(getPatient().getPatientMobileNumber()).length() >= minPhoneLength)) {
+                JsfUtil.addErrorMessage("Please enter valid mobile number with at least " + minPhoneLength + " digits");
+                return;
+            }
+        }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aa1a5a7 and 6a9e0d7.

📒 Files selected for processing (4)
  • src/main/java/com/divudi/bean/pharmacy/AmpController.java (2 hunks)
  • src/main/java/com/divudi/bean/pharmacy/PharmacySaleController.java (1 hunks)
  • src/main/webapp/pharmacy/admin/amp.xhtml (1 hunks)
  • src/main/webapp/pharmacy/pharmacy_bill_retail_sale_1.xhtml (1 hunks)
🔇 Additional comments (5)
src/main/webapp/pharmacy/admin/amp.xhtml (1)

40-40: Improved security by conditionally enabling the delete AMP button

This change ensures that the delete button is only enabled when the application's configuration option for editing/deleting AMPs from Pharmacy Administration is set to true, which aligns with the privilege check in the controller.

src/main/java/com/divudi/bean/pharmacy/AmpController.java (3)

658-658: Improved error message clarity

Changed the error message from a typo "Nothuing selected" to a clearer "No AMP is selected", which improves user experience.


662-667: Added permission check for AMP editing

This change enforces proper privilege control for editing AMPs, checking if the configuration option "Enable edit and delete AMP from Pharmacy Administration" is enabled before allowing edits to existing AMPs. This is a good security practice that aligns with the disabled attribute added to the delete button in the UI.


670-670: Improved validation message clarity

Changed the error message from "No Name" to a more instructive "Please add a name to AMP", which provides clearer guidance to users.

src/main/webapp/pharmacy/pharmacy_bill_retail_sale_1.xhtml (1)

715-716: Controller reference and path updates for consistency.

The changes standardize the controller references and paths between the top navigation buttons and the bottom preview panel buttons. This ensures consistent behavior between the different sections of the page.

@GSMgeeth GSMgeeth merged commit 14fe53a into development Apr 4, 2025
3 checks passed
@GSMgeeth GSMgeeth deleted the 11399-phone-number-validation-for-sale-for-cashier branch April 4, 2025 06:31
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.

2 participants