Fakultas Ilmu Komputer UI

Commit 1f469430 authored by Dave Nathanael's avatar Dave Nathanael
Browse files

Implement `is_positive` field on `InvestigationCase`

parent 263b4ecb
......@@ -14,6 +14,11 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='account',
name='phone_number',
field=models.CharField(max_length=64, validators=[django.core.validators.RegexValidator(message='Phone number has 9-15 digits, allowed to have + prefix', regex='^\\+?\\d{9,15}$')]),
field=models.CharField(
max_length=64,
validators=[
django.core.validators.RegexValidator(
message='Phone number has 9-15 digits, allowed to have + prefix',
regex='^\\+?\\d{9,15}$')]),
),
]
......@@ -45,12 +45,14 @@ INVESTIGATION_CASE_FILTERSET_FIELDS = (
"reference_case__is_referral_needed",
"reference_case__medical_facility_reference",
"reference_case__outcome",
"reference_case__is_positive",
"case_relation",
"medical_symptoms",
"risk_factors",
"is_referral_needed",
"medical_facility_reference",
"outcome",
"is_positive",
"author__name",
"created_at",
)
......@@ -67,12 +69,14 @@ INVESTIGATION_CASE_SEARCH_FIELDS = (
"reference_case__risk_factors",
"reference_case__medical_facility_reference",
"reference_case__outcome",
"reference_case__is_positive",
"reference_case__created_at",
"case_relation",
"medical_symptoms",
"risk_factors",
"medical_facility_reference",
"outcome",
"is_positive",
"author__name",
)
......@@ -90,6 +94,7 @@ INVESTIGATION_CASE_ORDERING_FIELDS = (
"reference_case__is_referral_needed",
"reference_case__medical_facility_reference",
"reference_case__outcome",
"reference_case__is_positive",
"reference_case__created_at",
"case_relation",
"medical_symptoms",
......@@ -97,6 +102,7 @@ INVESTIGATION_CASE_ORDERING_FIELDS = (
"is_referral_needed",
"medical_facility_reference",
"outcome",
"is_positive",
"author__name",
"created_at",
)
......@@ -115,6 +121,7 @@ MONITORING_CASE_FILTERSET_FIELDS = (
"investigation_case__reference_case__is_referral_needed",
"investigation_case__reference_case__medical_facility_reference",
"investigation_case__reference_case__outcome",
"investigation_case__reference_case__is_positive",
"is_referred",
"is_checked",
"is_medicated",
......@@ -138,6 +145,7 @@ MONITORING_CASE_SEARCH_FIELDS = (
"investigation_case__reference_case__risk_factors",
"investigation_case__reference_case__medical_facility_reference",
"investigation_case__reference_case__outcome",
"investigation_case__reference_case__is_positive",
"investigation_case__reference_case__created_at",
"is_referred",
"is_checked",
......@@ -163,6 +171,7 @@ MONITORING_CASE_ORDERING_FIELDS = (
"investigation_case__reference_case__is_referral_needed",
"investigation_case__reference_case__medical_facility_reference",
"investigation_case__reference_case__outcome",
"investigation_case__reference_case__is_positive",
"investigation_case__reference_case__created_at",
"is_referred",
"is_checked",
......
# Generated by Django 3.0.1 on 2020-05-18 08:32
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cases', '0011_monitoring_checking_date'),
]
operations = [
migrations.AddField(
model_name='investigationcase',
name='is_positive',
field=models.BooleanField(db_index=True, null=True),
),
migrations.AddField(
model_name='investigationcasehistory',
name='is_positive',
field=models.BooleanField(db_index=True, null=True),
),
]
......@@ -79,6 +79,7 @@ class InvestigationCaseHistory(HistoryModel):
is_referral_needed = models.BooleanField(db_index=True)
medical_facility_reference = models.CharField(max_length=128, blank=True)
outcome = models.CharField(max_length=256, blank=True, null=True)
is_positive = models.BooleanField(db_index=True, null=True)
author = models.ForeignKey(
Account,
blank=True,
......@@ -129,6 +130,7 @@ class InvestigationCase(HistoryEnabledModel):
is_referral_needed = models.BooleanField(db_index=True)
medical_facility_reference = models.CharField(max_length=128, blank=True)
outcome = models.CharField(max_length=256, blank=True, null=True)
is_positive = models.BooleanField(db_index=True, null=True)
author = models.ForeignKey(
Account,
blank=True,
......
......@@ -63,6 +63,7 @@ class InvestigationCaseSummarySerializer(serializers.ModelSerializer):
"is_referral_needed",
"medical_facility_reference",
"outcome",
"is_positive",
"author",
"created_at",
]
......@@ -88,7 +89,13 @@ class InvestigationCaseSerializer(serializers.ModelSerializer):
def save(self):
account = self.context.get('request').user.account
super(InvestigationCaseSerializer, self).save(author=account)
outcome = self.validated_data.get('outcome', None)
is_positive = None
if outcome is not None:
is_positive = True if "+" in outcome else False
super(InvestigationCaseSerializer, self).save(author=account, is_positive=is_positive)
def to_representation(self, instance):
serializer = InvestigationCaseSummarySerializer(instance)
......
......@@ -34,6 +34,7 @@ class InvestigationCaseViewTest(APITestCase):
case_subject=cls.case_subject,
author=cls.author,
outcome="BTA+",
is_positive=True,
)
cls.case = InvestigationCaseFactory(
author=cls.author,
......@@ -209,6 +210,40 @@ class InvestigationCaseViewTest(APITestCase):
investigation_case_history_current_count, investigation_case_history_prev_count + 1
)
def test_edit_investigation_to_positive_success(self):
url = self.BASE_URL + str(self.case.id) + "/"
data = {
"case_subject": str(self.case_subject.id),
"reference_case": str(self.reference_case.id),
"case_relation": self.case.case_relation,
"medical_symptoms": self.case.medical_symptoms,
"risk_factors": self.case.risk_factors,
"is_referral_needed": not self.case.is_referral_needed,
"medical_facility_reference": self.case.medical_facility_reference,
"outcome": "BTA+",
}
investigation_case_prev_count = InvestigationCase.objects.all().count()
positive_case_prev_count = InvestigationCase.objects.filter(is_positive=True).count()
response = self.client.put(path=url, data=data, format="json",)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(
response.data["is_referral_needed"], not self.case.is_referral_needed
)
investigation_case_current_count = InvestigationCase.objects.all().count()
positive_case_current_count = InvestigationCase.objects.filter(is_positive=True).count()
self.assertEqual(
investigation_case_current_count, investigation_case_prev_count
)
self.assertEqual(
positive_case_current_count, positive_case_prev_count + 1
)
def test_edit_investigation_case_fails_with_incomplete_data(self):
url = self.BASE_URL + str(self.case.id) + "/"
......
......@@ -71,7 +71,7 @@ class InvestigationCaseViewSet(viewsets.ModelViewSet):
query_include_positive = self.request.query_params.get('include_positive', None)
if query_include_positive is not None:
return self.queryset
return self.queryset.filter(Q(outcome__isnull=True) | Q(outcome__icontains="-"))
return self.queryset.exclude(is_positive=True)
return self.queryset
def get_serializer_class(self):
......@@ -85,8 +85,7 @@ class InvestigationCaseViewSet(viewsets.ModelViewSet):
class InvestigationPositiveCaseAPIView(ListAPIView):
serializer_class = InvestigationCaseSummarySerializer
queryset = InvestigationCase.objects.filter(
outcome__isnull=False).exclude(outcome__icontains="-")
queryset = InvestigationCase.objects.filter(is_positive=True)
filter_backends = (DjangoFilterBackend, SearchFilter, OrderingFilter)
permission_classes = (IsAuthenticated,)
pagination_class = PageNumberPagination
......
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