001/**
002 * Copyright (C) 2014  Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
003 *
004 * This file is part of Dicoogle/dicoogle.
005 *
006 * Dicoogle/dicoogle is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * Dicoogle/dicoogle is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with Dicoogle.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package pt.ua.dicoogle.core.dicom;
020
021import java.util.ArrayList;
022import java.util.HashMap;
023import java.util.concurrent.ExecutionException;
024import org.slf4j.LoggerFactory;
025import pt.ua.dicoogle.plugins.PluginController;
026import pt.ua.dicoogle.sdk.datastructs.SearchResult;
027import pt.ua.dicoogle.sdk.task.JointQueryTask;
028import pt.ua.dicoogle.sdk.task.Task;
029
030/**
031 *
032 * @author Luís A. Bastião Silva - <bastiao@ua.pt>
033 */
034public class SearchURI {
035
036    public Iterable<SearchResult> search(String query) {
037
038        HashMap<String, String> extraFields = new HashMap<String, String>();
039        ArrayList<SearchResult> resultsArr = new ArrayList<SearchResult>();
040        extraFields.put("SOPInstanceUID", "SOPInstanceUID");
041        MyHolder holder = new MyHolder();
042        PluginController.getInstance().queryAll(holder, query, extraFields);
043        Iterable<SearchResult> results = null;
044        try {
045            results = holder.get();
046        } catch (InterruptedException ex) {
047            LoggerFactory.getLogger(SearchURI.class).error(ex.getMessage(), ex);
048        } catch (ExecutionException ex) {
049            LoggerFactory.getLogger(SearchURI.class).error(ex.getMessage(), ex);
050        }
051        if (results==null)
052        {
053            return results;
054        }
055        for (SearchResult r : results) {
056            resultsArr.add(r);
057        }
058
059        return resultsArr;
060        
061
062    }
063
064    class MyHolder extends JointQueryTask {
065
066        @Override
067        public void onCompletion() {
068            
069        }
070
071        @Override
072        public void onReceive(Task<Iterable<SearchResult>> e) {
073
074        }
075
076    }
077
078}