-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from onehealthtoolkit/fix_issues
OSDAS-308 OSDAS-318 request to delete mutation form evaluate simulation
- Loading branch information
Showing
7 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
accounts/schema/mutations/request_to_delete_my_account_mutation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
reports/schema/mutations/evaluate_report_simulation_mutation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters