Commit 0e766204 authored by Marco Descher's avatar Marco Descher 🏔

[16258] IAppointmentService#getAreas

parent 5cf2c9a9
Pipeline #12079 passed with stages
in 4 minutes and 57 seconds
......@@ -2,6 +2,7 @@ package ch.elexis.core.services;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
......@@ -15,6 +16,8 @@ import org.osgi.service.component.annotations.Reference;
import ch.elexis.core.model.IAppointment;
import ch.elexis.core.model.Messages;
import ch.elexis.core.model.ModelPackage;
import ch.elexis.core.model.agenda.Area;
import ch.elexis.core.model.agenda.AreaType;
import ch.elexis.core.model.builder.IAppointmentBuilder;
import ch.elexis.core.services.IQuery.COMPARATOR;
import ch.elexis.core.services.holder.ConfigServiceHolder;
......@@ -29,7 +32,10 @@ public class AppointmentService implements IAppointmentService {
public static final String AG_TERMINTYPEN = "agenda/TerminTypen"; //$NON-NLS-1$
public static final String AG_TERMINSTATUS = "agenda/TerminStatus"; //$NON-NLS-1$
public static final String AG_BEREICHE = "agenda/bereiche"; //$NON-NLS-1$
public static final String AG_BEREICH_PREFIX = "agenda/bereich/"; //$NON-NLS-1$
public static final String AG_BEREICH_TYPE_POSTFIX = "/type"; //$NON-NLS-1$
private static final int TYPE_FREE = 0; //frei
private static final int TYPE_RESERVED = 1; //reserviert
private static final int TYPE_DEFAULT = 2; //standard
......@@ -49,18 +55,15 @@ public class AppointmentService implements IAppointmentService {
@Override
public IAppointment clone(IAppointment appointment){
/**
* DEPRECATED JPA
// Termin ret =
// new Termin(get(FLD_BEREICH), get(FLD_TAG), getStartMinute(), getStartMinute()
// + getDauer(), getType(), getStatus(), get(FLD_PRIORITY));
// Kontakt k = getKontakt();
// if (k != null) {
// ret.setKontakt(getKontakt());
// }
// return ret;
* **/
return new IAppointmentBuilder(iModelService, appointment.getSchedule(), appointment.getStartTime(), appointment.getEndTime(),
appointment.getType(), appointment.getState(), appointment.getPriority(), appointment.getSubjectOrPatient()).buildAndSave();
* DEPRECATED JPA // Termin ret = // new Termin(get(FLD_BEREICH), get(FLD_TAG),
* getStartMinute(), getStartMinute() // + getDauer(), getType(), getStatus(),
* get(FLD_PRIORITY)); // Kontakt k = getKontakt(); // if (k != null) { //
* ret.setKontakt(getKontakt()); // } // return ret;
**/
return new IAppointmentBuilder(iModelService, appointment.getSchedule(),
appointment.getStartTime(), appointment.getEndTime(), appointment.getType(),
appointment.getState(), appointment.getPriority(), appointment.getSubjectOrPatient())
.buildAndSave();
}
@Activate
......@@ -77,7 +80,7 @@ public class AppointmentService implements IAppointmentService {
}
}
private List<IAppointment> getLinkedAppoinments(IAppointment orig){
private List<IAppointment> getLinkedAppoinments(IAppointment orig){
if (StringTool.isNothing(orig.getLinkgroup())) {
return Collections.singletonList(orig);
}
......@@ -100,8 +103,7 @@ public class AppointmentService implements IAppointmentService {
iModelService.delete(linked.get(0));
} else {
if (appointment.getId().equals(appointment.getLinkgroup())) {
if (linked.size() > 1)
{
if (linked.size() > 1) {
int index = 0;
IAppointment moveto = linked.get(index);
while (moveto.getId().equals(appointment.getLinkgroup())) {
......@@ -111,7 +113,7 @@ public class AppointmentService implements IAppointmentService {
moveto.setReason(appointment.getReason());
//TODO created by not working
//moveto.set(Termin.FLD_CREATOR, get(Termin.FLD_CREATOR));
moveto.setCreatedBy(appointment.getCreatedBy());
moveto.setCreatedBy(appointment.getCreatedBy());
moveto.setExtension(appointment.getExtension());
iModelService.save(moveto);
......@@ -129,69 +131,29 @@ public class AppointmentService implements IAppointmentService {
}
return true;
/**
* DEPRECATED JPA
// boolean confirmed = !askForConfirmation;
// if (checkLock()) {
// return false;
// }
// String linkgroup = get(FLD_LINKGROUP); //$NON-NLS-1$
// boolean isLinked = linkgroup != null && !linkgroup.isEmpty();
//
// if (isLinked && askForConfirmation) {
// MessageDialog msd =
// new MessageDialog(UiDesk.getTopShell(), Messages.Termin_deleteSeries, null,
// Messages.Termin_thisAppIsPartOfSerie, MessageDialog.QUESTION, new String[] {
// Messages.Termin_yes, Messages.Termin_no
// }, 1);
// int retval = msd.open();
// if (retval == SWT.DEFAULT)
// {
// return false;
// }
// confirmed = (retval == Dialog.OK);
// }
// if (isLinked) {
// List<Termin> linked = getLinked(this);
// if (confirmed) {
// // delete whole series
// for (Termin ae : (List<Termin>) linked) {
// ae.set(new String[] {
// FLD_LASTEDIT, FLD_DELETED
// }, new String[] {
// createTimeStamp(), StringConstants.ONE
// });
// }
// } else {
// if (getId().equals(linkgroup)) {
// // move root information
// if (linked.size() > 1) {
// int index = 0;
// Termin moveto = linked.get(index);
// while (moveto.getId().equals(linkgroup)) {
// moveto = linked.get(++index);
// }
// moveto.set(Termin.FLD_PATIENT, get(Termin.FLD_PATIENT));
// moveto.set(Termin.FLD_GRUND, get(Termin.FLD_GRUND));
// moveto.set(Termin.FLD_CREATOR, get(Termin.FLD_CREATOR));
// moveto.set(Termin.FLD_EXTENSION, get(Termin.FLD_EXTENSION));
// for (Termin termin : linked) {
// termin.set(Termin.FLD_LINKGROUP, moveto.getId());
// }
// }
// }
// // delete this
// set(new String[] {
// FLD_DELETED, FLD_LASTEDIT
// }, StringConstants.ONE, createTimeStamp());
// }
// } else {
// // delete this
// set(new String[] {
// FLD_DELETED, FLD_LASTEDIT
// }, StringConstants.ONE, createTimeStamp());
// }
// return true;
**/
* DEPRECATED JPA // boolean confirmed = !askForConfirmation; // if (checkLock()) { //
* return false; // } // String linkgroup = get(FLD_LINKGROUP); //$NON-NLS-1$ // boolean
* isLinked = linkgroup != null && !linkgroup.isEmpty(); // // if (isLinked &&
* askForConfirmation) { // MessageDialog msd = // new MessageDialog(UiDesk.getTopShell(),
* Messages.Termin_deleteSeries, null, // Messages.Termin_thisAppIsPartOfSerie,
* MessageDialog.QUESTION, new String[] { // Messages.Termin_yes, Messages.Termin_no // },
* 1); // int retval = msd.open(); // if (retval == SWT.DEFAULT) // { // return false; // }
* // confirmed = (retval == Dialog.OK); // } // if (isLinked) { // List<Termin> linked =
* getLinked(this); // if (confirmed) { // // delete whole series // for (Termin ae :
* (List<Termin>) linked) { // ae.set(new String[] { // FLD_LASTEDIT, FLD_DELETED // }, new
* String[] { // createTimeStamp(), StringConstants.ONE // }); // } // } else { // if
* (getId().equals(linkgroup)) { // // move root information // if (linked.size() > 1) { //
* int index = 0; // Termin moveto = linked.get(index); // while
* (moveto.getId().equals(linkgroup)) { // moveto = linked.get(++index); // } //
* moveto.set(Termin.FLD_PATIENT, get(Termin.FLD_PATIENT)); // moveto.set(Termin.FLD_GRUND,
* get(Termin.FLD_GRUND)); // moveto.set(Termin.FLD_CREATOR, get(Termin.FLD_CREATOR)); //
* moveto.set(Termin.FLD_EXTENSION, get(Termin.FLD_EXTENSION)); // for (Termin termin :
* linked) { // termin.set(Termin.FLD_LINKGROUP, moveto.getId()); // } // } // } // //
* delete this // set(new String[] { // FLD_DELETED, FLD_LASTEDIT // }, StringConstants.ONE,
* createTimeStamp()); // } // } else { // // delete this // set(new String[] { //
* FLD_DELETED, FLD_LASTEDIT // }, StringConstants.ONE, createTimeStamp()); // } // return
* true;
**/
}
@Override
......@@ -201,7 +163,7 @@ public class AppointmentService implements IAppointmentService {
query.and("tag", COMPARATOR.EQUALS, date);
List<IAppointment> resList = query.execute();
String typReserved = getType(AppointmentType.BOOKED);
String stateEmpty = getState(AppointmentState.EMPTY);
String stateDefault = getState(AppointmentState.DEFAULT);
......@@ -233,7 +195,7 @@ public class AppointmentService implements IAppointmentService {
LocalDateTime startTime =
date.atStartOfDay().plusMinutes(TimeTool.getMinutesFromTimeString(from));
LocalDateTime endTime =
date.atStartOfDay().plusMinutes(TimeTool.getMinutesFromTimeString(until));
date.atStartOfDay().plusMinutes(TimeTool.getMinutesFromTimeString(until));
iAppointment.setStartTime(startTime);
iAppointment.setType(typReserved);
iAppointment.setState(stateEmpty);
......@@ -294,4 +256,22 @@ public class AppointmentService implements IAppointmentService {
iConfigService.set(AG_TERMINSTATUS, tt);
states = iConfigService.getAsList(AG_TERMINSTATUS, null);
}
@Override
public List<Area> getAreas(){
List<Area> ret = new ArrayList<>();
List<String> areas = iConfigService.getAsList(AG_BEREICHE, null);
areas.forEach(entry -> {
String typeString =
iConfigService.get(AG_BEREICH_PREFIX + entry + AG_BEREICH_TYPE_POSTFIX, null);
AreaType type = AreaType.GENERIC;
String contactId = null;
if (typeString != null) {
type = AreaType.CONTACT;
contactId = typeString.substring(AreaType.CONTACT.name().length() + 1);
}
ret.add(new Area(entry, type, contactId));
});
return ret;
}
}
package ch.elexis.core.model.agenda;
public class Area {
private final String name;
private final AreaType type;
private final String contactId;
/**
*
* @param name
* the name of the area
* @param type
* @param contactId
* <code>null</code> if {@link AreaType#GENERIC}, else the contact id
*/
public Area(String name, AreaType type, String contactId){
this.name = name;
this.type = type;
this.contactId = contactId;
}
public String getName(){
return name;
}
public AreaType getType(){
return type;
}
public String getContactId(){
return contactId;
}
}
package ch.elexis.core.services;
import java.time.LocalDate;
import java.util.List;
import ch.elexis.core.model.IAppointment;
import ch.elexis.core.model.agenda.Area;
import ch.elexis.core.types.AppointmentState;
import ch.elexis.core.types.AppointmentType;
......@@ -28,7 +30,7 @@ public interface IAppointmentService {
public boolean delete(IAppointment appointment, boolean whole);
/**
* Updates the boundaries and check whether the only entries are appointments if yes also check
* Updates the boundaries and check whether the only entries are appointments if yes also check
* whether some boundaries are missing
*
* @param schedule
......@@ -65,4 +67,11 @@ public interface IAppointmentService {
* @param periodType
*/
public void addState(String state);
/**
* Get all defined areas.
*
* @return
*/
public List<Area> getAreas();
}
......@@ -16,10 +16,11 @@ import ch.elexis.core.utils.OsgiServiceUtil;
@RunWith(Suite.class)
@SuiteClasses({
AccessControlServiceTest.class, IConfigServiceTest.class, IElexisEnvironmentServiceTest.class,
ILabServiceTest.class, IStoreToStringServiceTest.class, IStickerServiceTest.class,
IAppointmentServiceTest.class, IUserServiceTest.class, IMessageServiceTest.class,
IVirtualFilesystemServiceTest.class, IXidServiceTest.class, IMedicationServiceTest.class
AccessControlServiceTest.class, IAppointmentServiceTest.class, IConfigServiceTest.class,
IElexisEnvironmentServiceTest.class, ILabServiceTest.class, IStoreToStringServiceTest.class,
IStickerServiceTest.class, IAppointmentServiceTest.class, IUserServiceTest.class,
IMessageServiceTest.class, IVirtualFilesystemServiceTest.class, IXidServiceTest.class,
IMedicationServiceTest.class
})
public class AllServiceTests {
......
......@@ -13,9 +13,12 @@ import java.util.stream.Collectors;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import ch.elexis.core.model.IAppointment;
import ch.elexis.core.model.agenda.Area;
import ch.elexis.core.model.agenda.AreaType;
import ch.elexis.core.model.builder.IAppointmentBuilder;
import ch.elexis.core.services.IQuery.COMPARATOR;
import ch.elexis.core.types.AppointmentState;
......@@ -27,6 +30,13 @@ public class IAppointmentServiceTest extends AbstractServiceTest {
private IAppointmentService appointmentService = OsgiServiceUtil.getService(IAppointmentService.class).get();
private IAppointment savedAppointment;
@BeforeClass
public static void beforeClass() {
IConfigService iConfigService = OsgiServiceUtil.getService(IConfigService.class).get();
iConfigService.set("agenda/bereiche", "Notfall,MPA,OP,Arzt 1,Arzt 2");
iConfigService.set("agenda/bereich/Arzt 1/type", "CONTACT/be5370812884c8fc5019123");
}
@Before
public void before(){
savedAppointment = new IAppointmentBuilder(coreModelService, "Notfall", LocalDateTime.of(2018, 01, 02, 9, 0), LocalDateTime.of(2018, 01, 02, 9, 30),
......@@ -95,6 +105,20 @@ public class IAppointmentServiceTest extends AbstractServiceTest {
//@todo delete with linkgroup
}
@Test
public void getAreas() {
List<Area> areas = appointmentService.getAreas();
assertEquals(5, areas.size());
for (Area area : areas) {
if("Arzt 1".equals(area.getName())) {
assertEquals(AreaType.CONTACT, area.getType());
assertEquals("be5370812884c8fc5019123", area.getContactId());
} else {
assertEquals(AreaType.GENERIC, area.getType());
}
}
}
@After
public void after(){
//cleanup
......
......@@ -2,6 +2,7 @@ package ch.elexis.core.services;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.List;
......@@ -47,6 +48,9 @@ public class IStickerServiceTest extends AbstractServiceTest {
List<ISticker> patientStickers = service.getStickers(patient.get());
assertFalse(patientStickers.isEmpty());
assertTrue(patientStickers.contains(newSticker));
for (ISticker iSticker : patientStickers) {
assertNotNull(iSticker.getLastupdate());
}
service.removeSticker(newSticker, patient.get());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment