Beispiel #1
0
def customise_pr_person_resource(r, tablename):

    s3db = current.s3db
    table = r.resource.table

    # Disallow "unknown" gender and defaults to "male"
    evr_gender_opts = dict((k, v) for k, v in s3db.pr_gender_opts.items()
                                  if k in (2, 3))
    gender = table.gender
    gender.requires = IS_IN_SET(evr_gender_opts, zero=None)
    gender.default = 3

    if r.controller == "evr":
        # Hide evacuees emergency contacts
        settings.pr.show_emergency_contacts = False

        # Last name and date of birth mandatory in EVR module
        table.last_name.requires = IS_NOT_EMPTY(error_message = T("Please enter a last name"))
        
        dob_requires = s3_date("dob",
                               future = 0,
                               past = 1320,
                               empty = False).requires
        dob_requires.error_message = T("Please enter a date of birth")
        table.date_of_birth.requires = dob_requires

        # Enable Location_id
        from gluon import DIV
        from s3.s3widgets import S3LocationSelectorWidget2
        levels = ("L1","L2","L3",)
        location_id = table.location_id
        location_id.readable = location_id.writable = True
        location_id.label = T("Place of Birth")
        location_id.widget = S3LocationSelectorWidget2(levels=levels,
                                                       lines=True,
                                                       )
        location_id.represent = s3db.gis_LocationRepresent(sep=" | ")
        # Enable place of birth
        place_of_birth = s3db.pr_person_details.place_of_birth
        place_of_birth.label = "Specify a Different Place of Birth"
        place_of_birth.comment = DIV(_class="tooltip",
                                    _title="%s|%s" % (T("Different Place of Birth"),
                                                      T("Specify a different place of birth (foreign country, village, hamlet)")))
        place_of_birth.readable = place_of_birth.writable = True
            
        # Disable religion selection
        s3db.pr_person_details.religion.readable = False
        s3db.pr_person_details.religion.writable = False

    # Disable unneeded physical details
    pdtable = s3db.pr_physical_description
    hide_fields = [
        "race",
        "complexion",
        "height",
        "weight",
        "hair_length",
        "hair_style",
        "hair_baldness",
        "hair_comment",
        "facial_hair_type",
        "facial_hair_length",
        "facial_hair_color",
        "facial_hair_comment",
        "body_hair",
        "skin_marks",
        "medical_conditions"
    ]
    for fname in hide_fields:
        field = pdtable[fname]
        field.readable = field.writable = False

    # This set is suitable for Italy
    ethnicity_opts = ("Italian",
                      "Chinese",
                      "Albanese",
                      "Philippine",
                      "Pakistani",
                      "English",
                      "African",
                      "Other",
                      "Unknown",
                      )
    ethnicity_opts = dict((v, T(v)) for v in ethnicity_opts)

    ethnicity = pdtable.ethnicity
    ethnicity.requires = IS_EMPTY_OR(IS_IN_SET(ethnicity_opts,
                                               sort=True))
    ethnicity.represent = S3Represent(options=ethnicity_opts,
                                      translate=True)
