Пример #1
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
Пример #2
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
Пример #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))
Пример #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))