package org.pdxfinder.services;

import org.pdxfinder.dao.TreatmentSummary;
import org.pdxfinder.repositories.DrugRepository;
import org.pdxfinder.repositories.ResponseRepository;
import org.pdxfinder.repositories.TreatmentProtocolRepository;
import org.pdxfinder.repositories.TreatmentSummaryRepository;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/*
 * Created by csaba on 29/03/2018.
 */
@Service
public class DrugService {

    private TreatmentSummaryRepository treatmentSummaryRepository;
    private TreatmentProtocolRepository treatmentProtocolRepository;
    private ResponseRepository responseRepository;
    private DrugRepository drugRepository;

    public DrugService(TreatmentSummaryRepository treatmentSummaryRepository,
                       TreatmentProtocolRepository treatmentProtocolRepository,
                       ResponseRepository responseRepository,
                       DrugRepository drugRepository) {

        this.treatmentSummaryRepository = treatmentSummaryRepository;
        this.treatmentProtocolRepository = treatmentProtocolRepository;
        this.responseRepository = responseRepository;
        this.drugRepository = drugRepository;
    }


    public int getDosingStudiesNumberByDataSource(String dataSource){

        return treatmentSummaryRepository.findStudyNumberByDataSource(dataSource);
    }


    public String getPlatformUrlByDataSource(String dataSource){

        return treatmentSummaryRepository.findPlatformUrlByDataSource(dataSource);
    }

    public List<String> getDrugNames(){

        return drugRepository.findDistinctDrugNames();
    }

    public List<String> getResponseOptions(){

        return responseRepository.findAllResponses();
    }

    public List<TreatmentSummary> getSummariesWithDrugAndResponse(){

        return treatmentSummaryRepository.findAllWithDrugData();
    }

    public int getTotalSummaryNumber(){

        return treatmentSummaryRepository.findTotalSummaryNumber();
    }

}

@@ -26,16 +26,60 @@
 vices;%0A%0A
+import org.pdxfinder.dao.TreatmentProtocol;%0A
 import o
@@ -435,19 +435,67 @@
 va.util.
-Lis
+HashSet;%0Aimport java.util.List;%0Aimport java.util.Se
 t;%0A%0A/*%0A 
@@ -1698,53 +1698,505 @@
     
-return drug
+Set%3CString%3E drugNamesSet = new HashSet%3C%3E();%0A        List%3CString%3E drugNames = new ArrayList%3C%3E();%0A%0A        List%3CTreatmentSummary%3E treatmentSummaries = getSummariesWithDrugAnd
 Re
+s
 po
-sitory.findDistinctDrugNames()
+nse();%0A%0A        for(TreatmentSummary ts : treatmentSummaries)%7B%0A%0A            for(TreatmentProtocol tp : ts.getTreatmentProtocols())%7B%0A%0A                String drugName = tp.getDrugString();%0A                drugNamesSet.add(drugName);%0A            %7D%0A        %7D%0A%0A        drugNames.addAll(drugNamesSet);%0A        return drugNames
 ;%0A  

Include drug combinations to suggestions