Beispiel #2
0
def customise_pr_person_resource(r, tablename):

    T = current.T
    s3db = current.s3db
    table = r.resource.table

    # Disallow "unknown" gender and defaults to "male"
    evr_gender_opts = dict(
        (k, v) for k, v in s3db.pr_gender_opts.items() if k in (2, 3))
    gender = table.gender
    gender.requires = IS_IN_SET(evr_gender_opts, zero=None)
    gender.default = 3

    if r.controller == "evr":
        # Hide evacuees emergency contacts
        current.deployment_settings.pr.show_emergency_contacts = False

        # Last name and date of birth mandatory in EVR module
        table.last_name.requires = IS_NOT_EMPTY(
            error_message=T("Please enter a last name"))

        dob_requires = s3_date("dob", future=0, past=1320,
                               empty=False).requires
        dob_requires.error_message = T("Please enter a date of birth")
        table.date_of_birth.requires = dob_requires

        # Enable Location_id
        from gluon import DIV
        from s3 import S3LocationSelector
        location_id = table.location_id
        location_id.readable = location_id.writable = True
        location_id.label = T("Place of Birth")
        levels = (
            "L1",
            "L2",
            "L3",
        )
        location_id.widget = S3LocationSelector(
            levels=levels,
            lines=True,
        )
        location_id.represent = s3db.gis_LocationRepresent(sep=" | ")
        # Enable place of birth
        place_of_birth = s3db.pr_person_details.place_of_birth
        place_of_birth.label = "Specify a Different Place of Birth"
        place_of_birth.comment = DIV(
            _class="tooltip",
            _title="%s|%s" %
            (T("Different Place of Birth"),
             T("Specify a different place of birth (foreign country, village, hamlet)"
               )))
        place_of_birth.readable = place_of_birth.writable = True

        # Disable religion selection
        s3db.pr_person_details.religion.readable = False
        s3db.pr_person_details.religion.writable = False

    # Disable unneeded physical details
    pdtable = s3db.pr_physical_description
    hide_fields = [
        "race", "complexion", "height", "weight", "hair_length", "hair_style",
        "hair_baldness", "hair_comment", "facial_hair_type",
        "facial_hair_length", "facial_hair_color", "facial_hair_comment",
        "body_hair", "skin_marks", "medical_conditions"
    ]
    for fname in hide_fields:
        field = pdtable[fname]
        field.readable = field.writable = False

    # This set is suitable for Italy
    ethnicity_opts = (
        "Italian",
        "Chinese",
        "Albanese",
        "Philippine",
        "Pakistani",
        "English",
        "African",
        "Other",
        "Unknown",
    )
    ethnicity_opts = dict((v, T(v)) for v in ethnicity_opts)

    ethnicity = pdtable.ethnicity
    ethnicity.requires = IS_EMPTY_OR(IS_IN_SET(ethnicity_opts, sort=True))
    ethnicity.represent = S3Represent(options=ethnicity_opts, translate=True)
    def formfields():
        """
            Generate the form fields for the registration form

            @returns: a tuple (formfields, required_fields, subheadings)
                      - formfields = list of form fields
                      - required_fields = list of field names of required fields
                      - subheadings = list of tuples (position, heading) to
                                      insert into the form
        """

        T = current.T
        request = current.request

        db = current.db
        s3db = current.s3db

        auth = current.auth
        auth_settings = auth.settings
        auth_messages = auth.messages

        utable = auth_settings.table_user
        passfield = auth_settings.password_field

        occupation_type_represent = S3Represent(
            lookup="pr_occupation_type",
            multiple=True,
        )

        # Instantiate Consent Tracker
        consent = s3db.auth_Consent(processing_types=["SHARE"])

        # Last name is required
        utable.last_name.requires = IS_NOT_EMPTY(
            error_message=T("input required"))

        ltable = s3db.gis_location

        # Form fields
        formfields = [utable.first_name,
                      utable.last_name,
                      s3_date("date_of_birth",
                              label = T("Date of Birth"),
                              future = -156,
                              empty = False,
                              ),
                      # --------------------------------------------
                      utable.email,
                      utable[passfield],

                      # Password Verification Field
                      Field("password_two", "password",
                            label = auth_messages.verify_password,
                            requires = IS_EXPR("value==%s" % \
                                               repr(request.vars.get(passfield)),
                                               error_message = auth_messages.mismatched_password,
                                               ),
                            comment = DIV(_class = "tooltip",
                                          _title = "%s|%s" % (auth_messages.verify_password,
                                                              T("Enter the same password again"),
                                                              ),
                                          ),
                            ),
                      # --------------------------------------------
                      Field("home_phone",
                            label = T("Phone"),
                            requires = IS_EMPTY_OR(IS_PHONE_NUMBER_MULTI()),
                            ),
                      Field("mobile_phone",
                            label = T("Mobile Phone"),
                            requires = IS_EMPTY_OR(IS_PHONE_NUMBER_SINGLE()),
                            ),
                      #Field("office_phone",
                      #      label = T("Office Phone"),
                      #      requires = IS_EMPTY_OR(IS_PHONE_NUMBER_MULTI()),
                      #      ),
                      # --------------------------------------------
                      s3db.gis_location_id("location_id",
                                           widget = S3LocationSelector(
                                                       show_address = False,
                                                       show_postcode = False,
                                                       show_map = False,
                                                       ),
                                           ),
                      Field("addr_street",
                            label = ltable.addr_street.label,
                            ),
                      Field("addr_postcode",
                            label = ltable.addr_postcode.label,
                            requires = IS_NOT_EMPTY(),
                            ),

                      # --------------------------------------------
                      Field("occupation_type_ids",
                            "list:reference pr_occupation_type",
                            label = T("Occupation Type"),
                            requires = IS_EMPTY_OR(IS_ONE_OF(db,
                                          "pr_occupation_type.id",
                                          occupation_type_represent,
                                          multiple=True,
                                          )),
                            represent = occupation_type_represent,
                            widget = S3MultiSelectWidget(),
                            comment = DIV(_class = "tooltip",
                                          _title = "%s|%s" % (T("Occupation Type"),
                                                              T("Select all that apply"),
                                                              ),
                                          ),
                            ),
                      Field("occupation",
                            label = T("Occupation / Speciality"),
                            comment = DIV(_class = "tooltip",
                                          _title = "%s|%s" % (T("Occupation / Speciality"),
                                                              T("Specify your exact job designation"),
                                                              ),
                                          ),
                            ),

                      # --------------------------------------------
                      s3_date("start_date",
                              label = T("Available from"),
                              default = "now",
                              past = 0,
                              set_min = "#auth_user_start_date",
                              ),
                      s3_date("end_date",
                              label = T("Available until"),
                              past = 0,
                              set_max = "#auth_user_start_date",
                              ),
                      Field("hours_per_week", "integer",
                            label = T("Hours per Week"),
                            requires = IS_EMPTY_OR(IS_INT_IN_RANGE(1, 60)),
                            comment = DIV(_class = "tooltip",
                                          _title = "%s|%s" % (T("Hours per Week"),
                                                              T("Specify the maximum number of weekly hours"),
                                                              ),
                                          ),
                            ),
                      Field("schedule", "text",
                            label = T("Availability Schedule"),
                            widget = s3_comments_widget,
                            comment = DIV(_class = "tooltip",
                                          _title = "%s|%s" % (T("Availability Schedule"),
                                                              T("Specify days/hours like: Monday 10-12; Tuesday 10-12 and 14-19; Friday 13-15"),
                                                              ),
                                          ),
                            ),
                      s3db.hrm_multi_skill_id(
                            label = T("Skills / Resources"),
                            widget = S3GroupedOptionsWidget(cols = 1,
                                                            size = None,
                                                            help_field = "comments",
                                                            ),
                            ),

                      # --------------------------------------------
                      Field("comments", "text",
                            label = T("Comments"),
                            widget = s3_comments_widget,
                            ),

                      # --------------------------------------------
                      Field("consent",
                           label = T("Consent"),
                           widget = consent.widget,
                           ),
                      ]

        # Required fields
        required_fields = [
            "first_name",
            "last_name",
        ]

        # Subheadings
        subheadings = (
            (3, T("User Account")),
            (6, T("Contact Information")),
            (8, T("Address")),
            (11, T("Occupation")),
            (13, T("Availability and Resources")),
            (18, T("Comments")),
            (19, T("Privacy")),
        )

        return formfields, required_fields, subheadings
