Fakultas Ilmu Komputer UI

Commit 3dbaec9a authored by Dave Nathanael's avatar Dave Nathanael
Browse files

[GREEN] Rework CaseSubject and InvestigationCase and fix issues

parent 89e461fd
Pipeline #41132 failed with stages
in 2 minutes and 9 seconds
......@@ -2,25 +2,25 @@ from django_filters.rest_framework import FilterSet
from apps.cases.models import InvestigationCase, MonitoringCase
CASE_SUBJECT_FILTERSET_FIELDS = [
CASE_SUBJECT_FILTERSET_FIELDS = (
"name",
"age",
"is_male",
"address",
"district",
"sub_district",
]
)
CASE_SUBJECT_SEARCH_FIELDS = [
CASE_SUBJECT_SEARCH_FIELDS = (
"name",
"age",
"address",
"district",
"sub_district",
"created_at",
]
)
CASE_SUBJECT_ORDERING_FIELDS = [
CASE_SUBJECT_ORDERING_FIELDS = (
"name",
"age",
"is_male",
......@@ -28,9 +28,9 @@ CASE_SUBJECT_ORDERING_FIELDS = [
"district",
"sub_district",
"created_at",
]
)
INVESTIGATION_CASE_FILTERSET_FIELDS = [
INVESTIGATION_CASE_FILTERSET_FIELDS = (
"case_subject__name",
"case_subject__age",
"case_subject__is_male",
......@@ -49,9 +49,9 @@ INVESTIGATION_CASE_FILTERSET_FIELDS = [
"is_referral_needed",
"medical_facility_reference",
"outcome",
]
)
INVESTIGATION_CASE_SEARCH_FIELDS = [
INVESTIGATION_CASE_SEARCH_FIELDS = (
"case_subject__name",
"case_subject__age",
"case_subject__address",
......@@ -70,9 +70,9 @@ INVESTIGATION_CASE_SEARCH_FIELDS = [
"medical_facility_reference",
"outcome",
"created_at",
]
)
INVESTIGATION_CASE_ORDERING_FIELDS = [
INVESTIGATION_CASE_ORDERING_FIELDS = (
"case_subject__name",
"case_subject__age",
"case_subject__is_male",
......@@ -94,13 +94,13 @@ INVESTIGATION_CASE_ORDERING_FIELDS = [
"medical_facility_reference",
"outcome",
"created_at",
]
)
class MonitoringCaseFilter(FilterSet):
class Meta:
model = MonitoringCase
fields = [
fields = (
"investigation_case_id",
"is_referred",
"is_checked",
......@@ -108,4 +108,4 @@ class MonitoringCaseFilter(FilterSet):
"treatment_start_date",
"treatment_end_date",
"author",
]
)
# Generated by Django 3.0.1 on 2020-04-18 09:32
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('cases', '0006_auto_20200417_2200'),
]
operations = [
migrations.AddField(
model_name='investigationcase',
name='case_subject',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='investigation_case', to='cases.CaseSubject'),
),
migrations.AddField(
model_name='investigationcase',
name='reference_case',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='referring_investigation_case', to='cases.InvestigationCase'),
),
]
......@@ -148,6 +148,9 @@ class InvestigationCase(HistoryEnabledModel):
related_name="investigation_case",
)
history_class = InvestigationCaseHistory
relation_fields = ["case_subject", "reference_case"]
objects = SoftDeleteManager()
class Meta:
......@@ -158,18 +161,6 @@ class InvestigationCase(HistoryEnabledModel):
def __str__(self):
return f"[Active] ID. {self.id} | by {self.author}"
@property
def reference_case(self):
return InvestigationCase.objects.filter(
is_active=True, deleted_at__isnull=True, case_id=self.reference_case_id
).first()
@property
def case_subject(self):
return CaseSubject.objects.filter(
is_active=True, deleted_at__isnull=True, subject_id=self.case_subject_id
).first()
class MonitoringCase(models.Model):
revision_id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
......
......@@ -45,9 +45,8 @@ class CaseSubjectHistorySerializer(serializers.ModelSerializer):
class InvestigationCaseSummarySerializer(serializers.ModelSerializer):
# case_subject = CaseSubjectSerializer()
# reference_case = InvestigationCaseSummarySerializer()
# author = AccountSerializer()
case_subject = CaseSubjectSerializer()
author = AccountSerializer()
class Meta:
model = InvestigationCase
......
......@@ -46,6 +46,12 @@ class HistoryEnabledModel(SoftDeleteModel):
instance_dict.pop("created_at")
instance_dict.pop("deleted_at")
if hasattr(self, "relation_fields"):
for field in self.relation_fields:
value = instance_dict[field]
instance_dict["{}_id".format(field)] = str(value) if value != None else value
instance_dict.pop(field)
action = ACTIVITY_TYPE_CREATE if self._state.adding else ACTIVITY_TYPE_EDIT
instance_dict["object_id"] = self.id
instance_dict["action_type"] = action
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment