package org.pdxfinder.dao;

import org.neo4j.ogm.annotation.GraphId;
import org.neo4j.ogm.annotation.NodeEntity;
import org.neo4j.ogm.annotation.Relationship;

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

/*
 * Created by csaba on 23/10/2017.
 */


@NodeEntity
public class TreatmentProtocol {

    /**
     * @param components                The treatment components that were used in this protocol
     * @param armSize                   The number of animals used in the study arm
     * @param response                  A recist classification of the response to the treatment
     * @param responseCalculationMethod The method used to determine the response classification
     * @param passages                  The list of passages at which this treatment was applied
     */

    @GraphId
    private Long id;

    @Relationship(type = "TREATMENT_COMPONENT")
    private List<TreatmentComponent> components;

    @Relationship(type = "RESPONSE")
    private Response response;

    @Relationship(type = "CURRENT_TREATMENT")
    private CurrentTreatment currentTreatment;

    private String armSize;
    private String responseCalculationMethod;
    private String passages;

    private String treatmentDate;

    public TreatmentProtocol() {
        components = new ArrayList<>();
    }


    public List<TreatmentComponent> getComponents() {
        return components;
    }

    public void setComponents(List<TreatmentComponent> components) {
        this.components = components;
    }

    public Response getResponse() {
        return response;
    }

    public void setResponse(Response response) {
        this.response = response;
    }

    public String getArmSize() {
        return armSize;
    }

    public void setArmSize(String armSize) {
        this.armSize = armSize;
    }

    public String getResponseCalculationMethod() {
        return responseCalculationMethod;
    }

    public void setResponseCalculationMethod(String responseCalculationMethod) {
        this.responseCalculationMethod = responseCalculationMethod;
    }

    public String getPassages() {
        return passages;
    }

    public void setPassages(String passages) {
        this.passages = passages;
    }

    public CurrentTreatment getCurrentTreatment() {
        return currentTreatment;
    }

    public void setCurrentTreatment(CurrentTreatment currentTreatment) {
        this.currentTreatment = currentTreatment;
    }

    public String getTreatmentDate() {
        return treatmentDate;
    }

    public void setTreatmentDate(String treatmentDate) {
        this.treatmentDate = treatmentDate;
    }

    public String getDrugString(boolean includeControlDrugs){

        String ret = "";

        for(TreatmentComponent comp:components){

            String drugName = comp.getDrug().getName();

            if(includeControlDrugs){
                if(!ret.isEmpty()){
                    ret+=" and ";
                }
                ret+=drugName;
            }
            //include only Drugs but no Controls
            else{

                if(comp.getType().equals("Drug")){

                    if(!ret.isEmpty()){
                        ret+=" and ";
                    }
                    ret+=drugName;
                }

            }

        }

        return ret;
    }





    public String getDurationString(){

        String durString = "";

        for(TreatmentComponent comp:components){

            String duration = comp.getDuration();

                if(!durString.isEmpty()){
                    durString+=" / ";
                }
                durString += duration;

        }

        return durString;
    }

    public String getDoseString(){

        String doseString = "";

        for(TreatmentComponent comp:components){

            String dose = comp.getDose();

            if(!doseString.isEmpty()){
                doseString+=" / ";
            }
            doseString += dose;

        }

        return doseString;
    }


    public void addTreatmentComponent(TreatmentComponent tc){

        if(components == null){
            components = new ArrayList<>();
        }

        components.add(tc);
    }


    public void addDurationForAllComponents(String duration){

        if(components != null){

            for(TreatmentComponent tc : components){

                tc.setDuration(duration);
            }
        }
    }

}

@@ -3353,24 +3353,51 @@
 ationString(
+boolean includeControlDrugs
 )%7B%0A%0A        
@@ -3492,21 +3492,16 @@
 ring dur
-ation
  = comp.
@@ -3512,24 +3512,61 @@
 uration();%0A%0A
+            if(includeControlDrugs)%7B%0A
             
@@ -3680,21 +3680,327 @@
 ring
- += duration;
++=dur;%0A            %7D%0A            //include only Drugs but no Controls%0A            else%7B%0A%0A                if(comp.getType().equals(%22Drug%22))%7B%0A%0A                    if(!durString.isEmpty())%7B%0A                        durString+=%22 / %22;%0A                    %7D%0A                    durString+=dur;%0A                %7D%0A%0A            %7D
 %0A%0A  
@@ -4073,16 +4073,43 @@
 eString(
+boolean includeControlDrugs
 )%7B%0A%0A    
@@ -4226,24 +4226,65 @@
 getDose();%0A%0A
+            if(includeControlDrugs)%7B%0A    
             
@@ -4318,32 +4318,36 @@
                 
+    
 doseString+=%22 / 
@@ -4341,32 +4341,36 @@
 eString+=%22 / %22;%0A
+    
             %7D%0A  
@@ -4371,32 +4371,36 @@
   %7D%0A            
+    
 doseString += do
@@ -4397,17 +4397,332 @@
 ring
- += dose;
++=dose;%0A            %7D%0A            //include only Drugs but no Controls%0A            else%7B%0A%0A                if(comp.getType().equals(%22Drug%22))%7B%0A%0A                    if(!doseString.isEmpty())%7B%0A                        doseString+=%22 / %22;%0A                    %7D%0A                    doseString+=dose;%0A                %7D%0A%0A            %7D
 %0A%0A  

Add duration and dose string getters