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 01/11] 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 02/11] 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 03/11] 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 04/11] 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 20abde0d82467f5327c4efc137148026e60c772a Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 12:59:04 +0530 Subject: [PATCH 05/11] Add schema definition for extracted data validation --- src/schema.py | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/schema.py diff --git a/src/schema.py b/src/schema.py new file mode 100644 index 0000000..ba1866c --- /dev/null +++ b/src/schema.py @@ -0,0 +1,7 @@ +REQUIRED_FIELDS = { + "incident_type": str, + "location": str, + "incident_time": str, + "units_involved": list, + "summary": str +} From 271f68dbf0848897c09f4e3fe06e60b5058a5c6b Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 13:00:47 +0530 Subject: [PATCH 06/11] Update validation logic to use schema-based enforcement Refactor validation to use REQUIRED_FIELDS from schema. --- src/validation.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/validation.py b/src/validation.py index 0c41938..eeaa16c 100644 --- a/src/validation.py +++ b/src/validation.py @@ -1,13 +1,11 @@ -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"] +from src.schema import REQUIRED_FIELDS - for field in required_fields: - if field not in data or not data[field]: +def validate_extracted_data(data: dict) -> bool: + for field, field_type in REQUIRED_FIELDS.items(): + if field not in data: + return False + if not isinstance(data[field], field_type): + return False + if data[field] in ["", None]: return False - return True From c0c48ce317f6886455fb53aacae8ac21c2230c77 Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 13:20:47 +0530 Subject: [PATCH 07/11] Update tests for schema-based validation and add type-check test --- tests/src/tests/test_validation.py | 31 +++++++++++------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/tests/src/tests/test_validation.py b/tests/src/tests/test_validation.py index 1f30f7a..3ebb8e9 100644 --- a/tests/src/tests/test_validation.py +++ b/tests/src/tests/test_validation.py @@ -1,28 +1,19 @@ -import pytest -from src.validation import validate_extracted_data - - def test_valid_data(): data = { - "patient_name": "John Doe", - "age": 30, - "diagnosis": "Flu" + "incident_type": "Fire", + "location": "Downtown", + "incident_time": "2026-03-20 10:00", + "units_involved": ["Unit1", "Unit2"], + "summary": "Fire contained" } 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(): +def test_wrong_type(): data = { - "patient_name": "", - "age": 30, - "diagnosis": "Flu" + "incident_type": "Fire", + "location": "Downtown", + "incident_time": "2026-03-20 10:00", + "units_involved": "Unit1", # should be list + "summary": "Fire contained" } assert validate_extracted_data(data) == False From cb3c229031d9cbd4b8d7dab7a832755b1fcaace2 Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 18:15:55 +0530 Subject: [PATCH 08/11] Implement test for fill_form validation failure Add a test for form validation failure in Controller --- tests/test_controller.py | 22 ++++++++++++++++++++++ 1 file changed, 22 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..541deb6 --- /dev/null +++ b/tests/test_controller.py @@ -0,0 +1,22 @@ +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 { + "incident_type": "", # invalid (empty) + "location": "Downtown", + "incident_time": "2026-03-20T10:30:00", + "units_involved": ["Unit 42"], + "summary": "Minor incident reported" + } + + 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 380d45a112de9b7a2893253a4bedca5c4346a968 Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 18:17:24 +0530 Subject: [PATCH 09/11] Add validation tests for incident data --- tests/test_vallidation | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/test_vallidation diff --git a/tests/test_vallidation b/tests/test_vallidation new file mode 100644 index 0000000..3ebb8e9 --- /dev/null +++ b/tests/test_vallidation @@ -0,0 +1,19 @@ +def test_valid_data(): + data = { + "incident_type": "Fire", + "location": "Downtown", + "incident_time": "2026-03-20 10:00", + "units_involved": ["Unit1", "Unit2"], + "summary": "Fire contained" + } + assert validate_extracted_data(data) == True + +def test_wrong_type(): + data = { + "incident_type": "Fire", + "location": "Downtown", + "incident_time": "2026-03-20 10:00", + "units_involved": "Unit1", # should be list + "summary": "Fire contained" + } + assert validate_extracted_data(data) == False From 9602eb5359dfb81d4a8519d3c4d19661de91cbd4 Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 18:17:55 +0530 Subject: [PATCH 10/11] Rename test_vallidation to test_vallidation.py --- tests/{test_vallidation => test_vallidation.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{test_vallidation => test_vallidation.py} (100%) diff --git a/tests/test_vallidation b/tests/test_vallidation.py similarity index 100% rename from tests/test_vallidation rename to tests/test_vallidation.py From a4bd13d829763a35ff119390b23344ae780d0c7a Mon Sep 17 00:00:00 2001 From: Ayush Basu <98446798+ayushhbasu@users.noreply.github.com> Date: Fri, 20 Mar 2026 18:35:05 +0530 Subject: [PATCH 11/11] 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