Exemple #1
0
 def setting_valid(self, term_service=None):
     #TODO remove this consistence when we finish implementing the terminologyService
     if term_service is not None:
         OPENEHR_TERMINOLOGY_NAME = TerminologyService()
         openehr_terminology = TerminologyService.terminology(OPENEHR_TERMINOLOGY_NAME,OPENEHR_TERMINOLOGY_NAME.TERMINOLOGY_ID)
         GROUP_ID_SETTING = TerminologyService.GROUP_ID_SETTING
         if not openehr_terminology.has_code_for_group_id(GROUP_ID_SETTING, self.setting.definingCode):
             raise AttributeError(u'setting must be in terminology service')
 def setUp(self):
     super(TerminologyServiceTestCase,self).setUp()
     self.unregister_all_terminologies_and_codesets()
     self.term_service = TerminologyService()
     grok_component('DummyOpenEHRTerminology',DummyOpenEHRTerminology)
     grok_component('LanguageCodeSetAccess',LanguageCodeSetAccess)
class TerminologyServiceTestCase(FunctionalTestCase):
    

    layer = FunctionalLayer


    def setUp(self):
        super(TerminologyServiceTestCase,self).setUp()
        self.unregister_all_terminologies_and_codesets()
        self.term_service = TerminologyService()
        grok_component('DummyOpenEHRTerminology',DummyOpenEHRTerminology)
        grok_component('LanguageCodeSetAccess',LanguageCodeSetAccess)

    def unregister_all_terminologies_and_codesets(self):
        gsm = getGlobalSiteManager()
        for utility in getAllUtilitiesRegisteredFor(ITerminologyAccess):
            gsm.unregisterUtility(utility)
        for utility in getAllUtilitiesRegisteredFor(ICodeSetAccess):
            gsm.unregisterUtility(utility)

    def test_validating_internal_codesets_and_openehr_terminology_group_ids(self):
        self.assertTrue(self.term_service.valid_code_set_id('languages'))
        self.assertFalse(self.term_service.valid_code_set_id('units'))
        self.assertTrue(self.term_service.valid_group_id('term mapping purpose'))
        self.assertFalse(self.term_service.valid_group_id('media types'))

    def test_if_has_a_codeset(self):
        self.assertTrue(self.term_service.has_code_set('languages'))
        self.assertFalse(self.term_service.has_code_set('ISO_0001'))

    def test_catch_a_codeset_access(self):
        language_code_set = self.term_service.code_set_for_id('languages')
        self.assertTrue(ICodeSetAccess.providedBy(language_code_set))
        self.assertRaises(ValueError,self.term_service.code_set_for_id,'ISO_639-1')
        self.assertRaises(ValueError,self.term_service.code_set,'countries')

    def test_get_all_openehr_codesets_and_their_internal_names(self):
        code_sets_names = self.term_service.openehr_code_sets()
        self.assertTrue(code_sets_names['languages'],'ISO_639-1')
        self.assertTrue(code_sets_names['countries'],'ISO_3611-1')

    def test_retrieve_a_codeset_using_a_external_name(self):
        iso_codeset = self.term_service.code_set('ISO_639-1')
        lang_codeset = self.term_service.code_set_for_id('languages')
        self.assertEquals(iso_codeset, lang_codeset)

    def test_getting_all_terminology_identifiers(self):
        term_ids = self.term_service.terminology_identifiers()
        self.assertTrue(isinstance(term_ids,list))
        self.assertTrue(len(term_ids)>1)

    def test_if_has_a_terminology(self):
        self.assertTrue(self.term_service.has_terminology('openehr'))
        self.assertFalse(self.term_service.has_terminology('SNOMED-CT'))

    def test_getting_a_terminology_access(self):
        term_access = self.term_service.terminology('openehr')
        self.assertTrue(ITerminologyAccess.providedBy(term_access))
        self.assertTrue(term_access.id,'openehr')
        self.assertRaises(ValueError,self.term_service.terminology,'UML123')