package info.elexis.server.core.connector.elexis.services;

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

import ch.elexis.core.types.Gender;
import ch.rgw.tools.TimeTool;
import info.elexis.server.core.connector.elexis.jpa.model.annotated.Behandlung;
import info.elexis.server.core.connector.elexis.jpa.model.annotated.Fall;
import info.elexis.server.core.connector.elexis.jpa.model.annotated.Kontakt;
import info.elexis.server.core.connector.elexis.jpa.model.annotated.Verrechnet;

public abstract class AbstractServiceTest {

	public List<Kontakt> testContacts = new ArrayList<Kontakt>();
	public List<Kontakt> testPatients = new ArrayList<Kontakt>();
	public List<Fall> testFaelle = new ArrayList<Fall>();
	public List<Behandlung> testBehandlungen = new ArrayList<Behandlung>();

	public void createTestMandantPatientFallBehandlung() {
		TimeTool timeTool = new TimeTool();
		Kontakt mandator = new KontaktService.PersonBuilder("mandator1 " + timeTool.toString(),
				"Anton" + timeTool.toString(), timeTool.toLocalDate(), Gender.MALE).mandator().buildAndSave();
		testContacts.add(mandator);

		Kontakt patient = new KontaktService.PersonBuilder("Armer", "Anton" + timeTool.toString(),
				timeTool.toLocalDate(), Gender.MALE).buildAndSave();
		testPatients.add(patient);

		Fall testFall = new FallService.Builder(patient, "Fallbezeichnung", "Fallgrund", "KVG").buildAndSave();
		testFaelle.add(testFall);

		Behandlung behandlung = new BehandlungService.Builder(testFall, mandator).buildAndSave();
		testBehandlungen.add(behandlung);
	}

	public void cleanup() {
		for (Behandlung cons : testBehandlungen) {
			List<Verrechnet> verrechnet = VerrechnetService.getAllVerrechnetForBehandlung(cons);
			for (Verrechnet verrechnet2 : verrechnet) {
				System.out
						.println("Deleting verrechnet " + verrechnet2.getLabel() + " on behandlung " + cons.getLabel());
				VerrechnetService.remove(verrechnet2);
			}

			System.out.println("Deleting behandlung " + cons.getLabel());
			BehandlungService.remove(cons);
		}
		for (Fall fall : testFaelle) {
			System.out.println("Removing fall " + fall.getLabel());
			FallService.remove(fall);
		}
		for (Kontakt contact : testPatients) {
			System.out.println("Removing patient " + contact.getLabel());
			PersistenceService.remove(contact);
		}
		for (Kontakt contact : testContacts) {
			System.out.println("Removing contact " + contact.getLabel());
			PersistenceService.remove(contact);
		}
	}

}

@@ -1772,26 +1772,24 @@
 %09%09%09%09%09%09.print
-ln
 (%22Deleting v
@@ -1908,16 +1908,49 @@
 hnet2);%0A
+%09%09%09%09System.out.println(%22 %5BOK%5D%22);%0A
 %09%09%09%7D%0A%0A%09%09
@@ -1966,18 +1966,16 @@
 ut.print
-ln
 (%22Deleti
@@ -2045,16 +2045,48 @@
 (cons);%0A
+%09%09%09System.out.println(%22 %5BOK%5D%22);%0A
 %09%09%7D%0A%09%09fo
@@ -2125,34 +2125,32 @@
 System.out.print
-ln
 (%22Removing fall 
@@ -2200,16 +2200,48 @@
 (fall);%0A
+%09%09%09System.out.println(%22 %5BOK%5D%22);%0A
 %09%09%7D%0A%09%09fo
@@ -2288,34 +2288,32 @@
 System.out.print
-ln
 (%22Removing patie
@@ -2375,24 +2375,56 @@
 e(contact);%0A
+%09%09%09System.out.println(%22 %5BOK%5D%22);%0A
 %09%09%7D%0A%09%09for (K
@@ -2475,18 +2475,16 @@
 ut.print
-ln
 (%22Removi
@@ -2558,16 +2558,48 @@
 ntact);%0A
+%09%09%09System.out.println(%22 %5BOK%5D%22);%0A
 %09%09%7D%0A%09%7D%0A%0A

Enhance system out message in test entity removal