Beispiel #1
0
class CaseSerializerBase(PartialUpdateExcludeReadonlySerializerMixin,
                         ClaModelSerializer):
    eligibility_check = UUIDSerializer(slug_field="reference", read_only=True)
    diagnosis = UUIDSerializer(slug_field="reference",
                               required=False,
                               read_only=True)
    personal_details = PersonalDetailsSerializerBase()
    notes = serializers.CharField(max_length=10000, required=False)
    provider_notes = serializers.CharField(max_length=5000, required=False)
    matter_type1 = serializers.SlugRelatedField(
        slug_field="code",
        required=False,
        queryset=MatterType.objects.filter(level=MATTER_TYPE_LEVELS.ONE))
    matter_type2 = serializers.SlugRelatedField(
        slug_field="code",
        required=False,
        queryset=MatterType.objects.filter(level=MATTER_TYPE_LEVELS.TWO))
    media_code = serializers.SlugRelatedField(slug_field="code",
                                              required=False)
    outcome_code = serializers.CharField(max_length=50, required=False)
    outcome_description = serializers.SerializerMethodField(
        "_get_outcome_description")
    call_started = serializers.SerializerMethodField("_call_started")

    def _call_started(self, case):
        return Log.objects.filter(case=case, code="CALL_STARTED").exists()

    def _get_outcome_description(self, case):
        return event_registry.event_registry.all().get(case.outcome_code,
                                                       {}).get(
                                                           "description", "")

    def _get_fields_for_partial_update(self):
        fields = super(CaseSerializerBase,
                       self)._get_fields_for_partial_update()
        fields.append("modified")
        return fields

    def validate(self, attrs):
        attrs = super(CaseSerializerBase, self).validate(attrs)
        if attrs.get("exempt_user") and not attrs.get("exempt_user_reason"):
            raise ValidationError({
                u"exempt_user_reason":
                [u"A reason is required if client is exempt."]
            })
        return attrs

    class Meta(object):
        model = Case
        fields = ()
        exclude = ("audit_log", )
        read_only_fields = ("exempt_user", "exempt_user_reason")
Beispiel #2
0
class ComplaintSerializerBase(serializers.ModelSerializer):
    eod = UUIDSerializer(slug_field="reference")
    owner = serializers.SlugRelatedField(slug_field="username", required=False)
    created_by = CreatedByField(read_only=True)
    category_name = serializers.CharField(source="category.name",
                                          read_only=True)
    full_name = serializers.CharField(
        source="eod.case.personal_details.full_name", read_only=True)
    category_of_law = serializers.CharField(
        source="eod.case.eligibility_check.category", read_only=True)
    case_reference = serializers.CharField(source="eod.case.reference",
                                           read_only=True)

    # # virtual fields created by extra SQL
    closed = serializers.DateTimeField(source="closed", read_only=True)
    voided = serializers.DateTimeField(source="voided", read_only=True)
    holding_letter = serializers.DateTimeField(source="holding_letter",
                                               read_only=True)
    full_letter = serializers.DateTimeField(source="full_letter",
                                            read_only=True)
    out_of_sla = NullBooleanField(source="out_of_sla", read_only=True)
    holding_letter_out_of_sla = NullBooleanField(
        source="holding_letter_out_of_sla", read_only=True)

    # # virtual fields on model
    status_label = serializers.CharField(source="status_label", read_only=True)
    requires_action_at = serializers.DateTimeField(source="requires_action_at",
                                                   read_only=True)

    class Meta:
        model = Complaint
        read_only_fields = ("created", "modified", "resolved")
        exclude = ("audit_log", )
Beispiel #3
0
class CaseSerializerFull(CaseSerializerBase):
    eligibility_check = UUIDSerializer(slug_field="reference",
                                       required=False,
                                       read_only=True)

    full_name = serializers.CharField(source="personal_details.full_name",
                                      read_only=True)
    postcode = serializers.CharField(source="personal_details.postcode",
                                     read_only=True)
    case_count = serializers.IntegerField(source="personal_details.case_count",
                                          read_only=True)

    personal_details = UUIDSerializer(required=False,
                                      slug_field="reference",
                                      read_only=True)
    thirdparty_details = UUIDSerializer(required=False,
                                        slug_field="reference",
                                        read_only=True)
    adaptation_details = UUIDSerializer(required=False,
                                        slug_field="reference",
                                        read_only=True)

    eod_details = UUIDSerializer(required=False,
                                 slug_field="reference",
                                 read_only=True)
    flagged_with_eod = serializers.BooleanField(source="flagged_with_eod",
                                                read_only=True)

    created = serializers.DateTimeField(read_only=True)
    modified = serializers.DateTimeField(read_only=True)
    created_by = serializers.CharField(read_only=True)
    provider = serializers.PrimaryKeyRelatedField(required=False,
                                                  read_only=True)
    provider_viewed = serializers.DateTimeField(required=False, read_only=True)

    eligibility_state = serializers.CharField(source="eligibility_check.state",
                                              read_only=True)
    diagnosis_state = serializers.CharField(source="diagnosis.state",
                                            read_only=True)

    date_of_birth = serializers.CharField(
        source="personal_details.date_of_birth", read_only=True)
    category = serializers.CharField(source="diagnosis.category.name",
                                     read_only=True)

    class Meta(CaseSerializerBase.Meta):
        fields = ()
Beispiel #4
0
class CreateCaseSerializer(CaseSerializer):
    """
    Case Serializer only used for creation.

    It allows the API to create a case with optional personal_details reference.
    No other fields can be used when creating a case atm.
    """
    personal_details = UUIDSerializer(slug_field='reference', required=False)
class CreateCaseSerializer(CaseSerializer):
    """
    Case Serializer only used for creation.

    It allows the API to create a case with optional personal_details reference.
    No other fields can be used when creating a case atm.
    """

    personal_details = UUIDSerializer(slug_field="reference", required=False)

    class Meta(CaseSerializer.Meta):
        fields = tuple(set(CaseSerializer.Meta.fields) - {"complaint_count"})
Beispiel #6
0
class CaseSerializerBase(PartialUpdateExcludeReadonlySerializerMixin,
                         ClaModelSerializer):
    eligibility_check = UUIDSerializer(slug_field='reference', read_only=True)
    diagnosis = UUIDSerializer(slug_field='reference',
                               required=False,
                               read_only=True)
    personal_details = PersonalDetailsSerializerBase()
    notes = serializers.CharField(max_length=5000, required=False)
    provider_notes = serializers.CharField(max_length=5000, required=False)
    matter_type1 = serializers.SlugRelatedField(
        slug_field='code',
        required=False,
        queryset=MatterType.objects.filter(level=MATTER_TYPE_LEVELS.ONE))
    matter_type2 = serializers.SlugRelatedField(
        slug_field='code',
        required=False,
        queryset=MatterType.objects.filter(level=MATTER_TYPE_LEVELS.TWO))
    media_code = serializers.SlugRelatedField(slug_field='code',
                                              required=False)
    outcome_code = serializers.CharField(max_length=50, required=False)

    def _get_fields_for_partial_update(self):
        fields = super(CaseSerializerBase,
                       self)._get_fields_for_partial_update()
        fields.append('modified')
        return fields

    def validate(self, attrs):
        attrs = super(CaseSerializerBase, self).validate(attrs)
        if attrs.get('exempt_user') and not attrs.get('exempt_user_reason'):
            raise ValidationError({
                u'exempt_user_reason':
                [u'A reason is required if client is exempt.']
            })
        return attrs

    class Meta:
        model = Case
        fields = ()