@@ -0,0 +1,3313 @@
+package org.opencb.opencga.app.migrations.v2_2_0.catalog;%0A%0Aimport com.mongodb.client.model.Projections;%0Aimport com.mongodb.client.model.UpdateOneModel;%0Aimport org.apache.commons.lang3.StringUtils;%0Aimport org.bson.Document;%0Aimport org.opencb.opencga.catalog.db.mongodb.MongoDBAdaptorFactory;%0Aimport org.opencb.opencga.catalog.migration.Migration;%0Aimport org.opencb.opencga.catalog.migration.MigrationTool;%0A%0Aimport java.util.Collections;%0Aimport java.util.List;%0A%0Aimport static com.mongodb.client.model.Filters.eq;%0A%0A@Migration(id = %22add_clinical_variant_evidence_review%22,%0A        description = %22Add new ClinicalVariantEvidenceReview object, #1874%22, version = %222.2.0%22,%0A        language = Migration.MigrationLanguage.JAVA,%0A        domain = Migration.MigrationDomain.CATALOG,%0A        date = 20220112)%0Apublic class ClinicalVariantEvidenceMigration extends MigrationTool %7B%0A%0A    public ClinicalVariantEvidenceMigration() %7B%0A        super(1);%0A    %7D%0A%0A    @Override%0A    protected void run() throws Exception %7B%0A        migrateCollection(MongoDBAdaptorFactory.INTERPRETATION_COLLECTION,%0A                new Document(),%0A                Projections.include(%22_id%22, %22primaryFindings%22, %22secondaryFindings%22),%0A                (doc, bulk) -%3E %7B%0A                    List%3CDocument%3E primaryFindings = doc.getList(%22primaryFindings%22, Document.class);%0A                    List%3CDocument%3E secondaryFindings = doc.getList(%22secondaryFindings%22, Document.class);%0A%0A                    Document update = new Document();%0A                    if (!primaryFindings.isEmpty()) %7B%0A                        applyChanges(primaryFindings);%0A                        update.put(%22primaryFindings%22, primaryFindings);%0A                    %7D%0A                    if (!secondaryFindings.isEmpty()) %7B%0A                        applyChanges(secondaryFindings);%0A                        update.put(%22secondaryFindings%22, secondaryFindings);%0A                    %7D%0A%0A                    bulk.add(new UpdateOneModel%3C%3E(%0A                            eq(%22_id%22, doc.get(%22_id%22)),%0A                            new Document(%22$set%22, update))%0A                    );%0A                %7D%0A        );%0A    %7D%0A%0A    private void applyChanges(List%3CDocument%3E clinicalVariants) %7B%0A        if (clinicalVariants.isEmpty()) %7B%0A            return;%0A        %7D%0A%0A        for (Document clinicalVariant : clinicalVariants) %7B%0A            List%3CDocument%3E evidences = clinicalVariant.getList(%22evidences%22, Document.class);%0A            if (evidences.isEmpty()) %7B%0A                continue;%0A            %7D%0A            for (Document evidence : evidences) %7B%0A                Document review = evidence.get(%22review%22, Document.class);%0A                // review field should not exist%0A                if (review == null) %7B%0A                    String justification = evidence.getString(%22justification%22);%0A                    evidence.remove(%22justification%22);%0A%0A                    Document clinicalEvidenceReview = new Document()%0A                            .append(%22select%22, false)%0A                            .append(%22acmg%22, Collections.emptyList());%0A                    if (StringUtils.isNotEmpty(justification)) %7B%0A                        clinicalEvidenceReview.put(%22discussion%22, justification);%0A                    %7D%0A                    evidence.put(%22review%22, clinicalEvidenceReview);%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

add ClinicalVariantEvidence migration, closes #1874