Skip to content

Commit

Permalink
[10813] extended IFileImportStrategy with setLabContactResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
huthomas authored and ngiger committed Sep 25, 2018
1 parent e4321ff commit 7831a54
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 7 deletions.
Expand Up @@ -7,13 +7,13 @@
import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;

import ch.elexis.core.importer.div.importers.HL7Parser;
import ch.elexis.core.importer.div.importers.IPersistenceHandler;
import ch.elexis.core.importer.div.importers.Messages;
import ch.elexis.core.importer.div.importers.multifile.strategy.IFileImportStrategy;
import ch.elexis.core.importer.div.importers.multifile.strategy.IFileImportStrategyFactory;


import ch.rgw.io.FileTool;
import ch.rgw.tools.Result;
import ch.rgw.tools.Result.SEVERITY;
Expand Down Expand Up @@ -50,8 +50,7 @@ public Result<Object> importFromFile(File hl7File,
try {
results.add(importStrategy.execute(file, context, hl7parser, persistenceHandler));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
LoggerFactory.getLogger(getClass()).error("Error executing import", e);
}
}
return results;
Expand Down
Expand Up @@ -6,6 +6,7 @@
import java.util.Map;

import ch.elexis.core.importer.div.importers.HL7Parser;
import ch.elexis.core.importer.div.importers.ILabContactResolver;
import ch.elexis.core.importer.div.importers.IPersistenceHandler;
import ch.elexis.core.importer.div.importers.multifile.IMultiFileParser;
import ch.elexis.core.model.ILabOrder;
Expand All @@ -27,6 +28,8 @@ public class DefaultHL7ImportStrategy implements IFileImportStrategy {

private boolean moveAfterImport;

private ILabContactResolver labContactResolver;

public static final String CFG_IMPORT_ENCDATA = "hl7Parser/importencdata";

@SuppressWarnings("unchecked")
Expand All @@ -38,12 +41,24 @@ public Result<Object> execute(File file, Map<String, Object> context, HL7Parser

if (testMode) {
// we need to enable patient creation when testing otherwise test will fail
result = (Result<Object>) hl7Parser.importFile(file.getAbsolutePath(), true);
if (labContactResolver != null) {
result = (Result<Object>) hl7Parser.importFile(file, null, null, labContactResolver,
true);
} else {
result = (Result<Object>) hl7Parser.importFile(file.getAbsolutePath(), true);
}

if (moveAfterImport) {
FileImportStrategyUtil.moveAfterImport(result.isOK(), file);
}
} else {
result = (Result<Object>) hl7Parser.importFile(file.getAbsolutePath(), false);
if (labContactResolver != null) {
result = (Result<Object>) hl7Parser.importFile(file, null, null, labContactResolver,
false);
} else {
result = (Result<Object>) hl7Parser.importFile(file.getAbsolutePath(), false);
}

if (moveAfterImport) {
FileImportStrategyUtil.moveAfterImport(result.isOK(), file);
}
Expand Down Expand Up @@ -82,4 +97,10 @@ public IFileImportStrategy setMoveAfterImport(boolean value){
this.moveAfterImport = value;
return this;
}

@Override
public IFileImportStrategy setLabContactResolver(ILabContactResolver resolver){
this.labContactResolver = resolver;
return this;
}
}
Expand Up @@ -5,6 +5,7 @@
import java.util.Map;

import ch.elexis.core.importer.div.importers.HL7Parser;
import ch.elexis.core.importer.div.importers.ILabContactResolver;
import ch.elexis.core.importer.div.importers.IPersistenceHandler;
import ch.elexis.core.importer.div.importers.multifile.IMultiFileParser;
import ch.rgw.tools.Result;
Expand Down Expand Up @@ -40,4 +41,12 @@ public Result<Object> execute(File file, Map<String, Object> context, HL7Parser
public IFileImportStrategy setMoveAfterImport(boolean value);

public void setTestMode(boolean testing);

/**
* Add the {@link ILabContactResolver} that should be used on import.
*
* @param resolver
* @return
*/
public IFileImportStrategy setLabContactResolver(ILabContactResolver resolver);
}
Expand Up @@ -3,6 +3,8 @@
import java.io.File;
import java.util.Map;

import ch.elexis.core.importer.div.importers.ILabContactResolver;

/**
* a factory containing information about all the available {@link IFileImportStrategy
* IFileImportStrategies} and for which file type they are appropriate.
Expand All @@ -25,4 +27,20 @@ public interface IFileImportStrategyFactory {
*/
public Map<File, IFileImportStrategy> createImportStrategyMap(File hl7File);

/**
* Specify if imported files should be moved to archive and error directory inside the import
* directory. Default is false.
*
* @param value
* @return
*/
public IFileImportStrategyFactory setMoveAfterImport(boolean value);

/**
* Add the {@link ILabContactResolver} that should be used on import.
*
* @param resolver
* @return
*/
public IFileImportStrategyFactory setLabContactResolver(ILabContactResolver resolver);
}
Expand Up @@ -7,6 +7,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.elexis.core.importer.div.importers.ILabContactResolver;
import ch.elexis.core.importer.div.importers.multifile.strategy.BasicFileImportStrategyFactory;
import ch.elexis.core.importer.div.importers.multifile.strategy.DefaultHL7ImportStrategy;
import ch.elexis.core.importer.div.importers.multifile.strategy.IFileImportStrategy;
Expand All @@ -27,6 +28,8 @@ public class DefaultImportStrategyFactory extends BasicFileImportStrategyFactory

private boolean moveAfterImport;

private ILabContactResolver labContactResolver;

@Override
public Map<File, IFileImportStrategy> createImportStrategyMap(File hl7File){
Map<File, IFileImportStrategy> ret = super.createImportStrategyMap(hl7File);
Expand All @@ -44,7 +47,8 @@ public Map<File, IFileImportStrategy> createImportStrategyMap(File hl7File){
}
}

ret.values().forEach(strategy -> strategy.setMoveAfterImport(moveAfterImport));
ret.values().forEach(strategy -> strategy.setMoveAfterImport(moveAfterImport)
.setLabContactResolver(labContactResolver));
return ret;
}

