package org.pdxfinder.mapping;

import joptsimple.OptionParser;
import joptsimple.OptionSet;
import org.pdxfinder.services.MappingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/*
 * Created by csaba on 24/04/2019.
 */
@Component
public class ExportMappings implements CommandLineRunner {

    @Autowired
    MappingService mappingService;
    Logger logger = LoggerFactory.getLogger(ExportMappings.class);

    @Value("${pdxfinder.root.dir}")
    private String finderRootDir;

    @Override
    public void run(String... args) throws Exception {

        OptionParser parser = new OptionParser();
        parser.allowsUnrecognizedOptions();
        parser.accepts("exportEuroPdxMappings", "Exporting mapping rules to a file");
        OptionSet options = parser.parse(args);

        if (options.has("exportEuroPdxMappings")) {
            exportEuroPdxMappings();
        }
    }

    private void exportEuroPdxMappings(){

        String diagnosisFileName = "%s/mappings_out//diagnosis_mappings.json".format(finderRootDir);
        String treatmentFileName = "%s/mappings_out/treatment_mappings.json".format(finderRootDir);
        List<String> dataSourcesToExport = new ArrayList<>(Arrays.asList(
            "Curie-BC",
            "Curie-LC",
            "Curie-OC",
            "IRCC-CRC",
            "IRCC-GC",
            "TRACE",
            "UOC-BC",
            "UOM-BC",
            "VHIO-BC",
            "VHIO-CRC"
        ));

        mappingService.saveMappingsToFile(
            diagnosisFileName,
            mappingService.getMappingsByDSAndType(dataSourcesToExport, "diagnosis").getEntityList()
        );
        mappingService.saveMappingsToFile(
            treatmentFileName,
            mappingService.getMappingsByDSAndType(dataSourcesToExport, "treatment").getEntityList()
        );

    }

}

@@ -1291,17 +1291,16 @@
 ngs_out/
-/
 diagnosi
@@ -1331,32 +1331,32 @@
 finderRootDir);%0A
+
         String t
@@ -1431,32 +1431,36 @@
 finderRootDir);%0A
+%0A%0A%0A%0A
         List%3CStr
@@ -1759,17 +1759,92 @@
     ));%0A
+        logger.info(%22Exporting diagnosis mappings to :%22+diagnosisFileName);
 %0A
-
         
@@ -2001,32 +2001,32 @@
 getEntityList()%0A
-
         );%0A     
@@ -2020,16 +2020,91 @@
      );%0A
+        logger.info(%22Exporting treatment mappings to %22+treatmentFileName);%0A
         

Add msg