Skip to content

Commit

Permalink
[#2996] Retrieve questions linked to a zaak with OpenKlant
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Schilling committed Jan 31, 2025
1 parent db9980d commit f8f466d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/open_inwoner/cms/cases/views/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def resolve_case(self, case: Zaak, group: ZGWApiGroupConfig) -> Zaak:

case.zaaktype_config = zaaktype_config

if zaaktype_config:
if zaaktype_config and case.status:
statustype_config = ZaakTypeStatusTypeConfig.objects.get(
zaaktype_config=zaaktype_config,
statustype_url=case.status.statustype.url,
Expand Down
2 changes: 1 addition & 1 deletion src/open_inwoner/cms/cases/views/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def get_context_data(self, **kwargs):
self.case, user=self.request.user
)
)
questions.sort(key=lambda q: q["registered_date"], reverse=True)
# questions.sort(key=lambda q: q["registered_date"], reverse=True)

statustypen = []
catalogi_client = api_group.catalogi_client
Expand Down
65 changes: 41 additions & 24 deletions src/open_inwoner/openklant/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
from open_inwoner.utils.api import ClientError, get_json_response
from open_inwoner.utils.logentry import system_action
from open_inwoner.utils.time import instance_is_new
from open_inwoner.utils.url import uuid_from_url
from open_inwoner.utils.views import LogMixin
from openklant2.client import OpenKlant2Client
from openklant2.types.resources.digitaal_adres import DigitaalAdres
Expand Down Expand Up @@ -1318,27 +1317,30 @@ def questions_for_partij(self, partij_uuid: str) -> list[OpenKlant2Question]:
klantcontact["uuid"]
] = klantcontact

# TODO: revisit answer/question check
# A klantcontact is an answer if it is linked to a Question via an onderwerp object
if onderwerp_objecten := klantcontact["gingOverOnderwerpobjecten"]:

# To which question klantcontact is this an answer?
answer_onderwerp_object = self.client.onderwerp_object.retrieve(
onderwerp_objecten[0]["uuid"]
)

if not answer_onderwerp_object["wasKlantcontact"]:
logger.error(
"Onderwerp object %s should point to question klantcontact",
answer_onderwerp_object["uuid"],
)
continue

# Map the question to the answer
question_uuid = answer_onderwerp_object["wasKlantcontact"]["uuid"]
answers_for_klantcontact_uuid[question_uuid] = klantcontact["uuid"]
else:
# No onderwerp object, so we treat this klantcontact as a question
question_uuids.append(klantcontact["uuid"])
# if onderwerp_objecten := klantcontact["gingOverOnderwerpobjecten"]:
#
# # To which question klantcontact is this an answer?
# answer_onderwerp_object = self.client.onderwerp_object.retrieve(
# onderwerp_objecten[0]["uuid"]
# )
#
# if not answer_onderwerp_object["wasKlantcontact"]:
# logger.error(
# "Onderwerp object %s should point to question klantcontact",
# answer_onderwerp_object["uuid"],
# )
# continue
#
# # Map the question to the answer
# question_uuid = answer_onderwerp_object["wasKlantcontact"]["uuid"]
# answers_for_klantcontact_uuid[question_uuid] = klantcontact["uuid"]
# else:
# # No onderwerp object, so we treat this klantcontact as a question
# question_uuids.append(klantcontact["uuid"])

question_uuids.append(klantcontact["uuid"])

question_objs: list[OpenKlant2Question] = []
for question_uuid in question_uuids:
Expand Down Expand Up @@ -1383,6 +1385,7 @@ def retrieve_question(
partij = self.find_organisatie_for_kvk(kvk_or_rsin)

all_questions = self.questions_for_partij(partij_uuid=partij["uuid"])
breakpoint()
question = next(
q for q in all_questions if q.question_kcm_uuid == question_uuid
)
Expand Down Expand Up @@ -1416,7 +1419,7 @@ def _build_question_dto(
{
"identification": question_ok2.nummer,
"api_source_url": question_ok2.url,
"api_source_uuid": uuid_from_url(question_ok2.url),
"api_source_uuid": str(question_ok2.question_kcm_uuid),
"subject": question_ok2.onderwerp,
"question_text": question_ok2.question,
"answer_text": answer_text,
Expand All @@ -1441,5 +1444,19 @@ def _has_new_answer_available(
)
return answer_is_recent and not answer.is_seen

def list_questions_for_zaak(self, zaak: Zaak, user: User) -> list[Question]:
return []
def list_questions_for_zaak(
self,
zaak: Zaak,
user: User,
) -> list[Question]:
klantcontacten_for_zaak = self.client.klant_contact.list(
params={
"onderwerpobject__onderwerpobjectidentificatorObjectId": zaak.identificatie
}
)["results"]

questions = [
OpenKlant2Question.from_klantcontact_and_answer(klantcontact, None)
for klantcontact in klantcontacten_for_zaak
]
return self._build_question_dtos(questions_ok2=questions, user=user)

0 comments on commit f8f466d

Please sign in to comment.