From e05c82635aadbec37e571a70c30cdddf468266cc Mon Sep 17 00:00:00 2001 From: StevenHosper Date: Mon, 4 Nov 2024 10:36:51 +0100 Subject: [PATCH 1/6] [Back-End]: underPrivilige Fixes #127 | Update pydantic model_validators --- api/bro_upload/upload_datamodels.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/api/bro_upload/upload_datamodels.py b/api/bro_upload/upload_datamodels.py index 32d9ccc..c98e773 100644 --- a/api/bro_upload/upload_datamodels.py +++ b/api/bro_upload/upload_datamodels.py @@ -1,7 +1,7 @@ import uuid from datetime import date, datetime -from pydantic import BaseModel, validator +from pydantic import BaseModel, field_validator ## Uploadtask models @@ -261,7 +261,7 @@ class FieldResearch(BaseModel): temperatureDifficultToMeasure: str fieldMeasurements: list[FieldMeasurement] | None = None - @validator("samplingDateTime", pre=True, always=True) + @field_validator("samplingDateTime", mode="before") def format_datetime(cls, value): """Ensure datetime is always serialized as BRO required format""" if isinstance(value, datetime): @@ -284,7 +284,7 @@ class AnalysisProcess(BaseModel): valuationMethod: str analyses: list[Analysis] - @validator("date", pre=True, always=True) + @field_validator("date", mode="before") def format_date(cls, value): """Ensure date is always serialized as a string, in BRO required format""" if isinstance(value, date): @@ -322,7 +322,7 @@ class TimeValuePair(BaseModel): censorReason: str | None = None censoringLimitvalue: str | float | None = None - @validator("time", pre=True, always=True) + @field_validator("time", mode="before") def format_datetime(cls, value): """Ensure datetime is always serialized as BRO required format""" if isinstance(value, datetime): @@ -347,28 +347,28 @@ class GLDAddition(BaseModel): resultTime: str timeValuePairs: list[TimeValuePair] - @validator("observationId", pre=True, always=True) + @field_validator("observationId", mode="before") def format_observationId(cls, value): """Ensure the observationId is always filled with an uuid""" if not value: return f"_{uuid.uuid4()}" return value - @validator("observationProcessId", pre=True, always=True) + @field_validator("observationProcessId", mode="before") def format_observationProcessId(cls, value): """Ensure the observationProcessId is always filled with an uuid""" if not value: return f"_{uuid.uuid4()}" return value - @validator("measurementTimeseriesId", pre=True, always=True) + @field_validator("measurementTimeseriesId", mode="before") def format_measurementTimeseriesId(cls, value): """Ensure the measurementTimeseriesId is always filled with an uuid""" if not value: return f"_{uuid.uuid4()}" return value - @validator("validationStatus", pre=True, always=True) + @field_validator("validationStatus", mode="before") def format_validationStatus(cls, value): """Ensure the measurementTimeseriesId is always filled with an uuid""" if cls.observationType == "reguliereMeting" and not value: From 7037a06141343e54bece54bfa6e43a174844b40f Mon Sep 17 00:00:00 2001 From: StevenHosper Date: Mon, 4 Nov 2024 11:21:41 +0100 Subject: [PATCH 2/6] remove underPrivilege from GAR --- api/bro_upload/templates/registration_GAR.html | 3 --- api/management/commands/dawaco_gar_bulk_upload.py | 1 - api/tests/test_gar_upload.py | 2 -- 3 files changed, 6 deletions(-) diff --git a/api/bro_upload/templates/registration_GAR.html b/api/bro_upload/templates/registration_GAR.html index 798c119..c40fce2 100644 --- a/api/bro_upload/templates/registration_GAR.html +++ b/api/bro_upload/templates/registration_GAR.html @@ -8,9 +8,6 @@ {{ metadata.deliveryAccountableParty }} {% endif %} {{ metadata.qualityRegime }} -{% if metadata.underPrivilege %} - {{ metadata.underPrivilege }} -{% endif %} {{ sourcedocs_data.objectIdAccountableParty }} diff --git a/api/management/commands/dawaco_gar_bulk_upload.py b/api/management/commands/dawaco_gar_bulk_upload.py index 5d0d074..5f65f70 100644 --- a/api/management/commands/dawaco_gar_bulk_upload.py +++ b/api/management/commands/dawaco_gar_bulk_upload.py @@ -219,7 +219,6 @@ def handle_gar_delivery( "qualityRegime": "IMBRO/A", # hardcoded "requestReference": "dawaco_export_gar_data_bulk_upload_brostar", # hardcoded "deliveryAccountableParty": organisation_instance.kvk_number, - "underPrivilege": "ja", } uploadtask_sourcedocument_data: datamodels.GAR = setup_gar_sourcedocs_data( diff --git a/api/tests/test_gar_upload.py b/api/tests/test_gar_upload.py index c117bc3..efd437a 100644 --- a/api/tests/test_gar_upload.py +++ b/api/tests/test_gar_upload.py @@ -11,8 +11,6 @@ IMBRO - ja - test From ddf536e1abffddc6d66feeda08a50ab7112fa575 Mon Sep 17 00:00:00 2001 From: StevenHosper Date: Mon, 4 Nov 2024 11:45:13 +0100 Subject: [PATCH 3/6] back to validator and add underprivilige --- api/bro_upload/upload_datamodels.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/api/bro_upload/upload_datamodels.py b/api/bro_upload/upload_datamodels.py index c98e773..a7d49ce 100644 --- a/api/bro_upload/upload_datamodels.py +++ b/api/bro_upload/upload_datamodels.py @@ -1,7 +1,7 @@ import uuid from datetime import date, datetime -from pydantic import BaseModel, field_validator +from pydantic import BaseModel, validator ## Uploadtask models @@ -16,6 +16,12 @@ class UploadTaskMetadata(BaseModel): correctionReason: str | None = None dateToBeCorrected: str | date | None = None + @validator("underPrivilege", pre=True, always=True) + def format_underPrivilege(cls, value): + if cls.qualityRegime == "IMBRO/A": + return "ja" + return value + class GARBulkUploadMetadata(BaseModel): requestReference: str @@ -261,7 +267,7 @@ class FieldResearch(BaseModel): temperatureDifficultToMeasure: str fieldMeasurements: list[FieldMeasurement] | None = None - @field_validator("samplingDateTime", mode="before") + @validator("samplingDateTime", pre=True, always=True) def format_datetime(cls, value): """Ensure datetime is always serialized as BRO required format""" if isinstance(value, datetime): @@ -284,7 +290,7 @@ class AnalysisProcess(BaseModel): valuationMethod: str analyses: list[Analysis] - @field_validator("date", mode="before") + @validator("date", pre=True, always=True) def format_date(cls, value): """Ensure date is always serialized as a string, in BRO required format""" if isinstance(value, date): @@ -322,7 +328,7 @@ class TimeValuePair(BaseModel): censorReason: str | None = None censoringLimitvalue: str | float | None = None - @field_validator("time", mode="before") + @validator("time", pre=True, always=True) def format_datetime(cls, value): """Ensure datetime is always serialized as BRO required format""" if isinstance(value, datetime): @@ -347,28 +353,28 @@ class GLDAddition(BaseModel): resultTime: str timeValuePairs: list[TimeValuePair] - @field_validator("observationId", mode="before") + @validator("observationId", pre=True, always=True) def format_observationId(cls, value): """Ensure the observationId is always filled with an uuid""" if not value: return f"_{uuid.uuid4()}" return value - @field_validator("observationProcessId", mode="before") + @validator("observationProcessId", pre=True, always=True) def format_observationProcessId(cls, value): """Ensure the observationProcessId is always filled with an uuid""" if not value: return f"_{uuid.uuid4()}" return value - @field_validator("measurementTimeseriesId", mode="before") + @validator("measurementTimeseriesId", pre=True, always=True) def format_measurementTimeseriesId(cls, value): """Ensure the measurementTimeseriesId is always filled with an uuid""" if not value: return f"_{uuid.uuid4()}" return value - @field_validator("validationStatus", mode="before") + @validator("validationStatus", pre=True, always=True) def format_validationStatus(cls, value): """Ensure the measurementTimeseriesId is always filled with an uuid""" if cls.observationType == "reguliereMeting" and not value: From 4e3f8c3a19c14c7281080e2ce8ee8376755cb8c7 Mon Sep 17 00:00:00 2001 From: StevenHosper Date: Mon, 4 Nov 2024 13:29:32 +0100 Subject: [PATCH 4/6] [Back-End]: underPrivilige Fixes #127 - Adjust CHANGES.md --- CHANGES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index cc900fd..c370a2c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,7 +3,8 @@ ## 0.55 (unreleased) -- Nothing changed yet. +- Auto fill underPrivilige +- Correct tubeTopDiameter optionality ## 0.54 (2024-11-04) From 5e614ef2c456bd686e4f09b94217a382394ebc3d Mon Sep 17 00:00:00 2001 From: StevenHosper Date: Mon, 4 Nov 2024 13:39:57 +0100 Subject: [PATCH 5/6] use root_validator to also use other fields --- api/bro_upload/upload_datamodels.py | 34 ++++++++++++++++++----------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/api/bro_upload/upload_datamodels.py b/api/bro_upload/upload_datamodels.py index a7d49ce..6524870 100644 --- a/api/bro_upload/upload_datamodels.py +++ b/api/bro_upload/upload_datamodels.py @@ -1,7 +1,7 @@ import uuid from datetime import date, datetime -from pydantic import BaseModel, validator +from pydantic import BaseModel, root_validator, validator ## Uploadtask models @@ -16,11 +16,15 @@ class UploadTaskMetadata(BaseModel): correctionReason: str | None = None dateToBeCorrected: str | date | None = None - @validator("underPrivilege", pre=True, always=True) - def format_underPrivilege(cls, value): - if cls.qualityRegime == "IMBRO/A": - return "ja" - return value + @root_validator(pre=True) + def format_underPrivilege(cls, values): + # Check and set `underPrivilege` + if values.get("qualityRegime") == "IMBRO/A" and not values.get( + "underPrivilege" + ): + values["underPrivilege"] = "ja" + + return values class GARBulkUploadMetadata(BaseModel): @@ -374,14 +378,18 @@ def format_measurementTimeseriesId(cls, value): return f"_{uuid.uuid4()}" return value - @validator("validationStatus", pre=True, always=True) - def format_validationStatus(cls, value): + @root_validator(pre=True) + def format_validationStatus(cls, values): """Ensure the measurementTimeseriesId is always filled with an uuid""" - if cls.observationType == "reguliereMeting" and not value: - return "onbekend" - elif cls.observationType == "controlemeting": - return None - return value + # Check and set `validationStatus` + if values.get("observationType") == "reguliereMeting" and not values.get( + "validationStatus" + ): + values["validationStatus"] = "onbekend" + elif values.get("observationType") == "controlemeting": + values["validationStatus"] = None + + return values # FRD From b918f87d0efafd8ec43e5bf323e10310394f61b2 Mon Sep 17 00:00:00 2001 From: StevenHosper Date: Mon, 4 Nov 2024 13:56:49 +0100 Subject: [PATCH 6/6] remove not required blank line --- api/tests/test_gar_upload.py | 1 - 1 file changed, 1 deletion(-) diff --git a/api/tests/test_gar_upload.py b/api/tests/test_gar_upload.py index efd437a..ce63120 100644 --- a/api/tests/test_gar_upload.py +++ b/api/tests/test_gar_upload.py @@ -10,7 +10,6 @@ test IMBRO - test