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

[#2259] Show case result in list view #1160

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/open_inwoner/openzaak/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from zgw_consumers.api_models.base import Model, ZGWModel
from zgw_consumers.api_models.constants import RolOmschrijving, RolTypes

from open_inwoner.utils.glom import glom_multiple

logger = logging.getLogger(__name__)


Expand All @@ -33,7 +35,7 @@ class Zaak(ZGWModel):
uiterlijke_einddatum_afdoening: Optional[date] = None
# publicatiedatum: Optional[date]
einddatum: Optional[date] = None
resultaat: Optional[str] = None
resultaat: Optional[Union[str, "Resultaat"]] = None
# relevante_andere_zaken: list
# zaakgeometrie: dict

Expand Down Expand Up @@ -73,17 +75,30 @@ def process_data(self) -> dict:

status_translate = StatusTranslation.objects.get_lookup()

status_text = status_translate.from_glom_multiple(
self,
("status.statustype.statustekst", "status.statustype.omschrijving"),
default="",
)
if self.einddatum and self.resultaat:
result_text = glom_multiple(
self,
(
"resultaat.resultaattype.omschrijving",
"resultaat.resultaattype.omschrijving_generiek",
"resultaat.resultaattype.resultaattypeomschrijving",
),
default="",
)
status_text = result_text or status_text

return {
"identification": self.identification,
"uuid": str(self.uuid),
"start_date": self.startdatum,
"end_date": getattr(self, "einddatum", None),
"description": self.zaaktype.omschrijving,
"current_status": status_translate.from_glom_multiple(
self,
("status.statustype.statustekst", "status.statustype.omschrijving"),
default="",
),
"current_status": status_text,
"zaaktype_config": getattr(self, "zaaktype_config", None),
"statustype_config": getattr(self, "statustype_config", None),
"case_type": "Zaak",
Expand Down
34 changes: 28 additions & 6 deletions src/open_inwoner/openzaak/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from zgw_consumers.concurrent import parallel

from .api_models import Zaak
from .clients import build_client
from .clients import CatalogiClient, ZakenClient, build_client
from .models import ZaakTypeConfig, ZaakTypeStatusTypeConfig
from .utils import is_zaak_visible

logger = logging.getLogger(__name__)


def resolve_zaak_type(case: Zaak, client=None) -> None:
def resolve_zaak_type(case: Zaak, client: CatalogiClient | None = None) -> None:
"""
Resolve `case.zaaktype` (`str`) to a `ZaakType(ZGWModel)` object

Expand All @@ -27,7 +27,7 @@ def resolve_zaak_type(case: Zaak, client=None) -> None:
case.zaaktype = case_type


def resolve_status(case: Zaak, client=None) -> None:
def resolve_status(case: Zaak, client: ZakenClient | None = None) -> None:
"""
Resolve `case.status` (`str`) to a `Status(ZGWModel)` object
"""
Expand All @@ -36,16 +36,36 @@ def resolve_status(case: Zaak, client=None) -> None:
case.status = client.fetch_single_status(case.status)


def resolve_status_type(case: Zaak, client=None) -> None:
def resolve_status_type(case: Zaak, client: CatalogiClient | None = None) -> None:
"""
Resolve `case.statustype` (`str`) to a `StatusType(ZGWModel)` object
Resolve `case.status.statustype` (`str`) to a `StatusType(ZGWModel)` object
"""
statustype_url = case.status.statustype
client = client or build_client("zaak")
client = client or build_client("catalogi")
if client:
case.status.statustype = client.fetch_single_status_type(statustype_url)


def resolve_resultaat(case: Zaak, client: ZakenClient | None = None) -> None:
"""
Resolve `case.resultaat` (`str`) to a `Resultaat(ZGWModel)` object
"""
client = client or build_client("zaak")
if client and case.resultaat:
case.resultaat = client.fetch_single_result(case.resultaat)


def resolve_resultaat_type(case: Zaak, client: CatalogiClient | None = None) -> None:
"""
Resolve `case.resultaat.resultaattype` (`str`) to a `ResultaatType(ZGWModel)` object
"""
client = client or build_client("catalogi")
if client and case.resultaat:
case.resultaat.resultaattype = client.fetch_single_resultaat_type(
case.resultaat.resultaattype
)


def add_zaak_type_config(case: Zaak) -> None:
"""
Add `ZaakTypeConfig` corresponding to the zaaktype type url of the case
Expand Down Expand Up @@ -90,6 +110,8 @@ def preprocess_data(cases: list[Zaak]) -> list[Zaak]:
def preprocess_case(case: Zaak) -> None:
resolve_status(case, client=zaken_client)
resolve_status_type(case, client=catalogi_client)
resolve_resultaat(case, client=zaken_client)
resolve_resultaat_type(case, client=catalogi_client)
add_zaak_type_config(case)
add_status_type_config(case)

Expand Down
52 changes: 51 additions & 1 deletion src/open_inwoner/openzaak/tests/test_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ def setUp(self):
volgnummer=2,
isEindstatus=True,
)
self.resultaat_type = generate_oas_component_cached(
"ztc",
"schemas/ResultaatType",
url=f"{CATALOGI_ROOT}resultaattypen/ab798107-ab27-4c3c-977d-777yu878km09",
zaaktype=self.zaaktype["url"],
omschrijving="Eindresultaat",
resultaattypeomschrijving="test1",
selectielijstklasse="ABC",
)

self.catalogus_config = CatalogusConfigFactory.create(
url=self.zaaktype["catalogus"]
Expand Down Expand Up @@ -274,6 +283,31 @@ def setUp(self):
datumStatusGezet="2021-03-12",
statustoelichting="",
)

self.zaak_result = generate_oas_component_cached(
"zrc",
"schemas/Zaak",
url=f"{ZAKEN_ROOT}zaken/e4d469b9-6666-4bdd-bf42-b53445298123",
uuid="e4d469b9-6666-4bdd-bf42-b53445298123",
zaaktype=self.zaaktype["url"],
identificatie="0014ESUITE43212022",
omschrijving="Result zaak",
startdatum="2020-01-01",
einddatum="2022-01-13",
status=f"{ZAKEN_ROOT}statussen/3da81560-c7fc-476a-ad13-beu760sle929",
resultaat=f"{ZAKEN_ROOT}resultaten/3da81560-c7fc-476a-ad13-beu760sle929",
vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduidingen.openbaar,
)
self.result = generate_oas_component_cached(
"zrc",
"schemas/Resultaat",
uuid="a44153aa-ad2c-6a07-be75-15add5113",
url=self.zaak_result["resultaat"],
resultaattype=self.resultaat_type["url"],
zaak=self.zaak_result["url"],
toelichting="resultaat toelichting",
)

self.zaak_eherkenning1 = generate_oas_component_cached(
"zrc",
"schemas/Zaak",
Expand Down Expand Up @@ -366,7 +400,7 @@ def _setUpMocks(self, m):
)
.url,
json=paginated_response(
[self.zaak1, self.zaak2, self.zaak3, self.zaak_intern]
[self.zaak1, self.zaak2, self.zaak3, self.zaak_intern, self.zaak_result]
),
)
for identifier in [self.eherkenning_user.kvk, self.eherkenning_user.rsin]:
Expand Down Expand Up @@ -399,6 +433,8 @@ def _setUpMocks(self, m):
self.zaaktype,
self.status_type_initial,
self.status_type_finish,
self.resultaat_type,
self.result,
self.status1,
self.status2,
self.status3,
Expand Down Expand Up @@ -463,6 +499,20 @@ def test_list_cases(self, m):
"statustype_config": None,
"case_type": "Zaak",
},
{
"uuid": self.zaak_result["uuid"],
"start_date": datetime.date.fromisoformat(
self.zaak_result["startdatum"]
),
"end_date": datetime.date(2022, 1, 13),
"identification": self.zaak_result["identificatie"],
"description": self.zaaktype["omschrijving"],
# use result here
"current_status": self.resultaat_type["omschrijving"],
"zaaktype_config": self.zaaktype_config1,
"statustype_config": self.zt_statustype_config1,
"case_type": "Zaak",
},
],
)
# don't show internal cases
Expand Down
13 changes: 13 additions & 0 deletions src/open_inwoner/utils/glom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from glom import glom


def glom_multiple(obj, paths: tuple[str, ...], *, default=None):
if not len(paths) > 1:
raise ValueError("glom_multiple requires a tuple of at least two paths")

# note this isn't the same as using glom.Coalesce() because we also skip falsy values
for p in paths:
value = glom(obj, p, default=None)
if value:
return value
return default
14 changes: 14 additions & 0 deletions src/open_inwoner/utils/tests/test_glom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.test import SimpleTestCase

from open_inwoner.utils.glom import glom_multiple


class GlomTestCase(SimpleTestCase):
def test_glom_multiple(self):
obj = {
"aa": {"bb": 1},
"cc": {"dd": 2},
}
self.assertEquals(glom_multiple(obj, ("aa.bb", "cc.dd")), 1)
self.assertEquals(glom_multiple(obj, ("aa.xyz", "cc.dd")), 2)
self.assertEquals(glom_multiple(obj, ("aa.xyz", "cc.xyz"), default=999), 999)
Loading