/*
 * Copyright 2015-2017 OpenCB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.opencb.opencga.storage.core.manager.clinical;

import org.opencb.commons.datastore.core.Query;
import org.opencb.commons.datastore.core.QueryOptions;
import org.opencb.commons.datastore.core.QueryResult;
import org.opencb.opencga.catalog.db.api.DBIterator;
import org.opencb.opencga.catalog.exceptions.CatalogException;
import org.opencb.opencga.catalog.managers.CatalogManager;
import org.opencb.opencga.catalog.managers.ClinicalAnalysisManager;
import org.opencb.opencga.core.models.ClinicalAnalysis;
import org.opencb.opencga.core.models.clinical.ReportedVariant;
import org.opencb.opencga.storage.core.StorageEngineFactory;
import org.opencb.opencga.storage.core.clinical.ClinicalVariantEngine;
import org.opencb.opencga.storage.core.clinical.ClinicalVariantException;
import org.opencb.opencga.storage.core.exceptions.StorageEngineException;
import org.opencb.opencga.storage.core.manager.StorageManager;

import java.io.IOException;

public class ClinicalInterpretationManager extends StorageManager {

    private ClinicalVariantEngine clinicalVariantEngine;

    public ClinicalInterpretationManager(CatalogManager catalogManager, StorageEngineFactory storageEngineFactory) {
        super(catalogManager, storageEngineFactory);
    }

    @Override
    public void testConnection() throws StorageEngineException {
    }

    public QueryResult<ReportedVariant> index(String token) throws IOException, ClinicalVariantException {
        return null;
    }

    public QueryResult<ReportedVariant> index(String study, String token) throws IOException, ClinicalVariantException, CatalogException {
        ClinicalAnalysisManager clinicalAnalysisManager = catalogManager.getClinicalAnalysisManager();
        DBIterator<ClinicalAnalysis> iterator = clinicalAnalysisManager.iterator(study, new Query(), QueryOptions.empty(), token);
        return null;
    }

    public QueryResult<ReportedVariant> query(Query query, QueryOptions options, String token)
            throws IOException, ClinicalVariantException {

        return clinicalVariantEngine.query(query, options, "");
    }

}

@@ -1104,16 +1104,135 @@
 alysis;%0A
+import org.opencb.opencga.core.models.clinical.Comment;%0Aimport org.opencb.opencga.core.models.clinical.Interpretation;%0A
 import o
@@ -1283,24 +1283,24 @@
 tedVariant;%0A
-
 import org.o
@@ -1485,32 +1485,105 @@
 riantException;%0A
+import org.opencb.opencga.storage.core.clinical.ReportedVariantIterator;%0A
 import org.openc
@@ -2885,10 +2885,1003 @@
 %0A    %7D%0A%0A
+    public QueryResult%3CInterpretation%3E interpretationQuery(Query query, QueryOptions options, String token)%0A            throws IOException, ClinicalVariantException %7B%0A%0A        return clinicalVariantEngine.interpretationQuery(query, options, %22%22);%0A    %7D%0A%0A    public ReportedVariantIterator iterator(Query query, QueryOptions options, String toten) throws IOException, ClinicalVariantException %7B%0A        return clinicalVariantEngine.iterator(query, options, %22%22);%0A    %7D%0A%0A    public void addInterpretationComment(long interpretationId, Comment comment, String toten)%0A            throws IOException, ClinicalVariantException %7B%0A        clinicalVariantEngine.addInterpretationComment(interpretationId, comment, %22%22);%0A    %7D%0A%0A    public void addReportedVariantComment(long interpretationId, String variantId, Comment comment, String toten)%0A            throws IOException, ClinicalVariantException %7B%0A        clinicalVariantEngine.addReportedVariantComment(interpretationId, variantId, comment, %22%22);%0A    %7D%0A
 %7D%0A

complete ClinicalInterpretationManager