<commit_before>.. doctest docs/specs/welfare/pcsw.rst
.. _welfare.specs.pcsw:

==========================================
The :mod:`lino_welfare.modlib.pcsw` plugin
==========================================

This page describes the :mod:`lino_welfare.modlib.pcsw` plugin.

.. contents:: Contents
   :local:
   :depth: 2

.. include:: /include/tested.rst
  
>>> from lino import startup
>>> startup('lino_book.projects.gerd.settings.doctests')
>>> from lino.api.doctest import *



.. >>> len(settings.SITE.languages)
   3

.. currentmodule:: lino_welfare.modlib.pcsw


Client events
==============

>>> show_choicelist(pcsw.ClientEvents)
=========== =========== ===================== ========================= ========================
 value       name        de                    fr                        en
----------- ----------- --------------------- ------------------------- ------------------------
 created     created     Erstellt              Créé                      Created
 modified    modified    Bearbeitet            Modifié                   Modified
 note        note        Notiz                 Notiz                     Note
 dispense    dispense    Dispenz               Dispenz                   Dispense
 penalty     penalty     AG-Sperre             AG-Sperre                 Penalty
 active      active      Begleitung            Intervention              Coaching
 isip        isip        VSE                   PIIS                      ISIP
 jobs        jobs        Art.60§7-Konvention   Mise à l'emploi art60§7   Art60§7 job supplyment
 available   available   Verfügbar             Verfügbar                 Available
 art61       art61       Art.61-Konvention     Mise à l'emploi art.61    Art61 job supplyment
=========== =========== ===================== ========================= ========================
<BLANKLINE>


Refusal reasons
================

>>> show_choicelist(pcsw.RefusalReasons)
======= ====== ============================================= ============================================ ==========================================
 value   name   de                                            fr                                           en
------- ------ --------------------------------------------- -------------------------------------------- ------------------------------------------
 10      None   Information (keine Begleitung erforderlich)   Demande d'information (pas d'intervention)   Information request (No coaching needed)
 20      None   ÖSHZ ist nicht zuständig                      CPAS n'est pas compétent                     PCSW is not competent
 30      None   Antragsteller ist nicht zurück gekommen       Client n'est plus revenu                     Client did not return
======= ====== ============================================= ============================================ ==========================================
<BLANKLINE>




eID card summary
================

Here a test case (fixed :blogref:`20130827`) 
to test the new `eid_info` field:

>>> soup = get_json_soup('rolf', 'pcsw/Clients/116', 'overview')
>>> print(soup.get_text("\n"))
... #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE +REPORT_UDIFF
Ansicht als Person , Klient
Herr 
<NAME>
Am Bahndamm
4700 Eupen
Adressen verwalten
Karte Nr. 123456789012 (C (Personalausweis für Ausländer)), ausgestellt durch Eupen
, gültig von 19.08.12 bis 18.08.13
Muss eID-Karte einlesen!
Keinen Kaffee anbieten
>>> soup = get_json_soup('rolf', 'pcsw/Clients/118', 'overview')
>>> print(soup.get_text("\n"))
... #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE +REPORT_UDIFF
Ansicht als Person ,  Klient
Frau 
<NAME>
Auf dem Spitzberg
4700 Eupen
Adressen verwalten
Karte Nr. 591413288107 (Belgischer Staatsbürger), ausgestellt durch Eupen, gültig von 19.08.11 bis 19.08.16


Coaching types
==============

>>> ses = rt.login('rolf')
>>> ses.show('coachings.CoachingTypes')
... #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE -REPORT_UDIFF
=================== ====== ====== =====================
 Bezeichnung         DSBE   ASD    Role in evaluations
------------------- ------ ------ ---------------------
 ASD                 Nein   Ja     Kollege
 DSBE                Ja     Nein   Kollege
 Schuldnerberatung   Nein   Nein
=================== ====== ====== =====================
<BLANKLINE>

.. note: above table shows only Bezeichnung in German because the othe
   languages are hidden:

   >>> hidden_languages = [lng.name for lng in ses.user.user_type.hidden_languages]
   >>> hidden_languages.sort()
   >>> hidden_languages
   ['en', 'fr']


