Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class AppointmentDefaultResponse {
private HashMap extensions;
private String teleconsultationLink;
private String priority;
private String[] fulfillingEncounters = new String[0];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indentation seems to be off

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think our general standard is to use a List instead of an Array (ie List), is there a reason you use an Array here?


public String getUuid() {
return uuid;
Expand Down Expand Up @@ -203,4 +204,12 @@ public Date getDateAppointmentScheduled() {
public void setDateAppointmentScheduled(Date dateAppointmentScheduled) {
this.dateAppointmentScheduled = dateAppointmentScheduled;
}

public String[] getFulfillingEncounters() {
return fulfillingEncounters;
}

public void setFulfillingEncounters(String[] fulfillingEncounters) {
this.fulfillingEncounters = fulfillingEncounters;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class AppointmentRequest {
private String comments;
private List<AppointmentProviderDetail> providers = new ArrayList<>();
private String priority;
private String[] fulfillingEncounters = new String[0];

public String getAppointmentNumber() {
return appointmentNumber;
Expand Down Expand Up @@ -144,4 +145,12 @@ public Date getDateAppointmentScheduled() {
public void setDateAppointmentScheduled(Date dateAppointmentScheduled) {
this.dateAppointmentScheduled = dateAppointmentScheduled;
}

public String[] getFulfillingEncounters() {
return fulfillingEncounters;
}

public void setFulfillingEncounters(String[] fulfillingEncounters) {
this.fulfillingEncounters = fulfillingEncounters;
}
Comment on lines +149 to +155

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same applies to this block

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.Encounter;
import org.openmrs.Location;
import org.openmrs.Patient;
import org.openmrs.Provider;
import org.openmrs.api.EncounterService;
import org.openmrs.api.LocationService;
import org.openmrs.api.PatientService;
import org.openmrs.api.ProviderService;
Expand All @@ -30,11 +32,13 @@
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -59,6 +63,9 @@ public class AppointmentMapper {
@Autowired
AppointmentsService appointmentsService;

@Autowired
EncounterService encounterService;

@Autowired(required = false)
AppointmentResponseExtension appointmentResponseExtension;

Expand Down Expand Up @@ -118,6 +125,15 @@ public void mapAppointmentRequestToAppointment(AppointmentRequest appointmentReq
if (appointmentRequest.getPriority() != null || StringUtils.isNotBlank(appointmentRequest.getPriority())) {
appointment.setPriority(AppointmentPriority.valueOf(appointmentRequest.getPriority()));
}

if (appointmentRequest.getFulfillingEncounters().length > 0){
Set<Encounter> fulfillingEncounters = Arrays.stream(appointmentRequest.getFulfillingEncounters())
.map(encounterService::getEncounterByUuid)
.filter(Objects::nonNull)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way we can throw an error (or at least a warning) if an encounter is not found for uuid? This seems like something that shouldn't just fail silently.

.collect(Collectors.toSet());

appointment.setFulfillingEncounters(fulfillingEncounters);
}
mapProvidersForAppointment(appointment, appointmentRequest.getProviders());
}

Expand Down Expand Up @@ -239,6 +255,9 @@ private AppointmentDefaultResponse mapToDefaultResponse(Appointment a, Appointme
response.getExtensions().put("notificationResults", collect);
}
}
if(a.getFulfillingEncounters() != null && !a.getFulfillingEncounters().isEmpty()) {
response.setFulfillingEncounters(a.getFulfillingEncounters().stream().map(Encounter::getUuid).toArray(String[]::new));
}
return response;
}

Expand Down