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.HashSet;
import java.util.Set;

/**
 * Created by jmason on 16/03/2017.
 */
@NodeEntity
public class PatientSnapshot {

    @GraphId
    private Long id;

    private Patient patient;
    private String age;
    private String dateAtCollection;
    private Boolean treatmentNaive;

    @Relationship(type = "SAMPLED_FROM")
    private Set<Sample> samples;

    @Relationship(type = "TREATED_WITH", direction = Relationship.INCOMING)
    private Set<Treatment> treatments;

    public PatientSnapshot() {
    }

    public PatientSnapshot(Patient patient, String age) {
        this.patient = patient;
        this.age = age;
    }

    public String getAgeBin() {
        String ageBin;

        try {
            Integer ageInteger = Integer.parseInt(this.age);

            if (ageInteger < 11) {
                ageBin = "Child";
            } else if (ageInteger < 21) {
                ageBin = "11-20";
            } else if (ageInteger < 31) {
                ageBin = "21-30";
            } else if (ageInteger < 41) {
                ageBin = "31-40";
            } else if (ageInteger < 51) {
                ageBin = "41-50";
            } else if (ageInteger < 61) {
                ageBin = "51-60";
            } else if (ageInteger < 71) {
                ageBin = "61-70";
            } else if (ageInteger < 81) {
                ageBin = "71-80";
            } else if (ageInteger < 91) {
                ageBin = "81-90";
            } else if (ageInteger < 101) {
                ageBin = "91-100";
            } else {
                ageBin = "> 101";
            }

        } catch (Exception e) {
            // probably a parse exception
            ageBin = this.age;
        }

        return ageBin;
    }

    public PatientSnapshot(Patient patient, String age, Set<Sample> samples) {
        this.patient = patient;
        this.age = age;
        this.samples = samples;
    }

    public PatientSnapshot(Patient patient, String age, Set<Sample> samples, Set<Treatment> treatments) {
        this.patient = patient;
        this.age = age;
        this.samples = samples;
        this.treatments = treatments;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public Set<Sample> getSamples() {
        return samples;
    }

    public void setSamples(Set<Sample> samples) {
        this.samples = samples;
    }
    
    public void addSample(Sample sample){
        if(this.samples == null){
            this.samples = new HashSet<>();
        }
        this.samples.add(sample);
    }

    public Patient getPatient() {
        return patient;
    }

    public void setPatient(Patient patient) {
        this.patient = patient;
    }

    public Set<Treatment> getTreatments() {
        return treatments;
    }

    public void setTreatments(Set<Treatment> treatments) {
        this.treatments = treatments;
    }

    public String getDateAtCollection() {
        return dateAtCollection;
    }

    public void setDateAtCollection(String dateAtCollection) {
        this.dateAtCollection = dateAtCollection;
    }

    public Boolean getTreatmentNaive() {
        return treatmentNaive;
    }

    public void setTreatmentNaive(Boolean treatmentNaive) {
        this.treatmentNaive = treatmentNaive;
    }
}

@@ -964,17 +964,17 @@
 eger %3C 1
-1
+0
 ) %7B%0A    
@@ -999,13 +999,11 @@
  = %22
-Child
+0-9
 %22;%0A 
@@ -1038,17 +1038,17 @@
 eger %3C 2
-1
+0
 ) %7B%0A    
@@ -1074,12 +1074,12 @@
 = %221
-1-20
+0-19
 %22;%0A 
@@ -1114,17 +1114,17 @@
 eger %3C 3
-1
+0
 ) %7B%0A    
@@ -1150,12 +1150,12 @@
 = %222
-1-30
+0-29
 %22;%0A 
@@ -1190,17 +1190,17 @@
 eger %3C 4
-1
+0
 ) %7B%0A    
@@ -1226,12 +1226,12 @@
 = %223
-1-40
+0-39
 %22;%0A 
@@ -1266,17 +1266,17 @@
 eger %3C 5
-1
+0
 ) %7B%0A    
@@ -1302,12 +1302,12 @@
 = %224
-1-50
+0-49
 %22;%0A 
@@ -1342,17 +1342,17 @@
 eger %3C 6
-1
+0
 ) %7B%0A    
@@ -1378,12 +1378,12 @@
 = %225
-1-60
+0-59
 %22;%0A 
@@ -1418,17 +1418,17 @@
 eger %3C 7
-1
+0
 ) %7B%0A    
@@ -1454,12 +1454,12 @@
 = %226
-1-70
+0-69
 %22;%0A 
@@ -1494,17 +1494,17 @@
 eger %3C 8
-1
+0
 ) %7B%0A    
@@ -1530,12 +1530,12 @@
 = %227
-1-80
+0-79
 %22;%0A 
@@ -1570,17 +1570,17 @@
 eger %3C 9
-1
+0
 ) %7B%0A    
@@ -1606,12 +1606,12 @@
 = %228
-1-90
+0-89
 %22;%0A 
@@ -1626,86 +1626,20 @@
    %7D
- else if (ageInteger %3C 101) %7B%0A                ageBin = %2291-100%22;%0A            %7D
+%0A           
  els
@@ -1672,13 +1672,11 @@
  = %22
-%3E 101
+90+
 %22;%0A 

Change age bins