From 4f12a8c526955ac285032e3b94ac355c27b10eef Mon Sep 17 00:00:00 2001 From: Pamela Canchanya Date: Tue, 1 Apr 2014 14:24:28 -0400 Subject: [PATCH] UHM-1172 Fix merge conflicts --- .../appointmentscheduling/Appointment.java | 29 ++++++++++--------- .../AppointmentStatusSerializer.java | 26 +++++++++++++++++ 2 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 api/src/main/java/org/openmrs/module/appointmentscheduling/serialize/AppointmentStatusSerializer.java diff --git a/api/src/main/java/org/openmrs/module/appointmentscheduling/Appointment.java b/api/src/main/java/org/openmrs/module/appointmentscheduling/Appointment.java index 9193f062..3df78a1f 100644 --- a/api/src/main/java/org/openmrs/module/appointmentscheduling/Appointment.java +++ b/api/src/main/java/org/openmrs/module/appointmentscheduling/Appointment.java @@ -13,18 +13,20 @@ */ package org.openmrs.module.appointmentscheduling; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; +import org.codehaus.jackson.map.annotate.JsonSerialize; import org.openmrs.BaseOpenmrsData; import org.openmrs.BaseOpenmrsMetadata; import org.openmrs.BaseOpenmrsObject; import org.openmrs.Patient; import org.openmrs.Visit; +import org.openmrs.module.appointmentscheduling.serialize.AppointmentStatusSerializer; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * It is a model class. It should extend either {@link BaseOpenmrsObject} or @@ -35,42 +37,41 @@ public class Appointment extends BaseOpenmrsData implements Serializable { private static final long serialVersionUID = 1L; // TODO confirm that "WALK-IN" should be considered active + @JsonSerialize(using = AppointmentStatusSerializer.class) public enum AppointmentStatus { SCHEDULED("Scheduled", false, false), RESCHEDULED("Rescheduled", false, false), WALKIN("Walk-In", false, true), CANCELLED( "Cancelled", true, false), WAITING("Waiting", false, true), INCONSULTATION("In-Consultation", false, true), COMPLETED( "Completed", false, false), MISSED("Missed", false, false), CANCELLED_AND_NEEDS_RESCHEDULE( "Cancelled and Needs Reschedule", true, false); - + private final String name; /** * Whether or not an appointment with this status should be considered "cancelled" Cancelled * statuses: CANCELLED, CANCELLED_AND_NEEDS_RESCHEDULE */ - private Boolean cancelled; + private boolean cancelled; /** * Whether or not an appointment with this status is an "active" appointment, where * active=patient checked-in and present within the health facility Active statuses: WALKIN, * WAITING, INCONSULTATION */ - private Boolean active; + private boolean active; - private AppointmentStatus(final String name, final Boolean cancelled, final Boolean active) { + private AppointmentStatus(final String name, final boolean cancelled, final boolean active) { this.name = name; this.cancelled = cancelled; this.active = active; } - + public String getName() { return this.name; } - - public Boolean isCancelled() { + public boolean isCancelled() { return this.cancelled; } - - public Boolean isActive() { + public boolean isActive() { return this.active; } diff --git a/api/src/main/java/org/openmrs/module/appointmentscheduling/serialize/AppointmentStatusSerializer.java b/api/src/main/java/org/openmrs/module/appointmentscheduling/serialize/AppointmentStatusSerializer.java new file mode 100644 index 00000000..54ad228e --- /dev/null +++ b/api/src/main/java/org/openmrs/module/appointmentscheduling/serialize/AppointmentStatusSerializer.java @@ -0,0 +1,26 @@ +package org.openmrs.module.appointmentscheduling.serialize; + +import org.codehaus.jackson.JsonGenerator; +import org.codehaus.jackson.JsonProcessingException; +import org.codehaus.jackson.map.JsonSerializer; +import org.codehaus.jackson.map.SerializerProvider; +import org.openmrs.module.appointmentscheduling.Appointment; + +import java.io.IOException; + +public class AppointmentStatusSerializer extends JsonSerializer { + + + @Override + public void serialize(Appointment.AppointmentStatus appointmentStatus, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException, JsonProcessingException { + + jsonGenerator.writeStartObject(); + jsonGenerator.writeFieldName("name"); + jsonGenerator.writeString(appointmentStatus.getName()); + jsonGenerator.writeFieldName("active"); + jsonGenerator.writeBoolean(appointmentStatus.isActive()); + jsonGenerator.writeFieldName("cancelled"); + jsonGenerator.writeBoolean(appointmentStatus.isActive()); + jsonGenerator.writeEndObject(); + } +}