Beispiel #4
0
def customise_pr_person_resource(r, tablename):

    s3db = current.s3db
    table = r.resource.table

    # Disallow "unknown" gender and defaults to "male"
    evr_gender_opts = dict((k, v) for k, v in s3db.pr_gender_opts.items()
                                  if k in (2, 3))
    gender = table.gender
    gender.requires = IS_IN_SET(evr_gender_opts, zero=None)
    gender.default = 3

    if r.controller == "evr":
        # Hide evacuees emergency contacts
        settings.pr.show_emergency_contacts = False

        # Last name and date of birth mandatory in EVR module
        table.last_name.requires = IS_NOT_EMPTY(
                        error_message = T("Please enter a last name"))

        dob_requires = s3_date("dob",
                               future = 0,
                               past = 1320,
                               empty = False).requires
        dob_requires.error_message = T("Please enter a date of birth")
        table.date_of_birth.requires = dob_requires

        s3db.pr_person_details.place_of_birth.requires = IS_NOT_EMPTY(
                        error_message = T("Please enter a place of birth"))

    # Disable unneeded physical details
    pdtable = s3db.pr_physical_description
    hide_fields = [
        "race",
        "complexion",
        "height",
        "weight",
        "hair_length",
        "hair_style",
        "hair_baldness",
        "hair_comment",
        "facial_hair_type",
        "facial_hair_length",
        "facial_hair_color",
        "facial_hair_comment",
        "body_hair",
        "skin_marks",
        "medical_conditions"
    ]
    for fname in hide_fields:
        field = pdtable[fname]
        field.readable = field.writable = False

    # This set is suitable for Italy
    ethnicity_opts = ("Italian",
                      "Chinese",
                      "Albanese",
                      "Philippine",
                      "Pakistani",
                      "English",
                      "African",
                      "Other",
                      "Unknown",
                      )
    ethnicity_opts = dict((v, T(v)) for v in ethnicity_opts)

    ethnicity = pdtable.ethnicity
    ethnicity.requires = IS_EMPTY_OR(IS_IN_SET(ethnicity_opts,
                                               sort=True))
    ethnicity.represent = S3Represent(options=ethnicity_opts,
                                      translate=True)

    # Enable place of birth
    place_of_birth = s3db.pr_person_details.place_of_birth
    place_of_birth.readable = place_of_birth.writable = True