Creating a new client
=====================


>>> url = '/api/pcsw/CoachedClients/-99999?an=insert&fmt=json'
>>> res = test_client.get(url, REMOTE_USER='rolf')
>>> res.status_code
200
>>> d = AttrDict(json.loads(res.content))
>>> keys = list(d.keys())
>>> keys.sort()
>>> rmu(keys)
... #doctest: +NORMALIZE_WHITESPACE +IGNORE_EXCEPTION_DETAIL +ELLIPSIS
['data', 'phantom', 'title']
>>> d.phantom
True
>>> print(d.title)
Einfügen in Klienten (Begleitet)

There are a lot of data fields:

>>> len(d.data.keys())
86

>>> print(' '.join(sorted(d.data.keys())))
... #doctest: +NORMALIZE_WHITESPACE +REPORT_UDIFF
AgentsByClient MovementsByProject activity activityHidden age
birth_country birth_countryHidden birth_date birth_place broker
brokerHidden cbss_identify_person cbss_manage_access cbss_relations
cbss_retrieve_ti_groups cbss_summary checkdata_ProblemsByOwner
civil_state civil_stateHidden client_state client_stateHidden created
cv_LanguageKnowledgesByPerson cvs_emitted declared_name
disable_editing disabled_fields dupable_clients_SimilarClients email
excerpts_ExcerptsByProject faculty facultyHidden fax first_name gender
genderHidden gesdos_id group groupHidden gsm
households_MembersByPerson humanlinks_LinksByHuman id id_document
image in_belgium_since income_ag income_kg income_misc income_rente
income_wg is_cpas is_obsolete is_senior job_agents language
languageHidden last_name middle_name modified national_id nationality
nationalityHidden needs_residence_permit needs_work_permit
noble_condition notes_NotesByProject obstacles overview phone
refusal_reason refusal_reasonHidden remarks remarks2 residence_type
residence_typeHidden row_class seeking_since skills tim_id
unavailable_until unavailable_why unemployed_since
uploads_UploadsByClient work_permit_suspended_until workflow_buttons





The detail action
=================

The following would have detected a bug which caused the MTI navigator
to not work (bug has been fixed :blogref:`20150227`) :

>>> from etgen.html import E
>>> p = contacts.Person.objects.get(pk=178)
>>> cli = pcsw.Client.objects.get(pk=178)
<commit_msg>adapt test cases aftger #2782<commit_after>.. doctest docs/specs/welfare/pcsw.rst
.. _welfare.specs.pcsw:

==========================================
The :mod:`lino_welfare.modlib.pcsw` plugin
==========================================

This page describes the :mod:`lino_welfare.modlib.pcsw` plugin.

.. contents:: Contents
   :local:
   :depth: 2

.. include:: /include/tested.rst
  
>>> from lino import startup
>>> startup('lino_book.projects.gerd.settings.doctests')
>>> from lino.api.doctest import *



.. >>> len(settings.SITE.languages)
   3

.. currentmodule:: lino_welfare.modlib.pcsw


Client events
==============

>>> show_choicelist(pcsw.ClientEvents)
=========== =========== ===================== ========================= ========================
 value       name        de                    fr                        en
----------- ----------- --------------------- ------------------------- ------------------------
 created     created     Erstellt              Créé                      Created
 modified    modified    Bearbeitet            Modifié                   Modified
 note        note        Notiz                 Notiz                     Note
 dispense    dispense    Dispenz               Dispenz                   Dispense
 penalty     penalty     AG-Sperre             AG-Sperre                 Penalty
 active      active      Begleitung            Intervention              Coaching
 isip        isip        VSE                   PIIS                      ISIP
 jobs        jobs        Art.60§7-Konvention   Mise à l'emploi art60§7   Art60§7 job supplyment
 available   available   Verfügbar             Verfügbar                 Available
 art61       art61       Art.61-Konvention     Mise à l'emploi art.61    Art61 job supplyment
=========== =========== ===================== ========================= ========================
<BLANKLINE>


