def setUp(self):
     oc_settings = OpenClinicaSettings(
         domain=DOMAIN,
         study=StudySettings(
             is_ws_enabled=False,
             metadata=TEST_METADATA
         )
     )
     oc_settings.save()
Exemple #2
0
 def setUp(self):
     oc_settings = OpenClinicaSettings(
         domain=DOMAIN,
         study=StudySettings(
             is_ws_enabled=False,
             metadata=TEST_METADATA
         )
     )
     oc_settings.save()
Exemple #3
0
    def _close(self):
        from custom.openclinica.models import OpenClinicaAPI, OpenClinicaSettings

        # Create the subjects and events that are in the ODM export using the API
        oc_settings = OpenClinicaSettings.for_domain(self.context['domain'])
        if oc_settings.study.is_ws_enabled:
            password = bz2.decompress(b64decode(oc_settings.study.password))
            api = OpenClinicaAPI(
                oc_settings.study.url,
                oc_settings.study.username,
                password,
                oc_settings.study.protocol_id
            )
            subject_keys = api.get_subject_keys()
            for subject in self.context['subjects']:
                if subject['subject_key'][3:] not in subject_keys:
                    # Skip 'SS_' prefix   ^^ that OpenClinica wants in ODM, but isn't in API's subject keys
                    api.create_subject(subject)
                    # NOTE: In the interests of keeping data in OpenClinica tidy, we are only scheduling events for
                    # subjects who don't yet exist in OpenClinica. New events of existing subjects must be added
                    # manually, or subjects must be deleted from OpenClinica before a re-import.
                    for event in subject['events']:
                        api.schedule_event(subject, event)

        self.file.write(render_to_string('couchexport/odm_export.xml', self.context))
Exemple #4
0
    def _close(self):
        from custom.openclinica.models import OpenClinicaAPI, OpenClinicaSettings

        # Create the subjects and events that are in the ODM export using the API
        oc_settings = OpenClinicaSettings.for_domain(self.context['domain'])
        if oc_settings.study.is_ws_enabled:
            password = bz2.decompress(b64decode(oc_settings.study.password))
            api = OpenClinicaAPI(
                oc_settings.study.url,
                oc_settings.study.username,
                password,
                oc_settings.study.protocol_id
            )
            subject_keys = api.get_subject_keys()
            for subject in self.context['subjects']:
                if subject['subject_key'][3:] not in subject_keys:
                    # Skip 'SS_' prefix   ^^ that OpenClinica wants in ODM, but isn't in API's subject keys
                    api.create_subject(subject)
                    # NOTE: In the interests of keeping data in OpenClinica tidy, we are only scheduling events for
                    # subjects who don't yet exist in OpenClinica. New events of existing subjects must be added
                    # manually, or subjects must be deleted from OpenClinica before a re-import.
                    for event in subject['events']:
                        api.schedule_event(subject, event)

        self.file.write(render_to_string('couchexport/odm_export.xml', self.context))
Exemple #5
0
def get_study_metadata_string(domain):
    """
    Return the study metadata for the given domain as a string

    Metadata is fetched from the OpenClinica web service
    """
    from custom.openclinica.models import OpenClinicaAPI, OpenClinicaSettings

    oc_settings = OpenClinicaSettings.for_domain(domain)
    if oc_settings.study.is_ws_enabled:
        password = bz2.decompress(b64decode(oc_settings.study.password))
        api = OpenClinicaAPI(
            oc_settings.study.url,
            oc_settings.study.username,
            password,
            oc_settings.study.protocol_id
        )
        string = api.get_study_metadata_string(oc_settings['STUDY'])
    else:
        string = oc_settings.study.metadata
    # If the XML is Unicode but it says that it's UTF-8, then make it UTF-8.
    if isinstance(string, unicode):
        match = re.match(r'<\?xml .*?encoding="([\w-]+)".*?\?>', string)  # Assumes no whitespace up front
        if match:
            string = string.encode(match.group(1))
    return string
