def randomization_rows(last_int: int, rows_to_add: int): rows = [] for country, sites in all_sites.items(): for site in sites: arm = "intervention" if is_intervention_site(site) else "control" n = int(f"{site.site_id}{last_int}") for i in range(1, rows_to_add + 1): n += 1 rows.append([n, arm, site.name, country]) return rows
def raise_if_intervention_site_without_icc_registration(): if is_intervention_site(): try: IntegratedCareClinicRegistration.objects.get( site_id=Site.objects.get_current()) except ObjectDoesNotExist: raise forms.ValidationError( "This is an intervention site. Complete the " f"`{IntegratedCareClinicRegistration._meta.verbose_name}` form first." )
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) icc_registration_outstanding = False if is_intervention_site(): try: IntegratedCareClinicRegistration.objects.get( site__id=settings.SITE_ID) except ObjectDoesNotExist: icc_registration_outstanding = True context.update( icc_registration_outstanding=icc_registration_outstanding, daily_closing_log_url=self.get_daily_closing_log_url(), ) return context
def clean(self): cleaned_data = super().clean() if not is_intervention_site(): raise forms.ValidationError( "Wait! This site is NOT an intervention site. Check randomization." ) if not self.instance.id: try: IntegratedCareClinicRegistration.objects.get( site=Site.objects.get_current()) except ObjectDoesNotExist: pass else: raise forms.ValidationError( "This form may only be completed once per facilty / site. " "Try `editing` the existing entry.") return cleaned_data
def save(self, *args, **kwargs): if not is_intervention_site(): raise Hba1cRegistrationManagerError( "Registration failed. This site is not included in this substudy. " "Perhaps catch this in the form validation.") super().save(*args, **kwargs)
def save(self, *args, **kwargs): if not is_intervention_site(): raise IntegratedCareClinicRegistrationError( "Registration failed. This is not an intervention site. " "Perhaps catch this in the form validation.") super().save(*args, **kwargs)
def test_is_not_intervention(self): self.assertFalse(is_intervention_site())
def test_is_intervention(self): self.assertTrue(is_intervention_site())