Skip to content

Commit

Permalink
[ERP-916] Add parent email preference (#666)
Browse files Browse the repository at this point in the history
Co-authored-by: lexie <[email protected]>
  • Loading branch information
Lexiel46 and lexie authored Jan 8, 2024
1 parent 62f97b9 commit ca77193
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
10 changes: 8 additions & 2 deletions rdrf/report/report_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,14 @@ def get_patient_fields():

if EmailNotification.objects.has_subscribable_registry(all_registries):
demographic_model['demographic_model'].update({
'emailPreferences': {
'label': 'Email Preferences',
'patientEmailPreferences': {
'label': 'Patient Email Preferences',
'fields': {
'unsubscribeAll': 'Unsubscribe All'
}
},
'parentEmailPreferences': {
'label': 'Parent Email Preferences',
'fields': {
'unsubscribeAll': 'Unsubscribe All'
}
Expand Down
13 changes: 10 additions & 3 deletions rdrf/report/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,14 @@ def clinical_data_resolver(patient, _info):
collection="cdes"
).order_by('created_at').all()

def email_preferences_resolver(patient, _info):
def patient_email_preferences_resolver(patient, _info):
return EmailPreference.objects.get_by_user(patient.user)

def parent_email_preferences_resolver(patient, _info):
parent = ParentGuardian.objects.filter(patient=patient).first()

return None if parent is None else EmailPreference.objects.get_by_user(parent.user)

schema_module = import_module(settings.SCHEMA_MODULE)
patient_fields_func = getattr(schema_module, settings.SCHEMA_METHOD_PATIENT_FIELDS)
patient_fields = patient_fields_func()
Expand Down Expand Up @@ -513,8 +518,10 @@ def email_preferences_resolver(patient, _info):
})

patient_fields.update({
"email_preferences": graphene.Field(EmailPreferencesType),
"resolve_email_preferences": email_preferences_resolver,
"patient_email_preferences": graphene.Field(EmailPreferencesType),
"resolve_patient_email_preferences": patient_email_preferences_resolver,
"parent_email_preferences": graphene.Field(EmailPreferencesType),
"resolve_parent_email_preferences": parent_email_preferences_resolver,
})

return type(f"DynamicPatient_{registry.code}", (DjangoObjectType,), patient_fields)
Expand Down

0 comments on commit ca77193

Please sign in to comment.