Skip to content

Commit

Permalink
Merge pull request #54 from onehealthtoolkit/fix_issues
Browse files Browse the repository at this point in the history
OSDAS-308 OSDAS-318
request to delete mutation
form evaluate simulation
  • Loading branch information
pphetra authored Dec 21, 2023
2 parents 4f994d4 + aac0d6f commit 252f7c6
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 0 deletions.
2 changes: 2 additions & 0 deletions accounts/schema/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
AdminConfigurationCreateMutation,
AdminConfigurationUpdateMutation,
AdminConfigurationDeleteMutation,
RequestToDeleteMyAccountMutation,
)


Expand Down Expand Up @@ -55,3 +56,4 @@ class Mutation(graphene.ObjectType):
admin_configuration_create = AdminConfigurationCreateMutation.Field()
admin_configuration_update = AdminConfigurationUpdateMutation.Field()
admin_configuration_delete = AdminConfigurationDeleteMutation.Field()
request_to_delete_my_account = RequestToDeleteMyAccountMutation.Field()
1 change: 1 addition & 0 deletions accounts/schema/mutations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
from .confirm_consent_mutation import *
from .admin_place_mutations import *
from .admin_configuration_mutations import *
from .request_to_delete_my_account_mutation import *
17 changes: 17 additions & 0 deletions accounts/schema/mutations/request_to_delete_my_account_mutation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import graphene
from graphql_jwt.decorators import login_required


class RequestToDeleteMyAccountMutation(graphene.Mutation):
class Arguments:
pass

success = graphene.Boolean()

@staticmethod
@login_required
def mutate(root, info):
user = info.context.user
success = True

return RequestToDeleteMyAccountMutation(success=success)
2 changes: 2 additions & 0 deletions reports/schema/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ConvertToTestReportMutation,
SubmitZeroReportMutation,
SubmitIncidentReport,
EvaluateReportSimulation,
SubmitFollowupReport,
SubmitImage,
SubmitUploadFile,
Expand All @@ -30,6 +31,7 @@ class Mutation(graphene.ObjectType):
convert_to_test_report = ConvertToTestReportMutation.Field()
publish_report_type = PublishReportTypeMutation.Field()
unpublish_report_type = UnPublishReportTypeMutation.Field()
evaluate_report_simulation = EvaluateReportSimulation.Field()
admin_category_create = AdminCategoryCreateMutation.Field()
admin_category_update = AdminCategoryUpdateMutation.Field()
admin_category_delete = AdminCategoryDeleteMutation.Field()
Expand Down
1 change: 1 addition & 0 deletions reports/schema/mutations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .submit_image_mutation import *
from .submit_upload_file_mutation import *
from .submit_incident_report_mutation import *
from .evaluate_report_simulation_mutation import *
from .submit_zero_report_mutation import *
from .submit_followup_report_mutation import *
from .convert_to_test_report_mutation import *
Expand Down
96 changes: 96 additions & 0 deletions reports/schema/mutations/evaluate_report_simulation_mutation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
from datetime import datetime
from django.template import Context, Template
import graphene
from graphql_jwt.decorators import login_required
from graphene.types.generic import GenericScalar
from cases.models import CaseDefinition, NotificationTemplate
from common.eval import build_eval_obj, FormData

from reports.models.report import IncidentReport
from reports.models.report_type import ReportType
from reports.schema.types import SimulationReportType
from django.template.defaultfilters import striptags


class EvaluateReportSimulation(graphene.Mutation):
class Arguments:
data = GenericScalar(required=True)
report_type_id = graphene.UUID(required=False)
renderer_data_template = graphene.String(required=True)
incident_date = graphene.Date(required=True)
report_id = graphene.UUID(required=False)

result = graphene.Field(SimulationReportType)

@staticmethod
@login_required
def mutate(
root,
info,
data,
report_type_id,
renderer_data_template,
incident_date,
report_id,
):
renderer_data = ""
template = renderer_data_template
if template:
t = Template(template)
c = Context(
IncidentReport.build_data_context(data, report_id, incident_date)
)
renderer_data = striptags(t.render(c))

reporter_notifications = []
case_definitions = []
if report_type_id is not None:
report_type = ReportType.objects.get(pk=report_type_id)
eval_context = build_eval_obj(
{
"data": data,
"form_data": FormData(data),
"report_date": datetime.now(),
"incident_date": incident_date,
"renderer_data": renderer_data,
"report_id": report_id,
"report_type": {
"id": report_type.id,
"name": report_type.name,
"category": report_type.category,
},
}
)
for template in NotificationTemplate.objects.filter(
type=NotificationTemplate.Type.REPORT,
report_type=report_type,
):
if template.condition:
try:
if eval_context.eval(template.condition):
reporter_notifications.append(
{"id": template.id, "name": template.name}
)
except:
pass
else:
reporter_notifications.append(
{"id": template.id, "name": template.name}
)

for definition in CaseDefinition.objects.filter(report_type=report_type):
try:
if eval_context.eval(definition.condition):
case_definitions.append(
{"id": definition.id, "description": definition.description}
)
except:
pass

return EvaluateReportSimulation(
result={
"reporter_notifications": reporter_notifications,
"case_definitions": case_definitions,
"renderer_data": renderer_data,
}
)
16 changes: 16 additions & 0 deletions reports/schema/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,19 @@ class ReporterNoReport(graphene.ObjectType):

class ReportDataSummaryType(graphene.ObjectType):
result = graphene.String()


class SimulationCaseDefinitionType(graphene.ObjectType):
id = graphene.Int()
description = graphene.String()


class SimulationReporterNotificationType(graphene.ObjectType):
id = graphene.Int()
name = graphene.String()


class SimulationReportType(graphene.ObjectType):
reporter_notifications = graphene.List(SimulationReporterNotificationType)
case_definitions = graphene.List(SimulationCaseDefinitionType)
renderer_data = graphene.String()

0 comments on commit 252f7c6

Please sign in to comment.