<commit_before>package edu.duke.cabig.c3pr.domain.factory;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import edu.duke.cabig.c3pr.dao.HealthcareSiteDao;
import edu.duke.cabig.c3pr.dao.Summary3ReportDao;
import edu.duke.cabig.c3pr.domain.HealthcareSite;
import edu.duke.cabig.c3pr.domain.Summary3Report;
import edu.duke.cabig.c3pr.domain.Summary3ReportDiseaseSite;
import edu.duke.cabig.c3pr.tools.Configuration;

public class Summary3ReportFactory {
	
	private Summary3ReportDao summary3ReportDao;
	
	private HealthcareSiteDao healthcareSiteDao;
	
	private Configuration configuration;
	
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	public void setHealthcareSiteDao(HealthcareSiteDao healthcareSiteDao) {
		this.healthcareSiteDao = healthcareSiteDao;
	}

	public Summary3ReportDao getSummary3ReportDao() {
		return summary3ReportDao;
	}

	public void setSummary3ReportDao(Summary3ReportDao summary3ReportDao) {
		this.summary3ReportDao = summary3ReportDao;
	}
	
	public void buildSummary3Report(Summary3Report summary3Report){
		
		if(summary3Report.getReportingSource()== null){
			String reportingSourceNCICode =	this.configuration.get(Configuration.LOCAL_NCI_INSTITUTE_CODE);;
			HealthcareSite reportingOrganization = healthcareSiteDao.getByPrimaryIdentifier(reportingSourceNCICode);
			summary3Report.setReportingSource(reportingOrganization.getName());
		}
		Date reportStartDate = summary3Report.getStartDate();
		Date reportEndDate = summary3Report.getEndDate();
		HealthcareSite hcs = summary3Report.getReportingOrganization();
		List<Summary3ReportDiseaseSite> diseaseSites = new ArrayList<Summary3ReportDiseaseSite>();
		diseaseSites = summary3ReportDao.getAllOrderedByName();
		
		Integer therapeuticSummary3DiseaseSiteRegistrationsCount =0;
		Integer summary3DiseaseSiteRegistrationsCount =0;
		
		for(Summary3ReportDiseaseSite summary3ReportDiseaseSite:diseaseSites){
			Map registrationsForDiseaseSite = new HashMap<String,Object>();
			Integer newlyEnrolledTherapeuticPatientsForGivenDiseaseSite = summary3ReportDao.getNewlyEnrolledTherapeuticStudySubjectCountForGivenSummary3ReportDiseaseSite(summary3ReportDiseaseSite, hcs, reportStartDate, reportEndDate);
			therapeuticSummary3DiseaseSiteRegistrationsCount = therapeuticSummary3DiseaseSiteRegistrationsCount+newlyEnrolledTherapeuticPatientsForGivenDiseaseSite;
			Integer newlyRegisteredPatientsForGivenICD9DiseaseSite = summary3ReportDao.getNewlyRegisteredSubjectCountForGivenSummary3ReportDiseaseSite(summary3ReportDiseaseSite, hcs, reportStartDate, reportEndDate);
			summary3DiseaseSiteRegistrationsCount = summary3DiseaseSiteRegistrationsCount + newlyRegisteredPatientsForGivenICD9DiseaseSite;
			registrationsForDiseaseSite.put("newlyEnrolledTherapeuticPatients", newlyEnrolledTherapeuticPatientsForGivenDiseaseSite);
			registrationsForDiseaseSite.put("newlyRegisteredPatients", " - ");
			summary3Report.getReportData().put(summary3ReportDiseaseSite,registrationsForDiseaseSite);
		}
		
		// creating a dummy anatomic site which has total as name for reporting purpose.
		//TODO find a better way to implement this		
		
		Map totalRegistrationCounts = new HashMap<String,Object>();
	
		Summary3ReportDiseaseSite totalICD9DiseaseSite = new Summary3ReportDiseaseSite();
		Integer newlyEnrolledTotalTherapeuticPatients = summary3ReportDao.getNewlyEnrolledTherapeuticStudySubjectCount( hcs, reportStartDate, reportEndDate);
		Integer newlyRegisteredTotalPatients = summary3ReportDao.getNewlyRegisteredSubjectCount(hcs, reportStartDate, reportEndDate);
		totalRegistrationCounts.put("newlyEnrolledTherapeuticPatients", newlyEnrolledTotalTherapeuticPatients);
		totalRegistrationCounts.put("newlyRegisteredPatients", " - ");
		
		// creating a dummy anatomic site which has total as name for reporting purpose.
		//TODO find a better way to implement this		
		
		totalICD9DiseaseSite.setName("TOTAL:");
		summary3Report.getReportData().put(totalICD9DiseaseSite, totalRegistrationCounts);
	
	}

}
<commit_msg>CPR-2383 : Fixed the sum of registrations against disease sites not adding up to total<commit_after>package edu.duke.cabig.c3pr.domain.factory;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import edu.duke.cabig.c3pr.dao.HealthcareSiteDao;
import edu.duke.cabig.c3pr.dao.Summary3ReportDao;
import edu.duke.cabig.c3pr.domain.HealthcareSite;
import edu.duke.cabig.c3pr.domain.Summary3Report;
import edu.duke.cabig.c3pr.domain.Summary3ReportDiseaseSite;
import edu.duke.cabig.c3pr.tools.Configuration;

