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 7, 2024
1 parent d5495db commit 606a820
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 34 deletions.
8 changes: 7 additions & 1 deletion src/open_inwoner/accounts/views/contactmoments.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,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_source": KlantenServiceType.esuite,
"kcm_uuid": kcm.uuid,
},
)
)
37 changes: 6 additions & 31 deletions src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,14 @@
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.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.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 @@ -164,36 +159,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 = []
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
questions = esuite_service.retrieve_questions_for_zaak(
self.case, user=self.request.user
)

# 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
25 changes: 25 additions & 0 deletions src/open_inwoner/openklant/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,31 @@ def retrieve_question(

return self._get_question_data(kcm), zaak_with_api_group

def retrieve_questions_for_zaak(self, zaak, user: User) -> list[Question]:
objectcontactmomenten = self.retrieve_objectcontactmomenten_for_zaak(zaak)

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, user)
for question in questions:
question.new_answer_available = contactmoment_has_new_answer(
question, kcm_answer_mapping
)

if exclude_range := self.config.exclude_contactmoment_kanalen:
questions = [
item
for item in questions
if glom.glom(item, "kanaal") not in exclude_range
]

return questions


@dataclass(frozen=True)
class OpenKlant2Answer:
Expand Down
10 changes: 8 additions & 2 deletions src/open_inwoner/openzaak/tests/test_case_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
from open_inwoner.accounts.tests.factories import UserFactory, eHerkenningUserFactory
from open_inwoner.cms.cases.views.status import InnerCaseDetailView, SimpleFile
from open_inwoner.openklant.api_models import ObjectContactMoment
from open_inwoner.openklant.constants import Status as ContactMomentStatus
from open_inwoner.openklant.constants import (
KlantenServiceType,
Status as ContactMomentStatus,
)
from open_inwoner.openklant.models import OpenKlantConfig
from open_inwoner.openklant.services import eSuiteVragenService
from open_inwoner.openklant.tests.factories import make_contactmoment
Expand Down Expand Up @@ -2550,7 +2553,10 @@ def test_kcm_redirect(self, m):
response,
reverse(
"cases:contactmoment_detail",
kwargs={"kcm_uuid": uuid_from_url(klant_contactmoment["url"])},
kwargs={
"api_source": KlantenServiceType.esuite,
"kcm_uuid": uuid_from_url(klant_contactmoment["url"]),
},
),
status_code=302,
target_status_code=200,
Expand Down

0 comments on commit 606a820

Please sign in to comment.