Refusal reasons
================

>>> show_choicelist(pcsw.RefusalReasons)
======= ====== ============================================= ============================================ ==========================================
 value   name   de                                            fr                                           en
------- ------ --------------------------------------------- -------------------------------------------- ------------------------------------------
 10      None   Information (keine Begleitung erforderlich)   Demande d'information (pas d'intervention)   Information request (No coaching needed)
 20      None   ÖSHZ ist nicht zuständig                      CPAS n'est pas compétent                     PCSW is not competent
 30      None   Antragsteller ist nicht zurück gekommen       Client n'est plus revenu                     Client did not return
======= ====== ============================================= ============================================ ==========================================
<BLANKLINE>




eID card summary
================

Here a test case (fixed :blogref:`20130827`) 
to test the new `eid_info` field:

>>> soup = get_json_soup('rolf', 'pcsw/Clients/116', 'overview')
>>> print(soup.get_text("\n"))
... #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE +REPORT_UDIFF
Ansicht als Person , Klient
Herr 
<NAME>
Am Bahndamm
4700 Eupen
Adressen verwalten
Karte Nr. 123456789012 (C (Personalausweis für Ausländer)), ausgestellt durch Eupen
, gültig von 19.08.12 bis 18.08.13
Muss eID-Karte einlesen!
Keinen Kaffee anbieten
>>> soup = get_json_soup('rolf', 'pcsw/Clients/118', 'overview')
>>> print(soup.get_text("\n"))
... #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE +REPORT_UDIFF
Ansicht als Person ,  Klient
Frau 
<NAME>
Auf dem Spitzberg
4700 Eupen
Adressen verwalten
Karte Nr. 591413288107 (Belgischer Staatsbürger), ausgestellt durch Eupen, gültig von 19.08.11 bis 19.08.16


Coaching types
==============

>>> ses = rt.login('rolf')
>>> ses.show('coachings.CoachingTypes')
... #doctest: +ELLIPSIS +NORMALIZE_WHITESPACE -REPORT_UDIFF
=================== ====== ====== =====================
 Bezeichnung         DSBE   ASD    Role in evaluations
------------------- ------ ------ ---------------------
 ASD                 Nein   Ja     Kollege
 DSBE                Ja     Nein   Kollege
 Schuldnerberatung   Nein   Nein
=================== ====== ====== =====================
<BLANKLINE>

.. note: above table shows only Bezeichnung in German because the othe
   languages are hidden:

   >>> hidden_languages = [lng.name for lng in ses.user.user_type.hidden_languages]
   >>> hidden_languages.sort()
   >>> hidden_languages
   ['en', 'fr']


Creating a new client
=====================


>>> url = '/api/pcsw/CoachedClients/-99999?an=insert&fmt=json'
>>> res = test_client.get(url, REMOTE_USER='rolf')
>>> res.status_code
200
>>> d = AttrDict(json.loads(res.content))
>>> keys = list(d.keys())
>>> keys.sort()
>>> rmu(keys)
... #doctest: +NORMALIZE_WHITESPACE +IGNORE_EXCEPTION_DETAIL +ELLIPSIS
['data', 'phantom', 'title']
>>> d.phantom
True
>>> print(d.title)
Einfügen in Klienten (Begleitet)

There are a lot of data fields:

>>> len(d.data.keys())
8

>>> print(' '.join(sorted(d.data.keys())))
... #doctest: +NORMALIZE_WHITESPACE +REPORT_UDIFF
disabled_fields first_name gender genderHidden language languageHidden last_name national_id



The detail action
=================

The following would have detected a bug which caused the MTI navigator
to not work (bug has been fixed :blogref:`20150227`) :

>>> from etgen.html import E
>>> p = contacts.Person.objects.get(pk=178)
>>> cli = pcsw.Client.objects.get(pk=178)

{'fraction_non_alphanumeric': 0.24222840314136126, 'fraction_numerical': 0.02012434554973822, 'mean_word_length': 2.6568950044869877, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 187, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2104502', 'n_tokens_mistral': 3703, 'n_tokens_neox': 3370, 'n_words': 844}