-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[26164] add ExportAllEncounters to dbcheck
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...exis.core.ui.dbcheck/src/ch/elexis/core/ui/dbcheck/contributions/ExportAllEncounters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package ch.elexis.core.ui.dbcheck.contributions; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
|
||
import org.eclipse.core.runtime.IProgressMonitor; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import ch.elexis.core.model.ICoverage; | ||
import ch.elexis.core.model.IEncounter; | ||
import ch.elexis.core.model.IPatient; | ||
import ch.elexis.core.services.IQuery; | ||
import ch.elexis.core.services.IQueryCursor; | ||
import ch.elexis.core.services.holder.CoreModelServiceHolder; | ||
import ch.elexis.core.ui.dbcheck.external.ExternalMaintenance; | ||
import ch.elexis.core.utils.CoreUtil; | ||
import ch.elexis.scripting.CSVWriter; | ||
|
||
public class ExportAllEncounters extends ExternalMaintenance { | ||
|
||
@Override | ||
public String executeMaintenance(IProgressMonitor pm, String DBVersion) { | ||
File file = new File(CoreUtil.getWritableUserDir(), "ExportAllEncounters.csv"); | ||
IQuery<IPatient> patientsQuery = CoreModelServiceHolder.get().getQuery(IPatient.class); | ||
|
||
int exportCounter = 0; | ||
try (FileWriter fw = new FileWriter(file)) { | ||
CSVWriter csv = new CSVWriter(fw); | ||
String[] header = new String[] { "PatNr", "PatId", "KonsId", "KonsText" }; | ||
csv.writeNext(header); | ||
|
||
try (IQueryCursor<IPatient> cursor = patientsQuery.executeAsCursor()) { | ||
pm.beginTask("Bitte warten, alle Konsultationen werden exportieren", cursor.size()); | ||
while (cursor.hasNext()) { | ||
IPatient patient = cursor.next(); | ||
for (ICoverage coverage : patient.getCoverages()) { | ||
for (IEncounter encounter : coverage.getEncounters()) { | ||
csv.writeNext(new String[] { patient.getPatientNr(), patient.getId(), encounter.getId(), | ||
encounter.getHeadVersionInPlaintext() }); | ||
exportCounter++; | ||
} | ||
} | ||
pm.worked(1); | ||
} | ||
} | ||
csv.close(); | ||
} catch (IOException e) { | ||
LoggerFactory.getLogger(getClass()).error("Error writing csv"); | ||
return "Die CSV Datei konnte nicht erstellt werden."; | ||
} | ||
|
||
return "Es wurden " + exportCounter + " Konsultationen in die Datei [" + file.getAbsolutePath() | ||
+ "] geschrieben."; | ||
} | ||
|
||
@Override | ||
public String getMaintenanceDescription() { | ||
return "Alle Konsultationen als CSV exportieren."; | ||
} | ||
|
||
} |