public class Summary3ReportFactory {
	
	private Summary3ReportDao summary3ReportDao;
	
	private HealthcareSiteDao healthcareSiteDao;
	
	private Configuration configuration;
	
	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	public void setHealthcareSiteDao(HealthcareSiteDao healthcareSiteDao) {
		this.healthcareSiteDao = healthcareSiteDao;
	}

	public Summary3ReportDao getSummary3ReportDao() {
		return summary3ReportDao;
	}

	public void setSummary3ReportDao(Summary3ReportDao summary3ReportDao) {
		this.summary3ReportDao = summary3ReportDao;
	}
	
	@SuppressWarnings("unchecked")
	public void buildSummary3Report(Summary3Report summary3Report){
		
		if(summary3Report.getReportingSource()== null){
			String reportingSourceNCICode =	this.configuration.get(Configuration.LOCAL_NCI_INSTITUTE_CODE);;
			HealthcareSite reportingOrganization = healthcareSiteDao.getByPrimaryIdentifier(reportingSourceNCICode);
			summary3Report.setReportingSource(reportingOrganization.getName());
		}
		Date reportStartDate = summary3Report.getStartDate();
		Date reportEndDate = summary3Report.getEndDate();
		HealthcareSite hcs = summary3Report.getReportingOrganization();
		List<Summary3ReportDiseaseSite> diseaseSites = new ArrayList<Summary3ReportDiseaseSite>();
		diseaseSites = summary3ReportDao.getAllOrderedByName();
		
	//	int summary3DiseaseSiteRegistrationsCount =0;
		int newlyEnrolledTotalTherapeuticPatients = 0;
		
		for(Summary3ReportDiseaseSite summary3ReportDiseaseSite:diseaseSites){
			Map registrationsForDiseaseSite = new LinkedHashMap<String,Object>();
			int newlyEnrolledTherapeuticPatientsForGivenDiseaseSite = summary3ReportDao.getNewlyEnrolledTherapeuticStudySubjectCountForGivenSummary3ReportDiseaseSite(summary3ReportDiseaseSite, hcs, reportStartDate, reportEndDate);
			// update the newly enrolled therapeutic patients with those for the particular disease
			newlyEnrolledTotalTherapeuticPatients = newlyEnrolledTotalTherapeuticPatients + newlyEnrolledTherapeuticPatientsForGivenDiseaseSite;
		//	int newlyRegisteredPatientsForGivenICD9DiseaseSite = summary3ReportDao.getNewlyRegisteredSubjectCountForGivenSummary3ReportDiseaseSite(summary3ReportDiseaseSite, hcs, reportStartDate, reportEndDate);
		//	summary3DiseaseSiteRegistrationsCount = summary3DiseaseSiteRegistrationsCount + newlyRegisteredPatientsForGivenICD9DiseaseSite;
			registrationsForDiseaseSite.put("newlyRegisteredPatients", " - ");
			registrationsForDiseaseSite.put("newlyEnrolledTherapeuticPatients", newlyEnrolledTherapeuticPatientsForGivenDiseaseSite);
			
			summary3Report.getReportData().put(summary3ReportDiseaseSite,(LinkedHashMap<String,Object>)registrationsForDiseaseSite);
		}
		
		// creating a dummy anatomic site which has total as name for reporting purpose.
		//TODO find a better way to implement this		
		
		Map totalRegistrationCounts = new LinkedHashMap<String,Object>();
	
		Summary3ReportDiseaseSite totalICD9DiseaseSite = new Summary3ReportDiseaseSite();
	//	Integer newlyRegisteredTotalPatients = summary3ReportDao.getNewlyRegisteredSubjectCount(hcs, reportStartDate, reportEndDate);
		totalRegistrationCounts.put("newlyRegisteredPatients", " - ");
		totalRegistrationCounts.put("newlyEnrolledTherapeuticPatients", newlyEnrolledTotalTherapeuticPatients);
		
		// creating a dummy anatomic site which has total as name for reporting purpose.
		//TODO find a better way to implement this		
		
		totalICD9DiseaseSite.setName("TOTAL:");
		summary3Report.getReportData().put(totalICD9DiseaseSite, (LinkedHashMap<String,Object>)totalRegistrationCounts);
	
	}

}

{'fraction_non_alphanumeric': 0.0688401548023924, 'fraction_numerical': 0.014072944763691803, 'mean_word_length': 6.507042253521127, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2148960', 'n_tokens_mistral': 2747, 'n_tokens_neox': 2450, 'n_words': 397}