From 84c30f062d3c55e5506b0facbe4c5f9db75ddca6 Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 10:49:28 +0530 Subject: [PATCH 1/8] Add basic validation utility for extracted data Adds a function to validate required fields in extracted data. --- src/validation.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/validation.py diff --git a/src/validation.py b/src/validation.py new file mode 100644 index 0000000..0c41938 --- /dev/null +++ b/src/validation.py @@ -0,0 +1,13 @@ +def validate_extracted_data(data: dict) -> bool: + """ + Basic validation for extracted form data. + Ensures required fields are present and non-empty. + """ + + required_fields = ["patient_name", "age", "diagnosis"] + + for field in required_fields: + if field not in data or not data[field]: + return False + + return True From fc7251ca80850eb2211f505ff58044da60dffe7c Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 10:58:24 +0530 Subject: [PATCH 2/8] Implement data validation in fill_form method Integrate validation into controller flow --- src/controller.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/controller.py b/src/controller.py index d31ec9c..7f78e60 100644 --- a/src/controller.py +++ b/src/controller.py @@ -1,3 +1,4 @@ +from src.validation import validate_extracted_data from src.file_manipulator import FileManipulator class Controller: @@ -5,7 +6,12 @@ def __init__(self): self.file_manipulator = FileManipulator() def fill_form(self, user_input: str, fields: list, pdf_form_path: str): - return self.file_manipulator.fill_form(user_input, fields, pdf_form_path) + data = self.file_manipulator.fill_form(user_input, fields, pdf_form_path) + + if not validate_extracted_data(data): + raise ValueError("Invalid extracted data") + + return data def create_template(self, pdf_path: str): - return self.file_manipulator.create_template(pdf_path) \ No newline at end of file + return self.file_manipulator.create_template(pdf_path) From 9404cbaa54c0d0528adc929bac6298886aa0e0db Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 11:02:06 +0530 Subject: [PATCH 3/8] Add tests for validate_extracted_data function Add unit tests for validation utility --- tests/src/tests/test_validation.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/src/tests/test_validation.py diff --git a/tests/src/tests/test_validation.py b/tests/src/tests/test_validation.py new file mode 100644 index 0000000..1f30f7a --- /dev/null +++ b/tests/src/tests/test_validation.py @@ -0,0 +1,28 @@ +import pytest +from src.validation import validate_extracted_data + + +def test_valid_data(): + data = { + "patient_name": "John Doe", + "age": 30, + "diagnosis": "Flu" + } + assert validate_extracted_data(data) == True + + +def test_missing_field(): + data = { + "patient_name": "John Doe", + "age": 30 + } + assert validate_extracted_data(data) == False + + +def test_empty_field(): + data = { + "patient_name": "", + "age": 30, + "diagnosis": "Flu" + } + assert validate_extracted_data(data) == False From ba1638467352b75401d8ea0f53a89accb5f2403f Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 11:06:13 +0530 Subject: [PATCH 4/8] Implement test for fill_form validation failure Add a test for form validation failure in Controller. dd validation + tests --- tests/src/tests/test_controller.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/src/tests/test_controller.py diff --git a/tests/src/tests/test_controller.py b/tests/src/tests/test_controller.py new file mode 100644 index 0000000..a182333 --- /dev/null +++ b/tests/src/tests/test_controller.py @@ -0,0 +1,16 @@ +from src.controller import Controller + + +def test_fill_form_validation_fail(monkeypatch): + controller = Controller() + + def mock_fill_form(user_input, fields, pdf_form_path): + return {"patient_name": "", "age": 30, "diagnosis": "Flu"} + + monkeypatch.setattr(controller.file_manipulator, "fill_form", mock_fill_form) + + try: + controller.fill_form("input", [], "file.pdf") + assert False # Should not reach here + except ValueError: + assert True From 6b56916eeacdc25a126206f6d4898c748d6aa018 Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 16:32:25 +0530 Subject: [PATCH 5/8] Delete tests/src/tests/test_validation.py --- tests/src/tests/test_validation.py | 28 ---------------------------- 1 file changed, 28 deletions(-) delete mode 100644 tests/src/tests/test_validation.py diff --git a/tests/src/tests/test_validation.py b/tests/src/tests/test_validation.py deleted file mode 100644 index 1f30f7a..0000000 --- a/tests/src/tests/test_validation.py +++ /dev/null @@ -1,28 +0,0 @@ -import pytest -from src.validation import validate_extracted_data - - -def test_valid_data(): - data = { - "patient_name": "John Doe", - "age": 30, - "diagnosis": "Flu" - } - assert validate_extracted_data(data) == True - - -def test_missing_field(): - data = { - "patient_name": "John Doe", - "age": 30 - } - assert validate_extracted_data(data) == False - - -def test_empty_field(): - data = { - "patient_name": "", - "age": 30, - "diagnosis": "Flu" - } - assert validate_extracted_data(data) == False From 237a3f594e5f5c3f02c3dee0415a883a80554bbe Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 16:33:07 +0530 Subject: [PATCH 6/8] Delete tests/src/tests/test_controller.py --- tests/src/tests/test_controller.py | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 tests/src/tests/test_controller.py diff --git a/tests/src/tests/test_controller.py b/tests/src/tests/test_controller.py deleted file mode 100644 index a182333..0000000 --- a/tests/src/tests/test_controller.py +++ /dev/null @@ -1,16 +0,0 @@ -from src.controller import Controller - - -def test_fill_form_validation_fail(monkeypatch): - controller = Controller() - - def mock_fill_form(user_input, fields, pdf_form_path): - return {"patient_name": "", "age": 30, "diagnosis": "Flu"} - - monkeypatch.setattr(controller.file_manipulator, "fill_form", mock_fill_form) - - try: - controller.fill_form("input", [], "file.pdf") - assert False # Should not reach here - except ValueError: - assert True From 8cba3d58b440cc4f8b97b5630dff639ad5b70739 Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 16:52:15 +0530 Subject: [PATCH 7/8] Add unit tests for validation utility --- tests/test_validation.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/test_validation.py diff --git a/tests/test_validation.py b/tests/test_validation.py new file mode 100644 index 0000000..1f30f7a --- /dev/null +++ b/tests/test_validation.py @@ -0,0 +1,28 @@ +import pytest +from src.validation import validate_extracted_data + + +def test_valid_data(): + data = { + "patient_name": "John Doe", + "age": 30, + "diagnosis": "Flu" + } + assert validate_extracted_data(data) == True + + +def test_missing_field(): + data = { + "patient_name": "John Doe", + "age": 30 + } + assert validate_extracted_data(data) == False + + +def test_empty_field(): + data = { + "patient_name": "", + "age": 30, + "diagnosis": "Flu" + } + assert validate_extracted_data(data) == False From 95968b65895846e4c3b016658b3be64c8b9fded2 Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 16:55:06 +0530 Subject: [PATCH 8/8] Add validation + tests Add a test to validate form filling failure. --- tests/test_controller.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/test_controller.py diff --git a/tests/test_controller.py b/tests/test_controller.py new file mode 100644 index 0000000..a182333 --- /dev/null +++ b/tests/test_controller.py @@ -0,0 +1,16 @@ +from src.controller import Controller + + +def test_fill_form_validation_fail(monkeypatch): + controller = Controller() + + def mock_fill_form(user_input, fields, pdf_form_path): + return {"patient_name": "", "age": 30, "diagnosis": "Flu"} + + monkeypatch.setattr(controller.file_manipulator, "fill_form", mock_fill_form) + + try: + controller.fill_form("input", [], "file.pdf") + assert False # Should not reach here + except ValueError: + assert True