Beispiel #5
0
def customise_pr_person_resource(r, tablename):

    s3db = current.s3db
    table = r.resource.table

    # Disallow "unknown" gender and defaults to "male"
    evr_gender_opts = dict(
        (k, v) for k, v in s3db.pr_gender_opts.items() if k in (2, 3))
    gender = table.gender
    gender.requires = IS_IN_SET(evr_gender_opts, zero=None)
    gender.default = 3

    if r.controller == "evr":
        # Hide evacuees emergency contacts
        settings.pr.show_emergency_contacts = False

        # Last name and date of birth mandatory in EVR module
        table.last_name.requires = IS_NOT_EMPTY(
            error_message=T("Please enter a last name"))

        dob_requires = s3_date("dob", future=0, past=1320,
                               empty=False).requires
        dob_requires.error_message = T("Please enter a date of birth")
        table.date_of_birth.requires = dob_requires

        s3db.pr_person_details.place_of_birth.requires = IS_NOT_EMPTY(
            error_message=T("Please enter a place of birth"))

    # Disable unneeded physical details
    pdtable = s3db.pr_physical_description
    hide_fields = [
        "race", "complexion", "height", "weight", "hair_length", "hair_style",
        "hair_baldness", "hair_comment", "facial_hair_type",
        "facial_hair_length", "facial_hair_color", "facial_hair_comment",
        "body_hair", "skin_marks", "medical_conditions"
    ]
    for fname in hide_fields:
        field = pdtable[fname]
        field.readable = field.writable = False

    # This set is suitable for Italy
    ethnicity_opts = (
        "Italian",
        "Chinese",
        "Albanese",
        "Philippine",
        "Pakistani",
        "English",
        "African",
        "Other",
        "Unknown",
    )
    ethnicity_opts = dict((v, T(v)) for v in ethnicity_opts)

    ethnicity = pdtable.ethnicity
    ethnicity.requires = IS_EMPTY_OR(IS_IN_SET(ethnicity_opts, sort=True))
    ethnicity.represent = S3Represent(options=ethnicity_opts, translate=True)

    # Enable place of birth
    place_of_birth = s3db.pr_person_details.place_of_birth
    place_of_birth.readable = place_of_birth.writable = True
