Skip to content

Commit

Permalink
[#2862] Integrate OpenKlant2 service with zaak detail view
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-sigma committed Nov 12, 2024
1 parent 1953136 commit b838099
Show file tree
Hide file tree
Showing 16 changed files with 537 additions and 407 deletions.
39 changes: 22 additions & 17 deletions src/open_inwoner/accounts/views/contactmoments.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ def get_context_data(self, **kwargs):
)
all_questions = questions_esuite + questions_ok2
all_questions.sort(key=lambda q: q["registered_date"], reverse=True)
ctx["contactmomenten"] = all_questions
ctx["questions"] = all_questions

paginator_dict = self.paginate_with_context(ctx["contactmomenten"])
paginator_dict = self.paginate_with_context(ctx["questions"])
ctx.update(paginator_dict)

return ctx
Expand All @@ -175,28 +175,27 @@ def get_anchors(self) -> list:
def get_context_data(self, **kwargs):
ctx = super().get_context_data(**kwargs)

if KlantenServiceType.esuite in self.request.path:
service = self.get_service(service_type=KlantenServiceType.esuite)
elif KlantenServiceType.openklant2 in self.request.path:
service = self.get_service(service_type=KlantenServiceType.openklant2)
if KlantenServiceType.ESUITE.value in self.request.path:
service = self.get_service(service_type=KlantenServiceType.ESUITE)
elif KlantenServiceType.OPENKLANT2.value in self.request.path:
service = self.get_service(service_type=KlantenServiceType.OPENKLANT2)

kcm, zaak = service.retrieve_question(
question, zaak = service.retrieve_question(
self.get_fetch_params(service), kwargs["kcm_uuid"], user=self.request.user
)
if not kcm:
if not question:
raise Http404()

QuestionValidator.validate_python(kcm)
QuestionValidator.validate_python(question)

local_kcm, created = KlantContactMomentAnswer.objects.get_or_create( # noqa
user=self.request.user, contactmoment_url=kcm["url"]
user=self.request.user, contactmoment_url=question["source_url"]
)
if not local_kcm.is_seen:
local_kcm.is_seen = True
local_kcm.save()

contactmoment = kcm
ctx["contactmoment"] = contactmoment
ctx["question"] = question
ctx["zaak"] = zaak.zaak if zaak else None
case_url = (
reverse(
Expand All @@ -212,19 +211,19 @@ def get_context_data(self, **kwargs):
ctx["metrics"] = [
{
"label": _("Status: "),
"value": contactmoment["status"],
"value": question["status"],
},
{
"label": _("Ingediend op: "),
"value": contactmoment["registered_date"],
"value": question["registered_date"],
},
{
"label": _("Vraag nummer: "),
"value": contactmoment["identification"],
"value": question["identification"],
},
{
"label": _("Contact gehad via: "),
"value": contactmoment["channel"],
"value": question["channel"],
},
]
origin = self.request.headers.get("Referer")
Expand Down Expand Up @@ -275,5 +274,11 @@ def get(self, request, *args, **kwargs):
raise Http404

return HttpResponseRedirect(
reverse("cases:contactmoment_detail", kwargs={"kcm_uuid": kcm.uuid})
reverse(
"cases:contactmoment_detail",
kwargs={
"api_service": KlantenServiceType.ESUITE.value,
"kcm_uuid": kcm.uuid,
},
)
)
2 changes: 1 addition & 1 deletion src/open_inwoner/cms/cases/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
name="contactmoment_list",
),
path(
"contactmomenten/<str:api_source>/<str:kcm_uuid>/",
"contactmomenten/<str:api_service>/<str:kcm_uuid>/",
KlantContactMomentDetailView.as_view(),
name="contactmoment_detail",
),
Expand Down
52 changes: 21 additions & 31 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from collections import defaultdict
from datetime import datetime
from typing import Iterable, Protocol

from django.conf import settings
from django.contrib import messages
Expand All @@ -20,19 +21,19 @@
from django.views.generic import FormView, TemplateView

from django_htmx.http import HttpResponseClientRedirect
from glom import glom
from mail_editor.helpers import find_template
from view_breadcrumbs import BaseBreadcrumbMixin
from zgw_consumers.api_models.constants import RolOmschrijving

from open_inwoner.accounts.models import User
from open_inwoner.mail.service import send_contact_confirmation_mail
from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.openklant.services import eSuiteKlantenService, eSuiteVragenService
from open_inwoner.openklant.wrap import (
contactmoment_has_new_answer,
get_fetch_parameters,
get_kcm_answer_mapping,
from open_inwoner.openklant.services import (
Question,
eSuiteKlantenService,
eSuiteVragenService,
)
from open_inwoner.openklant.wrap import get_fetch_parameters
from open_inwoner.openzaak.api_models import Status, StatusType, Zaak
from open_inwoner.openzaak.clients import CatalogiClient, ZakenClient
from open_inwoner.openzaak.documents import (
Expand Down Expand Up @@ -67,6 +68,15 @@ class SimpleFile:
created: datetime | None = None


class VragenService(Protocol):
def list_questions_for_zaak(
self,
zaak: Zaak,
user: User | None = None,
) -> Iterable[Question]: # noqa: E704
...


class OuterCaseDetailView(
OuterCaseAccessMixin, CommonPageMixin, BaseBreadcrumbMixin, TemplateView
):
Expand Down Expand Up @@ -164,36 +174,16 @@ def get_context_data(self, **kwargs):

# questions/E-suite contactmomenten
try:
service = eSuiteVragenService(config=openklant_config)
esuite_service = eSuiteVragenService(config=openklant_config)
except RuntimeError:
logger.error("Failed to build eSuiteVragenService")
objectcontactmomenten = []
questions = []
else:
objectcontactmomenten = service.retrieve_objectcontactmomenten_for_zaak(
self.case
questions = esuite_service.list_questions_for_zaak(
self.case, user=self.request.user
)

questions = []
for ocm in objectcontactmomenten:
question = getattr(ocm, "contactmoment", None)
if question:
questions.append(question)
questions.sort(key=lambda q: q.registratiedatum, reverse=True)

kcm_answer_mapping = get_kcm_answer_mapping(questions, self.request.user)
for question in questions:
question.new_answer_available = contactmoment_has_new_answer(
question, kcm_answer_mapping
)

# filter questions
openklant_config = OpenKlantConfig.get_solo()
if exclude_range := openklant_config.exclude_contactmoment_kanalen:
questions = [
item
for item in questions
if glom(item, "kanaal") not in exclude_range
]
# TODO: fetch OpenKlant2 questions + combine

statustypen = []
catalogi_client = api_group.catalogi_client
Expand Down
Loading

0 comments on commit b838099

Please sign in to comment.