Exemple #6
0
def get_study_metadata_string(domain):
    """
    Return the study metadata for the given domain as a string

    Metadata is fetched from the OpenClinica web service
    """
    from custom.openclinica.models import OpenClinicaAPI, OpenClinicaSettings

    oc_settings = OpenClinicaSettings.for_domain(domain)
    if oc_settings.study.is_ws_enabled:
        password = bz2.decompress(b64decode(oc_settings.study.password))
        api = OpenClinicaAPI(
            oc_settings.study.url,
            oc_settings.study.username,
            password,
            oc_settings.study.protocol_id
        )
        string = api.get_study_metadata_string(oc_settings['STUDY'])
    else:
        string = oc_settings.study.metadata
    # If the XML is Unicode but it says that it's UTF-8, then make it UTF-8.
    if isinstance(string, six.text_type):
        match = re.match(r'<\?xml .*?encoding="([\w-]+)".*?\?>', string)  # Assumes no whitespace up front
        if match:
            string = string.encode(match.group(1))
    return string
Exemple #7
0
 def save(self, domain):
     try:
         settings = OpenClinicaSettings.for_domain(domain.name)
         if settings is None:
             settings = OpenClinicaSettings(domain=domain.name)
         settings.study.is_ws_enabled = self.cleaned_data['is_ws_enabled']
         settings.study.url = self.cleaned_data['url']
         settings.study.username = self.cleaned_data['username']
         if self.cleaned_data['password']:
             # Simple symmetric encryption. We don't need it to be strong, considering we'd have to store the
             # algorithm and the key together anyway; it just shouldn't be plaintext.
             settings.study.password = b64encode(bz2.compress(self.cleaned_data['password']))
         settings.study.protocol_id = self.cleaned_data['protocol_id']
         settings.study.metadata = self.cleaned_data['metadata']
         settings.save()
         return True
     except Exception as err:
         logging.error('Unable to save OpenClinica settings: %s' % err)
         return False
Exemple #8
0
 def save(self, domain):
     try:
         settings = OpenClinicaSettings.for_domain(domain.name)
         if settings is None:
             settings = OpenClinicaSettings(domain=domain.name)
         settings.study.is_ws_enabled = self.cleaned_data['is_ws_enabled']
         settings.study.url = self.cleaned_data['url']
         settings.study.username = self.cleaned_data['username']
         if self.cleaned_data['password']:
             # Simple symmetric encryption. We don't need it to be strong, considering we'd have to store the
             # algorithm and the key together anyway; it just shouldn't be plaintext.
             settings.study.password = b64encode(bz2.compress(self.cleaned_data['password']))
         settings.study.protocol_id = self.cleaned_data['protocol_id']
         settings.study.metadata = self.cleaned_data['metadata']
         settings.save()
         return True
     except Exception as err:
         logging.error('Unable to save OpenClinica settings: %s' % err)
         return False
Exemple #9
0
def get_study_metadata_string(domain):
    """
    Return the study metadata for the given domain as an XML string
    """
    from custom.openclinica.models import OpenClinicaSettings

    oc_settings = OpenClinicaSettings.for_domain(domain)
    if oc_settings.study.is_ws_enabled:
        raise NotImplementedError('Fetching study metadata using web services is not yet available')
    else:
        string = oc_settings.study.metadata
    # If the XML is Unicode but it says that it's UTF-8, then make it UTF-8.
    if isinstance(string, unicode):
        match = re.match(r'<\?xml .*?encoding="([\w-]+)".*?\?>', string)  # Assumes no whitespace up front
        if match:
            string = string.encode(match.group(1))
    return string
Exemple #10
0
 def openclinica_settings_form(self):
     oc_settings = OpenClinicaSettings.for_domain(self.domain_object.name)
     initial = dict(oc_settings.study) if oc_settings else {}
     if self.request.method == 'POST':
         return OpenClinicaSettingsForm(self.request.POST, initial=initial)
     return OpenClinicaSettingsForm(initial=initial)
Exemple #11
0
 def openclinica_settings_form(self):
     oc_settings = OpenClinicaSettings.for_domain(self.domain_object.name)
     initial = dict(oc_settings.study) if oc_settings else {}
     if self.request.method == 'POST':
         return OpenClinicaSettingsForm(self.request.POST, initial=initial)
     return OpenClinicaSettingsForm(initial=initial)