use of ca.uhn.fhir.rest.annotation.Search in project gpconnect-demonstrator by nhsconnect.
the class MedicationAdministrationResourceProvider method getMedicationAdministrationsForPatientId.
@Search
public List<MedicationAdministration> getMedicationAdministrationsForPatientId(@RequiredParam(name = "patient") String patientId) {
ArrayList<MedicationAdministration> medicationAdministrations = new ArrayList<>();
List<MedicationAdministrationDetail> medicationAdministrationDetailList = medicationAdministrationSearch.findMedicationAdministrationForPatient(Long.parseLong(patientId));
if (medicationAdministrationDetailList != null && !medicationAdministrationDetailList.isEmpty()) {
for (MedicationAdministrationDetail medicationAdministrationDetail : medicationAdministrationDetailList) {
MedicationAdministration medicationAdministration = new MedicationAdministration();
String resourceId = String.valueOf(medicationAdministrationDetail.getId());
String versionId = String.valueOf(medicationAdministrationDetail.getLastUpdated().getTime());
String resourceType = medicationAdministration.getResourceType().toString();
IdType id = new IdType(resourceType, resourceId, versionId);
medicationAdministration.setId(id);
medicationAdministration.getMeta().setVersionId(versionId);
medicationAdministration.getMeta().setLastUpdated(medicationAdministrationDetail.getLastUpdated());
medicationAdministration.addDefinition(new Reference("Patient/" + medicationAdministrationDetail.getPatientId()));
medicationAdministration.addDefinition(new Reference("Practitioner/" + medicationAdministrationDetail.getPractitionerId()));
medicationAdministration.setPrescription(new Reference("MedicationOrder/" + medicationAdministrationDetail.getPrescriptionId()));
medicationAdministration.setEffective(new DateType(medicationAdministrationDetail.getAdministrationDate()));
medicationAdministration.setMedication(new Reference("Medication/" + medicationAdministrationDetail.getMedicationId()));
medicationAdministrations.add(medicationAdministration);
}
}
return medicationAdministrations;
}
use of ca.uhn.fhir.rest.annotation.Search in project gpconnect-demonstrator by nhsconnect.
the class OrganizationResourceProvider method getOrganizationsByODSCode.
@Search
public List<Organization> getOrganizationsByODSCode(@RequiredParam(name = Organization.SP_IDENTIFIER) TokenParam tokenParam, @Sort SortSpec sort, @Count Integer count) {
if (StringUtils.isBlank(tokenParam.getSystem()) || StringUtils.isBlank(tokenParam.getValue())) {
throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("Missing identifier token"), SystemCode.INVALID_PARAMETER, IssueType.INVALID);
}
if (tokenParam.getSystem().equals(SystemURL.ID_ODS_ORGANIZATION_CODE) || tokenParam.getSystem().equals(SystemURL.ID_ODS_OLD_ORGANIZATION_CODE)) {
List<Organization> organizationDetails = convertOrganizaitonDetailsListToOrganizationList(organizationSearch.findOrganizationDetailsByOrgODSCode(tokenParam.getValue()));
if (organizationDetails.isEmpty()) {
return null;
}
if (sort != null && sort.getParamName().equalsIgnoreCase(Location.SP_STATUS)) {
Collections.sort(organizationDetails, (Organization a, Organization b) -> {
String aStatus = a.getName();
String bStatus = b.getName();
if (aStatus == null && bStatus == null) {
return 0;
}
if (aStatus == null && bStatus != null) {
return -1;
}
if (aStatus != null && bStatus == null) {
return 1;
}
return aStatus.compareToIgnoreCase(bStatus);
});
}
// Update startIndex if we do paging
return count != null ? organizationDetails.subList(0, count) : organizationDetails;
} else {
throw OperationOutcomeFactory.buildOperationOutcomeException(new InvalidRequestException("Invalid system code"), SystemCode.INVALID_PARAMETER, IssueType.INVALID);
}
}
use of ca.uhn.fhir.rest.annotation.Search 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;
}
use of ca.uhn.fhir.rest.annotation.Search in project gpconnect-demonstrator by nhsconnect.
the class MedicationDispenseResourceProvider method getMedicationDispensesForPatientId.
@Search
public List<MedicationDispense> getMedicationDispensesForPatientId(@RequiredParam(name = "patient") String patientId) {
ArrayList<MedicationDispense> medicationDispenses = new ArrayList<>();
List<MedicationDispenseDetail> medicationDispenseDetailList = medicationDispenseSearch.findMedicationDispenseForPatient(Long.parseLong(patientId));
if (medicationDispenseDetailList != null && !medicationDispenseDetailList.isEmpty()) {
for (MedicationDispenseDetail medicationDispenseDetail : medicationDispenseDetailList) {
MedicationDispense medicationDispense = new MedicationDispense();
medicationDispense.setId(String.valueOf(medicationDispenseDetail.getId()));
medicationDispense.getMeta().setLastUpdated(medicationDispenseDetail.getLastUpdated());
medicationDispense.getMeta().setVersionId(String.valueOf(medicationDispenseDetail.getLastUpdated().getTime()));
switch(medicationDispenseDetail.getStatus().toLowerCase(Locale.UK)) {
case "completed":
medicationDispense.setStatus(MedicationDispenseStatus.COMPLETED);
break;
case "entered_in_error":
medicationDispense.setStatus(MedicationDispenseStatus.ENTEREDINERROR);
break;
case "in_progress":
medicationDispense.setStatus(MedicationDispenseStatus.INPROGRESS);
break;
case "on_hold":
medicationDispense.setStatus(MedicationDispenseStatus.ONHOLD);
break;
case "stopped":
medicationDispense.setStatus(MedicationDispenseStatus.STOPPED);
break;
}
medicationDispense.setSubject(new Reference("Patient/" + patientId));
medicationDispense.setAuthorizingPrescription(Collections.singletonList(new Reference("MedicationOrder/" + medicationDispenseDetail.getMedicationOrderId())));
Medication medication = new Medication();
Coding coding = new Coding();
coding.setCode(String.valueOf(medicationDispenseDetail.getMedicationId()));
coding.setDisplay(medicationDispenseDetail.getMedicationName());
CodeableConcept codeableConcept = new CodeableConcept();
codeableConcept.setCoding(Collections.singletonList(coding));
medication.setCode(codeableConcept);
medicationDispense.addDosageInstruction().setText(medicationDispenseDetail.getDosageText());
medicationDispenses.add(medicationDispense);
}
}
return medicationDispenses;
}
use of ca.uhn.fhir.rest.annotation.Search in project gpconnect-demonstrator by nhsconnect.
the class MedicationOrderResourceProvider method getMedicationOrdersForPatientId.
@Search
public List<MedicationRequest> getMedicationOrdersForPatientId(@RequiredParam(name = "patient") String patientId) {
ArrayList<MedicationRequest> medicationOrders = new ArrayList<>();
List<MedicationOrderDetails> medicationOrderDetailsList = medicationOrderSearch.findMedicationOrdersForPatient(Long.parseLong(patientId));
if (medicationOrderDetailsList != null && !medicationOrderDetailsList.isEmpty()) {
for (MedicationOrderDetails medicationOrderDetails : medicationOrderDetailsList) {
medicationOrders.add(medicationOrderDetailsToMedicationOrderResourceConverter(medicationOrderDetails));
}
}
return medicationOrders;
}
Aggregations