Expand All @@ -55,8 +59,21 @@ public Map<File, IFileImportStrategy> createImportStrategyMap(File hl7File){
* @param value
* @return
*/
@Override
public IFileImportStrategyFactory setMoveAfterImport(boolean value){
this.moveAfterImport = value;
return this;
}

/**
* Add the {@link ILabContactResolver} that should be used on import.
*
* @param resolver
* @return
*/
@Override
public IFileImportStrategyFactory setLabContactResolver(ILabContactResolver resolver){
this.labContactResolver = resolver;
return this;
}
}
Expand Up @@ -18,6 +18,7 @@
import ch.elexis.core.data.util.Extensions;
import ch.elexis.core.exceptions.ElexisException;
import ch.elexis.core.importer.div.importers.HL7Parser;
import ch.elexis.core.importer.div.importers.ILabContactResolver;
import ch.elexis.core.importer.div.importers.IPersistenceHandler;
import ch.elexis.core.importer.div.importers.ImportHandler;
import ch.elexis.core.importer.div.importers.OverwriteAllImportHandler;
Expand Down Expand Up @@ -246,4 +247,15 @@ public IFileImportStrategy setMoveAfterImport(boolean value){
this.moveAfterImport = value;
return this;
}

/**
* Add the {@link ILabContactResolver} that should be used on import.
*
* @param resolver
* @return
*/
public IFileImportStrategy setLabContactResolver(ILabContactResolver resolver){
// currently no use for a contact resolver here
return this;
}
}

0 comments on commit 7831a54

Please sign in to comment.