예제 #1
0
    def handle(self, *args, **options):
        haystack.signal_processor = haystack.signals.BaseSignalProcessor

        user = User.objects.filter(username='******').get()

        org = self.create_organization(user)

        sources = self.create_sources(org, user)

        importer_confs = [
            {'source': sources['Classes'], 'file': "./concept_classes.json"},
            {'source': sources['Locales'], 'file': "./locales.json"},
            {'source': sources['Datatypes'], 'file': "./datatypes_fixed.json"},
            {'source': sources['NameTypes'], 'file': "./nametypes_fixed.json"},
            {'source': sources['DescriptionTypes'], 'file': "./description_types.json"},
            {'source': sources['MapTypes'], 'file': "./maptypes_fixed.json"}
        ]

        update_index_required = False

        for conf in importer_confs:
            file = open(conf['file'], 'rb')
            source = conf['source']

            importer = ConceptsImporter(source, file, user, OutputWrapper(sys.stdout), OutputWrapper(sys.stderr), save_validation_errors=False)
            importer.import_concepts(**options)

            actions = importer.action_count
            update_index_required |= actions.get(ImportActionHelper.IMPORT_ACTION_ADD, 0) > 0
            update_index_required |= actions.get(ImportActionHelper.IMPORT_ACTION_UPDATE, 0) > 0

        if update_index_required:
            update_index.Command().handle(age=1, workers=4)
예제 #2
0
    def test_import_job_for_change_in_data(self):
        stdout_stub = TestStream()
        concept = Concept(
            mnemonic='1',
            created_by=self.user1,
            updated_by=self.user1,
            parent=self.source1,
            concept_class='Diagnosis',
            external_id='1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
            names=[self.name])
        kwargs = {
            'parent_resource': self.source1,
        }
        Concept.persist_new(concept, self.user1, **kwargs)

        importer = ConceptsImporter(self.source1, self.testfile, 'test', stdout_stub, TestStream())
        importer.import_concepts(total=1)
        all_concept_versions = ConceptVersion.objects.all()
        self.assertEquals(len(all_concept_versions), 2)

        latest_concept_version = [version for version in all_concept_versions if version.previous_version][0]

        self.assertEquals(len(latest_concept_version.names), 4)
        self.assertTrue((
                        'Updated concept, replacing version ID ' + latest_concept_version.previous_version.id) in stdout_stub.getvalue())
        self.assertTrue('concepts of 1 1 - 1 updated' in stdout_stub.getvalue())
예제 #3
0
    def test_import_concepts_into_openmrs_validated_source_with_valid_records(
            self):
        test_file = open(
            './integration_tests/fixtures/concepts_for_openmrs_validation.json',
            'rb')
        stderr_stub = TestStream()
        user = create_user()
        source = create_source(
            user, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)

        importer = ConceptsImporter(source, test_file, 'test', TestStream(),
                                    stderr_stub)
        importer.import_concepts(total=5)

        self.assertTrue(
            "Custom validation rules require a concept to have exactly one preferred name"
            in stderr_stub.getvalue())
        self.assertTrue(
            "Custom validation rules require a preferred name to be different than a short name"
            in stderr_stub.getvalue())
        self.assertTrue(
            "Custom validation rules require a preferred name not to be an index/search term"
            in stderr_stub.getvalue())
        self.assertTrue(
            "Custom validation rules require all names except type=SHORT to be unique"
            in stderr_stub.getvalue())

        self.assertEquals(
            2,
            Concept.objects.exclude(concept_class='Concept Class').count())
        self.assertEquals(
            2,
            ConceptVersion.objects.exclude(
                concept_class='Concept Class').count())
