use of ca.uhn.fhir.rest.param.TokenParam in project gpconnect-demonstrator by nhsconnect.
the class SlotResourceProvider method getSlotByIds.
@Search
public Bundle getSlotByIds(@RequiredParam(name = "start") DateParam startDate, @RequiredParam(name = "end") DateParam endDate, @RequiredParam(name = "status") String status, @OptionalParam(name = "searchFilter") TokenAndListParam searchFilters, @IncludeParam(allow = { "Slot:schedule", "Schedule:actor:Practitioner", "Schedule:actor:Location", "Location:managingOrganization" }) Set<Include> theIncludes) {
boolean foundSchedule = false;
for (Include anInclude : theIncludes) {
// getParamName returns any text between the first and second colons
if (anInclude.getParamName().equals("schedule")) {
foundSchedule = true;
break;
}
}
if (!foundSchedule) {
// TODO check not invalid parameter?
throwInvalidRequest400_BadRequestException("No include Slot:schedule parameter has been provided");
}
Bundle bundle = new Bundle();
String bookingOdsCode = "";
String bookingOrgType = "";
if (!status.equals("free")) {
throwUnprocessableEntityInvalid422_ParameterException("Status incorrect: Must be equal to free");
}
try {
startDate.isEmpty();
endDate.isEmpty();
} catch (Exception e) {
throwUnprocessableEntityInvalid422_ParameterException("Start Date and End Date must be populated with a correct date format");
}
if (startDate.getPrefix() != ParamPrefixEnum.GREATERTHAN_OR_EQUALS || endDate.getPrefix() != ParamPrefixEnum.LESSTHAN_OR_EQUALS) {
throwUnprocessableEntityInvalid422_ParameterException("Invalid Prefix used");
}
validateStartDateParamAndEndDateParam(startDate, endDate);
if (searchFilters != null) {
List<TokenOrListParam> searchFilter = searchFilters.getValuesAsQueryTokens();
for (TokenOrListParam filter : searchFilter) {
TokenParam token = filter.getValuesAsQueryTokens().get(0);
if (token.getSystem().equals(SystemURL.VS_GPC_ORG_TYPE)) {
bookingOrgType = token.getValue();
}
if (token.getSystem().equals(SystemURL.ID_ODS_ORGANIZATION_CODE)) {
bookingOdsCode = token.getValue();
}
}
}
boolean actorPractitioner = false;
boolean actorLocation = false;
boolean managingOrganisation = false;
for (Include include : theIncludes) {
switch(include.getValue()) {
case "Schedule:actor:Practitioner":
actorPractitioner = true;
break;
case "Schedule:actor:Location":
actorLocation = true;
break;
case "Location:managingOrganization":
managingOrganisation = true;
break;
}
}
startDate.getValueAsInstantDt().getValue();
getScheduleOperation.populateBundle(bundle, new OperationOutcome(), startDate.getValueAsInstantDt().getValue(), endDate.getValueAsInstantDt().getValue(), actorPractitioner, actorLocation, managingOrganisation, bookingOdsCode, bookingOrgType);
return bundle;
}
Aggregations