package reciter.pubmed.retriever;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Builder
@Getter
@Setter
public class PubMedQuery {
    private static SimpleDateFormat dt = new SimpleDateFormat("yyyy/MM/dd");

    @JsonProperty("author")
    private String author;

    @JsonProperty("start")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy/MM/dd")
    private Date start;

    @JsonProperty("end")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy/MM/dd")
    private Date end;

    @JsonProperty("strategy-query")
    private String strategyQuery;

    @Override
    public String toString() {
//        return author + "[au]" + " AND " + dt.format(start) + ":" + dt.format(end) + "[DP]";
        List<String> parts = new ArrayList<String>();
        if (author != null) {
            //parts.add(author + " [au]");
        	parts.add(author);
        }
        if (start != null && end != null) {
            parts.add(dt.format(start) + ":" + dt.format(end) + "[DP]");
        }
        if (strategyQuery != null && !strategyQuery.isEmpty()) {
            parts.add(strategyQuery);
        }

        return StringUtils.join(parts, " AND ");
    }
}

@@ -1157,32 +1157,143 @@
 hor);%0A        %7D%0A
+        //Switched from %5BDP%5D to %5BEDAT%5D for better capture of pubs : Date of publication - Date added to Entrez%0A
         if (star
@@ -1386,18 +1386,20 @@
 nd) + %22%5B
-DP
+EDAT
 %5D%22);%0A   

switch from DP to EDAT in date range