예제 #4
0
    def test_import_concepts_into_openmrs_validated_source_with_valid_records(
            self):
        test_file = open(
            './integration_tests/fixtures/concepts_for_openmrs_validation.json',
            'rb')
        stderr_stub = TestStream()
        user = create_user()
        source = create_source(
            user, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)

        importer = ConceptsImporter(source,
                                    test_file,
                                    'test',
                                    TestStream(),
                                    stderr_stub,
                                    save_validation_errors=False)
        importer.import_concepts(total=5)

        self.assertTrue(OPENMRS_MUST_HAVE_EXACTLY_ONE_PREFERRED_NAME in
                        stderr_stub.getvalue())
        self.assertTrue(
            OPENMRS_SHORT_NAME_CANNOT_BE_PREFERRED in stderr_stub.getvalue())
        self.assertTrue(
            OPENMRS_SHORT_NAME_CANNOT_BE_PREFERRED in stderr_stub.getvalue())
        self.assertTrue(OPENMRS_NAMES_EXCEPT_SHORT_MUST_BE_UNIQUE in
                        stderr_stub.getvalue())

        self.assertEquals(
            2,
            Concept.objects.exclude(
                concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
        self.assertEquals(
            2,
            ConceptVersion.objects.exclude(
                concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
예제 #5
0
    def test_import_job_for_change_in_data(self):
        stdout_stub = TestStream()
        concept = Concept(mnemonic='1',
                          created_by=self.user1,
                          updated_by=self.user1,
                          parent=self.source1,
                          concept_class='Diagnosis',
                          external_id='1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
                          names=[self.name])
        kwargs = {
            'parent_resource': self.source1,
        }
        Concept.persist_new(concept, self.user1, **kwargs)

        importer = ConceptsImporter(self.source1, self.testfile, 'test',
                                    stdout_stub, TestStream())
        importer.import_concepts(total=1)
        all_concept_versions = ConceptVersion.objects.all()
        self.assertEquals(len(all_concept_versions), 2)

        latest_concept_version = [
            version for version in all_concept_versions
            if version.previous_version
        ][0]

        self.assertEquals(len(latest_concept_version.names), 4)
        self.assertTrue(('Updated concept, replacing version ID ' +
                         latest_concept_version.previous_version.id
                         ) in stdout_stub.getvalue())
        self.assertTrue(
            'concepts of 1 1 - 1 updated' in stdout_stub.getvalue())
예제 #6
0
    def test_import_job_for_change_in_data(self):
        stdout_stub = TestStream()
        create_concept(mnemonic='1', user=self.user1, source=self.source1)

        importer = ConceptsImporter(self.source1,
                                    self.testfile,
                                    'test',
                                    stdout_stub,
                                    TestStream(),
                                    save_validation_errors=False)
        importer.import_concepts(total=1)
        all_concept_versions = ConceptVersion.objects.exclude(
            concept_class__in=LOOKUP_CONCEPT_CLASSES)
        self.assertEquals(len(all_concept_versions), 2)

        latest_concept_version = [
            version for version in all_concept_versions
            if version.previous_version
        ][0]

        self.assertEquals(len(latest_concept_version.names), 4)

        self.assertTrue(('Updated concept, replacing version ID ' +
                         latest_concept_version.previous_version.id
                         ) in stdout_stub.getvalue())
        self.assertTrue('**** Processed 1 out of 1 concepts - 1 updated, ****'
                        in stdout_stub.getvalue())
예제 #7
0
 def test_import_concepts_with_invalid_records(self):
     self.testfile = open(
         './integration_tests/fixtures/valid_invalid_concepts.json', 'rb')
     stderr_stub = TestStream()
     source = create_source(
         self.user1, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)
     importer = ConceptsImporter(source,
                                 self.testfile,
                                 'test',
                                 TestStream(),
                                 stderr_stub,
                                 save_validation_errors=False)
     importer.import_concepts(total=7)
     self.assertTrue(OPENMRS_AT_LEAST_ONE_FULLY_SPECIFIED_NAME in
                     stderr_stub.getvalue())
     self.assertTrue(OPENMRS_FULLY_SPECIFIED_NAME_UNIQUE_PER_SOURCE_LOCALE
                     in stderr_stub.getvalue())
     self.assertEquals(
         5,
         Concept.objects.exclude(
             concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
     self.assertEquals(
         5,
         ConceptVersion.objects.exclude(
             concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
 def test_import_single_concept_without_fully_specified_name(self):
     self.testfile = open('./integration_tests/fixtures/concept_without_fully_specified_name.json', 'rb')
     stderr_stub = TestStream()
     source = create_source(self.user1, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)
     importer = ConceptsImporter(source, self.testfile, 'test', TestStream(), stderr_stub, save_validation_errors=False)
     importer.import_concepts(total=1)
     self.assertTrue(OPENMRS_AT_LEAST_ONE_FULLY_SPECIFIED_NAME in stderr_stub.getvalue())
예제 #9
0
    def handle(self, *args, **options):
        user = User.objects.filter(username='******').get()

        org = self.create_organization(user)

        sources = self.create_sources(org, user)

        importer_confs = [{
            'source': sources['Classes'],
            'file': "./concept_classes.json"
        }, {
            'source': sources['Locales'],
            'file': "./locales.json"
        }, {
            'source': sources['Datatypes'],
            'file': "./datatypes_fixed.json"
        }, {
            'source': sources['NameTypes'],
            'file': "./nametypes_fixed.json"
        }, {
            'source': sources['DescriptionTypes'],
            'file': "./description_types.json"
        }]

        for conf in importer_confs:
            file = open(conf['file'], 'rb')
            source = conf['source']

            importer = ConceptsImporter(source, file, user,
                                        OutputWrapper(sys.stdout),
                                        OutputWrapper(sys.stderr))
            importer.import_concepts(**options)
예제 #10
0
    def test_update_concept_with_invalid_record(self):
        (concept, _) = create_concept(mnemonic='1',
                                      user=self.user1,
                                      source=self.source1,
                                      names=[self.name])

        self.testfile = open(
            './integration_tests/fixtures/concept_without_fully_specified_name.json',
            'rb')
        stderr_stub = TestStream()
        source = create_source(
            self.user1, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)
        importer = ConceptsImporter(source,
                                    self.testfile,
                                    'test',
                                    TestStream(),
                                    stderr_stub,
                                    save_validation_errors=False)
        importer.import_concepts(total=1)
        self.assertTrue(OPENMRS_AT_LEAST_ONE_FULLY_SPECIFIED_NAME in
                        stderr_stub.getvalue())
        self.assertEquals(
            1,
            Concept.objects.exclude(
                concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
        self.assertEquals(
            1,
            ConceptVersion.objects.exclude(
                concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
 def do_import(self, user, source, input_file, options):
     """ Performs the import of JSON lines concept file into OCL """
     validation_logger = None
     output_file_name = options.get('error_output_file', False)
     if output_file_name:
         validation_logger = ValidationLogger(output_file_name=output_file_name)
     importer = ConceptsImporter(source, input_file, user, self.stdout, self.stderr, validation_logger=validation_logger)
     importer.import_concepts(**options)
예제 #12
0
 def test_import_concepts_with_invalid_records(self):
     self.testfile = open('./integration_tests/fixtures/valid_invalid_concepts.json', 'rb')
     stderr_stub = TestStream()
     importer = ConceptsImporter(self.source1, self.testfile, 'test', TestStream(), stderr_stub)
     importer.import_concepts(total=7)
     self.assertTrue('Concept requires at least one fully specified name' in stderr_stub.getvalue())
     self.assertTrue('Concept preferred name must be unique for same source and locale' in stderr_stub.getvalue())
     self.assertEquals(5, Concept.objects.count())
     self.assertEquals(5, ConceptVersion.objects.count())
예제 #13
0
 def test_import_single_concept_without_fully_specified_name(self):
     self.testfile = open(
         './integration_tests/fixtures/concept_without_fully_specified_name.json',
         'rb')
     stderr_stub = TestStream()
     importer = ConceptsImporter(self.source1, self.testfile, 'test',
                                 TestStream(), stderr_stub)
     importer.import_concepts(total=1)
     self.assertTrue('Concept requires at least one fully specified name' in
                     stderr_stub.getvalue())
 def test_import_concepts_with_invalid_records(self):
     self.testfile = open('./integration_tests/fixtures/valid_invalid_concepts.json', 'rb')
     stderr_stub = TestStream()
     source = create_source(self.user1, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)
     importer = ConceptsImporter(source, self.testfile, 'test', TestStream(), stderr_stub, save_validation_errors=False)
     importer.import_concepts(total=7)
     self.assertTrue(OPENMRS_AT_LEAST_ONE_FULLY_SPECIFIED_NAME in stderr_stub.getvalue())
     self.assertTrue(OPENMRS_FULLY_SPECIFIED_NAME_UNIQUE_PER_SOURCE_LOCALE in stderr_stub.getvalue())
     self.assertEquals(5, Concept.objects.exclude(concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
     self.assertEquals(5, ConceptVersion.objects.exclude(concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
예제 #15
0
 def test_import_single_concept_without_fully_specified_name(self):
     self.testfile = open(
         './integration_tests/fixtures/concept_without_fully_specified_name.json',
         'rb')
     stderr_stub = TestStream()
     importer = ConceptsImporter(self.source1, self.testfile, 'test',
                                 TestStream(), stderr_stub)
     importer.import_concepts(total=1)
     self.assertTrue(
         BASIC_AT_LEAST_ONE_FULLY_SPECIFIED_NAME in stderr_stub.getvalue())
    def test_update_concept_with_invalid_record(self):
        (concept, _) = create_concept(mnemonic='1', user=self.user1, source=self.source1, names=[self.name])

        self.testfile = open('./integration_tests/fixtures/concept_without_fully_specified_name.json', 'rb')
        stderr_stub = TestStream()
        source = create_source(self.user1, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)
        importer = ConceptsImporter(source, self.testfile, 'test', TestStream(), stderr_stub, save_validation_errors=False)
        importer.import_concepts(total=1)
        self.assertTrue(OPENMRS_AT_LEAST_ONE_FULLY_SPECIFIED_NAME in stderr_stub.getvalue())
        self.assertEquals(1, Concept.objects.exclude(concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
        self.assertEquals(1, ConceptVersion.objects.exclude(concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
예제 #17
0
    def test_import_job_for_one_record(self):
        stdout_stub = TestStream()
        importer = ConceptsImporter(self.source1, self.testfile, 'test', stdout_stub, TestStream())
        importer.import_concepts(total=1)
        self.assertTrue('Created new concept: 1 = Diagnosis' in stdout_stub.getvalue())
        self.assertTrue('Finished importing concepts!' in stdout_stub.getvalue())
        inserted_concept = Concept.objects.get(mnemonic='1')
        self.assertEquals(inserted_concept.parent, self.source1)
        inserted_concept_version = ConceptVersion.objects.get(versioned_object_id=inserted_concept.id)
        source_version_latest = SourceVersion.get_latest_version_of(self.source1)

        self.assertEquals(source_version_latest.concepts, [inserted_concept_version.id])
예제 #18
0
    def test_validation_error_file_output(self):
        self.testfile = open("./integration_tests/fixtures/valid_invalid_concepts.json", "rb")
        stderr_stub = TestStream()

        logger = ValidationLogger(output=TestStream())
        source = create_source(self.user1, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)

        importer = ConceptsImporter(source, self.testfile, "test", TestStream(), stderr_stub, validation_logger=logger)
        importer.import_concepts(total=7)

        self.assertTrue("MNEMONIC;ERROR;JSON" in logger.output.getvalue())
        self.assertTrue("4;%s" % OPENMRS_AT_LEAST_ONE_FULLY_SPECIFIED_NAME in logger.output.getvalue())
        self.assertTrue("7;%s" % OPENMRS_FULLY_SPECIFIED_NAME_UNIQUE_PER_SOURCE_LOCALE in logger.output.getvalue())
    def test_validation_error_file_exists(self):
        self.testfile = open('./integration_tests/fixtures/valid_invalid_concepts.json', 'rb')
        stderr_stub = TestStream()

        output_file_name = 'test_file.csv'
        logger = ValidationLogger(output_file_name=output_file_name)

        importer = ConceptsImporter(create_source(user=self.user1, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS), self.testfile, 'test', TestStream(), stderr_stub,
                                    validation_logger=logger)
        importer.import_concepts(total=7)
        from os import path, remove
        self.assertTrue(path.exists(output_file_name))
        remove(output_file_name)
예제 #20
0
    def handle(self, *args, **options):
        user = self.create_admin_user()

        org = self.create_organization(user, 'CIEL')

        source = self.create_source(user, org, 'CIEL')

        demo_file = open('./demo-data/ciel_20180601_concepts_2k.json', 'rb')
        importer = ConceptsImporter(source, demo_file, user, OutputWrapper(sys.stdout), OutputWrapper(sys.stderr), save_validation_errors=False)
        importer.import_concepts(**options)

        demo_file = open('./demo-data/ciel_20180601_mappings_2k.json', 'rb')
        importer = MappingsImporter(source, demo_file, OutputWrapper(sys.stdout), OutputWrapper(sys.stderr), user)
        importer.import_mappings(**options)
예제 #21
0
 def test_import_concepts_with_invalid_records(self):
     self.testfile = open(
         './integration_tests/fixtures/valid_invalid_concepts.json', 'rb')
     stderr_stub = TestStream()
     importer = ConceptsImporter(self.source1, self.testfile, 'test',
                                 TestStream(), stderr_stub)
     importer.import_concepts(total=7)
     self.assertTrue('Concept requires at least one fully specified name' in
                     stderr_stub.getvalue())
     self.assertTrue(
         'Concept preferred name should be unique for same source and locale'
         in stderr_stub.getvalue())
     self.assertEquals(5, Concept.objects.count())
     self.assertEquals(5, ConceptVersion.objects.count())
예제 #22
0
 def do_import(self, user, source, input_file, options):
     """ Performs the import of JSON lines concept file into OCL """
     validation_logger = None
     output_file_name = options.get('error_output_file', False)
     if output_file_name:
         validation_logger = ValidationLogger(
             output_file_name=output_file_name)
     importer = ConceptsImporter(source,
                                 input_file,
                                 user,
                                 self.stdout,
                                 self.stderr,
                                 validation_logger=validation_logger)
     importer.import_concepts(**options)
    def test_import_job_for_change_in_data(self):
        stdout_stub = TestStream()
        create_concept(mnemonic='1', user=self.user1, source=self.source1)

        importer = ConceptsImporter(self.source1, self.testfile, 'test', stdout_stub, TestStream(), save_validation_errors=False)
        importer.import_concepts(total=1)
        all_concept_versions = ConceptVersion.objects.exclude(concept_class__in=LOOKUP_CONCEPT_CLASSES)
        self.assertEquals(len(all_concept_versions), 2)

        latest_concept_version = [version for version in all_concept_versions if version.previous_version][0]

        self.assertEquals(len(latest_concept_version.names), 4)

        self.assertTrue(('Updated concept, replacing version ID ' + latest_concept_version.previous_version.id) in stdout_stub.getvalue())
        self.assertTrue('**** Processed 1 out of 1 concepts - 1 updated, ****' in stdout_stub.getvalue())
예제 #24
0
    def test_import_concepts_into_openmrs_validated_source_with_valid_records(self):
        test_file = open('./integration_tests/fixtures/concepts_for_openmrs_validation.json', 'rb')
        stderr_stub = TestStream()
        user = create_user()
        source = create_source(user, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)

        importer = ConceptsImporter(source, test_file, 'test', TestStream(), stderr_stub)
        importer.import_concepts(total=5)

        self.assertTrue("Custom validation rules require a concept to have exactly one preferred name" in stderr_stub.getvalue())
        self.assertTrue("Custom validation rules require a preferred name to be different than a short name" in stderr_stub.getvalue())
        self.assertTrue("Custom validation rules require a preferred name not to be an index/search term" in stderr_stub.getvalue())
        self.assertTrue("Custom validation rules require all names except type=SHORT to be unique" in stderr_stub.getvalue())

        self.assertEquals(2, Concept.objects.count())
        self.assertEquals(2, ConceptVersion.objects.count())
예제 #25
0
    def test_import_concepts_into_openmrs_validated_source_with_valid_records(self):
        test_file = open("./integration_tests/fixtures/concepts_for_openmrs_validation.json", "rb")
        stderr_stub = TestStream()
        user = create_user()
        source = create_source(user, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)

        importer = ConceptsImporter(source, test_file, "test", TestStream(), stderr_stub, save_validation_errors=False)
        importer.import_concepts(total=5)

        self.assertTrue(OPENMRS_MUST_HAVE_EXACTLY_ONE_PREFERRED_NAME in stderr_stub.getvalue())
        self.assertTrue(OPENMRS_SHORT_NAME_CANNOT_BE_PREFERRED in stderr_stub.getvalue())
        self.assertTrue(OPENMRS_SHORT_NAME_CANNOT_BE_PREFERRED in stderr_stub.getvalue())
        self.assertTrue(OPENMRS_NAMES_EXCEPT_SHORT_MUST_BE_UNIQUE in stderr_stub.getvalue())

        self.assertEquals(2, Concept.objects.exclude(concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
        self.assertEquals(2, ConceptVersion.objects.exclude(concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
예제 #26
0
 def test_import_single_concept_without_fully_specified_name(self):
     self.testfile = open(
         './integration_tests/fixtures/concept_without_fully_specified_name.json',
         'rb')
     stderr_stub = TestStream()
     source = create_source(
         self.user1, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)
     importer = ConceptsImporter(source,
                                 self.testfile,
                                 'test',
                                 TestStream(),
                                 stderr_stub,
                                 save_validation_errors=False)
     importer.import_concepts(total=1)
     self.assertTrue(OPENMRS_AT_LEAST_ONE_FULLY_SPECIFIED_NAME in
                     stderr_stub.getvalue())
예제 #27
0
    def test_import_job_for_one_record(self):
        stdout_stub = TestStream()
        importer = ConceptsImporter(self.source1, self.testfile, 'test',
                                    stdout_stub, TestStream())
        importer.import_concepts(total=1)
        self.assertTrue(
            'Created new concept: 1 = Diagnosis' in stdout_stub.getvalue())
        self.assertTrue(
            'Finished importing concepts!' in stdout_stub.getvalue())
        inserted_concept = Concept.objects.get(mnemonic='1')
        self.assertEquals(inserted_concept.parent, self.source1)
        inserted_concept_version = ConceptVersion.objects.get(
            versioned_object_id=inserted_concept.id)
        source_version_latest = SourceVersion.get_latest_version_of(
            self.source1)

        self.assertEquals(source_version_latest.concepts,
                          [inserted_concept_version.id])
예제 #28
0
 def test_import_concepts_with_invalid_records(self):
     self.testfile = open(
         './integration_tests/fixtures/valid_invalid_concepts.json', 'rb')
     stderr_stub = TestStream()
     importer = ConceptsImporter(self.source1, self.testfile, 'test',
                                 TestStream(), stderr_stub)
     importer.import_concepts(total=7)
     self.assertTrue(
         BASIC_AT_LEAST_ONE_FULLY_SPECIFIED_NAME in stderr_stub.getvalue())
     self.assertTrue(BASIC_PREFERRED_NAME_UNIQUE_PER_SOURCE_LOCALE in
                     stderr_stub.getvalue())
     self.assertEquals(
         5,
         Concept.objects.exclude(
             concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
     self.assertEquals(
         5,
         ConceptVersion.objects.exclude(
             concept_class__in=LOOKUP_CONCEPT_CLASSES).count())
예제 #29
0
 def test_update_concept_with_invalid_record(self):
     concept = Concept(
         mnemonic='1',
         created_by=self.user1,
         updated_by=self.user1,
         parent=self.source1,
         concept_class='Diagnosis',
         external_id='1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
         names=[self.name])
     kwargs = {
         'parent_resource': self.source1,
     }
     Concept.persist_new(concept, self.user1, **kwargs)
     self.testfile = open('./integration_tests/fixtures/concept_without_fully_specified_name.json', 'rb')
     stderr_stub = TestStream()
     importer = ConceptsImporter(self.source1, self.testfile, 'test', TestStream(), stderr_stub)
     importer.import_concepts(total=1)
     self.assertTrue('Concept requires at least one fully specified name' in stderr_stub.getvalue())
     self.assertEquals(1, Concept.objects.count())
     self.assertEquals(1, ConceptVersion.objects.count())
예제 #30
0
    def test_validation_error_file_exists(self):
        self.testfile = open(
            './integration_tests/fixtures/valid_invalid_concepts.json', 'rb')
        stderr_stub = TestStream()

        output_file_name = 'test_file.csv'
        logger = ValidationLogger(output_file_name=output_file_name)

        importer = ConceptsImporter(create_source(
            user=self.user1,
            validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS),
                                    self.testfile,
                                    'test',
                                    TestStream(),
                                    stderr_stub,
                                    validation_logger=logger)
        importer.import_concepts(total=7)
        from os import path, remove
        self.assertTrue(path.exists(output_file_name))
        remove(output_file_name)
예제 #31
0
    def handle(self, *args, **options):
        user = User.objects.filter(username='******').get()

        org = self.create_organization(user)

        sources = self.create_sources(org, user)

        importer_confs = [
            {'source': sources['Classes'], 'file': "./concept_classes.json"},
            {'source': sources['Locales'], 'file': "./locales.json"},
            {'source': sources['Datatypes'], 'file': "./datatypes_fixed.json"},
            {'source': sources['NameTypes'], 'file': "./nametypes_fixed.json"},
            {'source': sources['DescriptionTypes'], 'file': "./description_types.json"}
        ]

        for conf in importer_confs:
            file = open(conf['file'], 'rb')
            source = conf['source']

            importer = ConceptsImporter(source, file, user, OutputWrapper(sys.stdout), OutputWrapper(sys.stderr))
            importer.import_concepts(**options)
예제 #32
0
    def handle(self, *args, **options):
        user = User.objects.filter(username='******').get()

        org = self.create_organization(user, 'CIEL')

        source = self.create_source(user, org, 'CIEL')

        demo_file = open('./demo-data/ciel_20180601_concepts_2k.json', 'rb')
        importer = ConceptsImporter(source,
                                    demo_file,
                                    user,
                                    OutputWrapper(sys.stdout),
                                    OutputWrapper(sys.stderr),
                                    save_validation_errors=False)
        importer.import_concepts(**options)

        demo_file = open('./demo-data/ciel_20180601_mappings_2k.json', 'rb')
        importer = MappingsImporter(source, demo_file,
                                    OutputWrapper(sys.stdout),
                                    OutputWrapper(sys.stderr), user)
        importer.import_mappings(**options)
예제 #33
0
    def test_import_job_for_change_in_data(self):
        stdout_stub = TestStream()
        create_concept(mnemonic='1', user=self.user1, source=self.source1)

        importer = ConceptsImporter(self.source1, self.testfile, 'test',
                                    stdout_stub, TestStream())
        importer.import_concepts(total=1)
        all_concept_versions = ConceptVersion.objects.exclude(
            concept_class='Concept Class')
        self.assertEquals(len(all_concept_versions), 2)

        latest_concept_version = [
            version for version in all_concept_versions
            if version.previous_version
        ][0]

        self.assertEquals(len(latest_concept_version.names), 4)
        self.assertTrue(('Updated concept, replacing version ID ' +
                         latest_concept_version.previous_version.id
                         ) in stdout_stub.getvalue())
        self.assertTrue(
            'concepts of 1 1 - 1 updated' in stdout_stub.getvalue())
예제 #34
0
    def test_update_concept_with_invalid_record(self):
        (concept, _) = create_concept(mnemonic='1',
                                      user=self.user1,
                                      source=self.source1,
                                      names=[self.name])

        self.testfile = open(
            './integration_tests/fixtures/concept_without_fully_specified_name.json',
            'rb')
        stderr_stub = TestStream()
        importer = ConceptsImporter(self.source1, self.testfile, 'test',
                                    TestStream(), stderr_stub)
        importer.import_concepts(total=1)
        self.assertTrue('Concept requires at least one fully specified name' in
                        stderr_stub.getvalue())
        self.assertEquals(
            1,
            Concept.objects.exclude(concept_class='Concept Class').count())
        self.assertEquals(
            1,
            ConceptVersion.objects.exclude(
                concept_class='Concept Class').count())
예제 #35
0
 def test_update_concept_with_invalid_record(self):
     concept = Concept(mnemonic='1',
                       created_by=self.user1,
                       updated_by=self.user1,
                       parent=self.source1,
                       concept_class='Diagnosis',
                       external_id='1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
                       names=[self.name])
     kwargs = {
         'parent_resource': self.source1,
     }
     Concept.persist_new(concept, self.user1, **kwargs)
     self.testfile = open(
         './integration_tests/fixtures/concept_without_fully_specified_name.json',
         'rb')
     stderr_stub = TestStream()
     importer = ConceptsImporter(self.source1, self.testfile, 'test',
                                 TestStream(), stderr_stub)
     importer.import_concepts(total=1)
     self.assertTrue('Concept requires at least one fully specified name' in
                     stderr_stub.getvalue())
     self.assertEquals(1, Concept.objects.count())
     self.assertEquals(1, ConceptVersion.objects.count())
예제 #36
0
    def test_validation_error_file_output(self):
        self.testfile = open(
            './integration_tests/fixtures/valid_invalid_concepts.json', 'rb')
        stderr_stub = TestStream()

        logger = ValidationLogger(output=TestStream())
        source = create_source(
            self.user1, validation_schema=CUSTOM_VALIDATION_SCHEMA_OPENMRS)

        importer = ConceptsImporter(source,
                                    self.testfile,
                                    'test',
                                    TestStream(),
                                    stderr_stub,
                                    validation_logger=logger)
        importer.import_concepts(total=7)

        self.assertTrue('MNEMONIC;ERROR;JSON' in logger.output.getvalue())
        self.assertTrue('4;%s' % OPENMRS_AT_LEAST_ONE_FULLY_SPECIFIED_NAME in
                        logger.output.getvalue())
        self.assertTrue('7;%s' %
                        OPENMRS_FULLY_SPECIFIED_NAME_UNIQUE_PER_SOURCE_LOCALE
                        in logger.output.getvalue())
예제 #37
0
    def handle(self, *args, **options):
        user = self.create_admin_user()

        version = 'v2019-07-01'

        source_version = SourceVersion.objects.filter(mnemonic=version)
        if source_version.exists():
            return

        org = self.create_organization(user, 'CIEL')

        source = self.create_source(user, org, 'CIEL')

        demo_file = open('./demo-data/ciel_' + version + '_c2k.json', 'rb')
        importer = ConceptsImporter(source,
                                    demo_file,
                                    user,
                                    OutputWrapper(sys.stdout),
                                    OutputWrapper(sys.stderr),
                                    save_validation_errors=False)
        importer.import_concepts(**options)

        demo_file = open('./demo-data/ciel_' + version + '_m2k.json', 'rb')
        importer = MappingsImporter(source, demo_file,
                                    OutputWrapper(sys.stdout),
                                    OutputWrapper(sys.stderr), user)
        importer.import_mappings(**options)

        new_version = SourceVersion.for_base_object(source,
                                                    version,
                                                    released=True)
        SourceVersion.persist_new(new_version,
                                  versioned_object=source,
                                  force_insert=True)
        update_children_for_resource_version.delay(new_version.id, 'source')

        export_source.delay(new_version.id)
 def do_import(self, user, source, input_file, options):
     """ Performs the import of JSON lines concept file into OCL """
     importer = ConceptsImporter(source, input_file, user, self.stdout,
                                 self.stderr)
     importer.import_concepts(**options)
 def do_import(self, user, source, input_file, options):
     """ Performs the import of JSON lines concept file into OCL """
     importer = ConceptsImporter(source, input_file, user, self.stdout, self.stderr)
     importer.import_concepts(**options)
예제 #40
0
 def test_import_single_concept_without_fully_specified_name(self):
     self.testfile = open('./integration_tests/fixtures/concept_without_fully_specified_name.json', 'rb')
     stderr_stub = TestStream()
     importer = ConceptsImporter(self.source1, self.testfile, 'test', TestStream(), stderr_stub)
     importer.import_concepts(total=1)
     self.assertTrue('Concept requires at least one fully specified name' in stderr_stub.getvalue())