package com.agilex.healthcare.schedulingmanager.translator;

import com.agilex.healthcare.schedulingmanager.domain.SMConsult;
import com.agilex.healthcare.schedulingmanager.domain.SMConsults;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;

/**
 * Created with IntelliJ IDEA.
 * User: patelh
 * Date: 12/24/13
 * Time: 9:45 AM
 * To change this template use File | Settings | File Templates.
 */
public class ConsultMongoTranslator {

    private SMConsults smConsults;

    public ConsultMongoTranslator() {
    }

    public ConsultMongoTranslator(SMConsults smConsults) {
        this.smConsults = smConsults;
    }

    public ArrayList<DBObject> convertToDBObjects() {
        Iterator<?>            listEntryIterator;
        ArrayList<DBObject> returnArray = new ArrayList<DBObject>();

        listEntryIterator = smConsults.iterator();
        while(listEntryIterator.hasNext()){
            SMConsult   smConsult;
            DBObject    dbObject = new BasicDBObject();

            smConsult = (SMConsult)listEntryIterator.next();

            dbObject.put(SMConsult.CONSULT_IEN_KEY, smConsult.getConsultIen());
            dbObject.put(SMConsult.REQUEST_DATE_KEY, smConsult.getRequestDate());
            dbObject.put(SMConsult.STATUS_KEY, smConsult.getStatus());
            dbObject.put(SMConsult.SERVICE_IEN_KEY, smConsult.getServiceIen());
            dbObject.put(SMConsult.SERVICE_NAME_KEY, smConsult.getServiceName());
            dbObject.put(SMConsult.PATIENT_DFN_KEY, smConsult.getPatientDfn());
            dbObject.put(SMConsult.PATIENT_NAME_KEY, smConsult.getPatientName());
            dbObject.put(SMConsult.SENDING_PROVIDER_DUZ_KEY, smConsult.getSendingProviderDuz());
            dbObject.put(SMConsult.SENDING_PROVIDER_NAME_KEY, smConsult.getSendingProviderName());
            dbObject.put(SMConsult.TEXT_KEY, smConsult.getText());
            dbObject.put(SMConsult.DAYS_ON_LIST_KEY, smConsult.getDaysOnList());

            returnArray.add(dbObject);
        }
        return returnArray;
    }

    public SMConsult dbObjectToSMConsult(DBObject dbObject){
        SMConsult smConsult = new SMConsult();

        smConsult.setConsultIen((String)dbObject.get(SMConsult.CONSULT_IEN_KEY));
        smConsult.setRequestDate((Date)dbObject.get(SMConsult.REQUEST_DATE_KEY));
        smConsult.setStatus((String)dbObject.get(SMConsult.STATUS_KEY));
        smConsult.setServiceIen((String)dbObject.get(SMConsult.SERVICE_IEN_KEY));
        smConsult.setServiceName((String)dbObject.get(SMConsult.SERVICE_NAME_KEY));
        smConsult.setPatientDfn((String)dbObject.get(SMConsult.PATIENT_DFN_KEY));
        smConsult.setPatientName((String)dbObject.get(SMConsult.PATIENT_NAME_KEY));
        smConsult.setSendingProviderDuz((String)dbObject.get(SMConsult.SENDING_PROVIDER_DUZ_KEY));
        smConsult.setSendingProviderName((String)dbObject.get(SMConsult.SENDING_PROVIDER_NAME_KEY));
        smConsult.setText((String)dbObject.get(SMConsult.TEXT_KEY));
        smConsult.setDaysOnList((String)dbObject.get(SMConsult.DAYS_ON_LIST_KEY));

        return smConsult;
    }
}
