<commit_before>package gov.nih.nci.cabig.caaers.api.impl;

import gov.nih.nci.cabig.caaers.integration.schema.aereport.AdverseEventReport;
import gov.nih.nci.cabig.caaers.integration.schema.common.CaaersServiceResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.transaction.annotation.Transactional;

public class SafetyReportManagementServiceImpl {
	private static Log logger = LogFactory.getLog(SafetyReportManagementServiceImpl.class);
	
	  @Transactional(readOnly=false)
	    public CaaersServiceResponse submitSafetyReport(AdverseEventReport adverseEventReport) {

	        CaaersServiceResponse response = Helper.createResponse();
	        //TODO
	        // implement the core service

	        return response;
	    }

}<commit_msg>Caaers-6230 : Implemented the Orchestration step.<commit_after>package gov.nih.nci.cabig.caaers.api.impl;


import gov.nih.nci.cabig.caaers.domain.ExpeditedAdverseEventReport;
import gov.nih.nci.cabig.caaers.domain.report.Report;
import gov.nih.nci.cabig.caaers.domain.repository.ReportValidationService;
import gov.nih.nci.cabig.caaers.integration.schema.aereport.AdverseEventReport;
import gov.nih.nci.cabig.caaers.integration.schema.common.CaaersServiceResponse;
import gov.nih.nci.cabig.caaers.service.DomainObjectImportOutcome;
import gov.nih.nci.cabig.caaers.service.EvaluationService;
import gov.nih.nci.cabig.caaers.service.ReportSubmissionService;
import gov.nih.nci.cabig.caaers.service.ReportSubmittability;
import gov.nih.nci.cabig.caaers.service.migrator.ExpeditedAdverseEventReportConverter;
import gov.nih.nci.cabig.caaers.service.migrator.ExpeditedReportMigrator;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.transaction.annotation.Transactional;

public class SafetyReportManagementServiceImpl {
	private static Log logger = LogFactory.getLog(SafetyReportManagementServiceImpl.class);
	
	/**	Expedited Report Converter. **/
	private ExpeditedAdverseEventReportConverter eaeConverter;
	
	/** Expedited Report Migrator. **/
	private ExpeditedReportMigrator migrator;
	
	/** Report Validation Service. **/
	private ReportValidationService reportValidationService;
	
	  /** The Evaluation Service. */
    private EvaluationService evaluationService;
    
    /** Report Submission Service.**/
    private ReportSubmissionService reportSubmissionService;
	
	@Transactional(readOnly=false)
	public CaaersServiceResponse submitSafetyReport(AdverseEventReport adverseEventReport) {

	   CaaersServiceResponse response = Helper.createResponse();
	   
	   try {
	        
		   // Steps to be followed are
		        
		   // 1. Call the Converter(s) to construct the domain object. 
		   ExpeditedAdverseEventReport aeSrcReport = eaeConverter.convert(adverseEventReport);
		   
		   ExpeditedAdverseEventReport aeDestReport = new ExpeditedAdverseEventReport();
		   
		   // 2. Call the GenericValidator to make sure input is correct.
		      	
		        	
		   // 3. Call the list of Migrators to fully populate the domain object.
		   DomainObjectImportOutcome<ExpeditedAdverseEventReport> outCome = new DomainObjectImportOutcome<ExpeditedAdverseEventReport>();
		   migrator.migrate(aeSrcReport, aeDestReport, outCome);
		   
		   if ( outCome.hasErrors() ) {
			   Helper.populateError(response, "GEN_ORH_001", "Error(s) occured during Migration step.");
			   return response;
		   }
		        	
		   // 4. Call the ReportValidationService to ensure all valid business rules and Report Definitions criteria is met.
		   // 5. Call Report Submission Service 
		   for ( Report  rpt: aeDestReport.getReports()) {
			   ReportSubmittability rptSubmittability =  reportValidationService.isSubmittable(rpt);
			   if ( rptSubmittability.isSubmittable() ) {
				   reportSubmissionService.submitReport(rpt);
			   } else {
				   outCome.addError("ER_ORH_001", "Validation failed for Report " + rpt.getName());
			   }
		   }
		   
		   if ( outCome.hasErrors() ) {
			   Helper.populateError(response, "GEN_ORH_001", "Error(s) occured during Report Submission step.");
			   return response;
		   }
	       
	   }catch(Exception e) {
		   logger.error("Unable to Create a Report from Safety Management Service");
		   Helper.populateError(response, "ERR_ORH_001",e.getMessage() );
	   }
	   
	    return response;
	}
	
	public ExpeditedReportMigrator getMigrator() {
		return migrator;
	}
	public void setMigrator(ExpeditedReportMigrator migrator) {
		this.migrator = migrator;
	}
	public ExpeditedAdverseEventReportConverter getEaeConverter() {
		return eaeConverter;
	}
	public void setEaeConverter(ExpeditedAdverseEventReportConverter eaeConverter) {
		this.eaeConverter = eaeConverter;
	}

	public ReportValidationService getReportValidationService() {
		return reportValidationService;
	}

	public void setReportValidationService(
			ReportValidationService reportValidationService) {
		this.reportValidationService = reportValidationService;
	}

	public EvaluationService getEvaluationService() {
		return evaluationService;
	}

	public void setEvaluationService(EvaluationService evaluationService) {
		this.evaluationService = evaluationService;
	}

}
{'fraction_non_alphanumeric': 0.08409610983981694, 'fraction_numerical': 0.004004576659038902, 'mean_word_length': 4.368474923234391, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5017915', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1526, 'n_words': 287}