Beispiel #6
0
    def register(self, r, **attr):
        """
            Register a test result

            @param r: the S3Request instance
            @param attr: controller attributes
        """

        if r.http not in ("GET", "POST"):
            r.error(405, current.ERROR.BAD_METHOD)
        if not r.interactive:
            r.error(415, current.ERROR.BAD_FORMAT)

        T = current.T
        db = current.db
        s3db = current.s3db
        auth = current.auth

        request = current.request
        response = current.response
        s3 = response.s3

        settings = current.deployment_settings

        # Page title and intro text
        title = T("Register Test Result")

        # Get intro text from CMS
        ctable = s3db.cms_post
        ltable = s3db.cms_post_module
        join = ltable.on((ltable.post_id == ctable.id) & \
                         (ltable.module == "disease") & \
                         (ltable.resource == "case_diagnostics") & \
                         (ltable.deleted == False))

        query = (ctable.name == "TestResultRegistrationIntro") & \
                (ctable.deleted == False)
        row = db(query).select(
            ctable.body,
            join=join,
            cache=s3db.cache,
            limitby=(0, 1),
        ).first()
        intro = row.body if row else None

        # Instantiate Consent Tracker
        consent = s3db.auth_Consent(
            processing_types=["CWA_ANONYMOUS", "CWA_PERSONAL"])

        table = s3db.disease_case_diagnostics

        # Configure disease_id
        field = table.disease_id
        if field.writable:
            default_disease = None
            offset = 1
        else:
            default_disease = field.default
            field.readable = False
            offset = 0

        # Probe date is mandatory
        field = table.probe_date
        requires = field.requires
        if isinstance(requires, IS_EMPTY_OR):
            field.requires = requires.other

        # Configure device_id
        field = table.device_id
        field.readable = field.writable = True

        dtable = s3db.disease_testing_device
        query = (dtable.device_class == "RAT") & \
                (dtable.approved == True) & \
                (dtable.available == True)
        if default_disease:
            query = (dtable.disease_id == default_disease) & query
        field.requires = IS_ONE_OF(
            db(query),
            "disease_testing_device.id",
            field.represent,
        )

        cwa_options = (
            ("NO", T("Do not report")),
            ("ANONYMOUS", T("Issue anonymous contact tracing code")),
            ("PERSONAL", T("Issue personal test certificate")),
        )
        formfields = [  # -- Test Result --
            table.site_id,
            table.disease_id,
            table.probe_date,
            table.device_id,
            table.result,

            # -- Report to CWA --
            Field(
                "report_to_cwa",
                "string",
                requires=IS_IN_SET(cwa_options, sort=False, zero=""),
                default="NO",
                label=T("Report test result to %(system)s") % CWA,
            ),
            Field(
                "last_name",
                label=T("Last Name"),
            ),
            Field(
                "first_name",
                label=T("First Name"),
            ),
            s3_date(
                "date_of_birth",
                label=T("Date of Birth"),
                month_selector=True,
            ),
            Field(
                "dcc_option",
                "boolean",
                default=False,
                label=T("Provide Digital %(title)s Certificate") %
                {"title": "COVID-19 Test"},
            ),
            Field(
                "consent",
                label="",
                widget=consent.widget,
            ),
        ]

        # Required fields
        required_fields = []

        # Subheadings
        subheadings = (
            (0, T("Test Result")),
            (4 + offset, CWA["system"]),
        )

        # Generate labels (and mark required fields in the process)
        labels, has_required = s3_mark_required(
            formfields,
            mark_required=required_fields,
        )
        s3.has_required = has_required

        # Form buttons
        REGISTER = T("Submit")
        buttons = [
            INPUT(
                _type="submit",
                _value=REGISTER,
            ),
        ]

        # Construct the form
        response.form_label_separator = ""
        form = SQLFORM.factory(table_name="test_result",
                               record=None,
                               hidden={"_next": request.vars._next},
                               labels=labels,
                               separator="",
                               showid=False,
                               submit_button=REGISTER,
                               delete_label=auth.messages.delete_label,
                               formstyle=settings.get_ui_formstyle(),
                               buttons=buttons,
                               *formfields)

        # Identify form for CSS & JS Validation
        form.add_class("result-register")

        # Add Subheadings
        if subheadings:
            for pos, heading in subheadings[::-1]:
                form[0].insert(pos, DIV(heading, _class="subheading"))

        # Inject scripts
        script = "/%s/static/themes/RLP/js/testresult.js" % r.application
        if script not in s3.scripts:
            s3.scripts.append(script)
        s3.jquery_ready.append("S3EnableNavigateAwayConfirm()")

        if form.accepts(
                request.vars,
                current.session,
                formname="register",
                onvalidation=self.validate,
        ):

            formvars = form.vars

            # Create disease_case_diagnostics record
            testresult = {
                "result": formvars.get("result"),
            }
            if "site_id" in formvars:
                testresult["site_id"] = formvars["site_id"]
            if "disease_id" in formvars:
                testresult["disease_id"] = formvars["disease_id"]
            if "probe_date" in formvars:
                testresult["probe_date"] = formvars["probe_date"]
            if "device_id" in formvars:
                testresult["device_id"] = formvars["device_id"]

            record_id = table.insert(**testresult)
            if not record_id:
                raise RuntimeError("Could not create testresult record")

            testresult["id"] = record_id
            # Set record owner
            auth = current.auth
            auth.s3_set_record_owner(table, record_id)
            auth.s3_make_session_owner(table, record_id)
            # Onaccept
            s3db.onaccept(table, testresult, method="create")
            response.confirmation = T("Test Result registered")

            report_to_cwa = formvars.get("report_to_cwa")
            if report_to_cwa == "NO":
                # Do not report to CWA, just forward to read view
                self.next = r.url(id=record_id, method="read")
            else:
                # Report to CWA and show test certificate
                dcc_option = False
                if report_to_cwa == "ANONYMOUS":
                    processing_type = "CWA_ANONYMOUS"
                    cwa_report = CWAReport(record_id)
                elif report_to_cwa == "PERSONAL":
                    dcc_option = formvars.get("dcc_option")
                    processing_type = "CWA_PERSONAL"
                    cwa_report = CWAReport(
                        record_id,
                        anonymous=False,
                        first_name=formvars.get("first_name"),
                        last_name=formvars.get("last_name"),
                        dob=formvars.get("date_of_birth"),
                        dcc=dcc_option,
                    )
                else:
                    processing_type = cwa_report = None

                if cwa_report:
                    # Register consent
                    if processing_type:
                        cwa_report.register_consent(
                            processing_type,
                            formvars.get("consent"),
                        )
                    # Send to CWA
                    success = cwa_report.send()
                    if success:
                        response.information = T(
                            "Result reported to %(system)s") % CWA
                        retry = False
                    else:
                        response.error = T("Report to %(system)s failed") % CWA
                        retry = True

                    # Store DCC data
                    if dcc_option:
                        cwa_data = cwa_report.data
                        from .dcc import DCC
                        try:
                            hcert = DCC.from_result(
                                cwa_data.get("hash"),
                                record_id,
                                cwa_data.get("fn"),
                                cwa_data.get("ln"),
                                cwa_data.get("dob"),
                            )
                        except ValueError as e:
                            hcert = None
                            response.warning = str(e)
                        if hcert:
                            hcert.save()
                        else:
                            # Remove DCC flag if hcert could not be generated
                            cwa_report.dcc = False

                    S3CustomController._view("RLPPTM", "certificate.html")

                    # Title
                    field = table.disease_id
                    if cwa_report.disease_id and field.represent:
                        disease = field.represent(cwa_report.disease_id)
                        title = "%s %s" % (disease, T("Test Result"))
                    else:
                        title = T("Test Result")

                    return {
                        "title": title,
                        "intro": None,  # TODO
                        "form": cwa_report.formatted(retry=retry),
                    }
                else:
                    response.information = T(
                        "Result not reported to %(system)s") % CWA
                    self.next = r.url(id=record_id, method="read")

            return None

        elif form.errors:
            current.response.error = T(
                "There are errors in the form, please check your input")

        # Custom View
        S3CustomController._view("RLPPTM", "testresult.html")

        return {
            "title": title,
            "intro": intro,
            "form": form,
        }