Skip to content

Commit

Permalink
Returning Resource Not Found 404 error
Browse files Browse the repository at this point in the history
Returning Resource Not Found 404 error if patientId is not valid
  • Loading branch information
netkraft authored Jun 27, 2023
1 parent 8a22269 commit 9073069
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import ca.uhn.fhir.rest.annotation.*;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.*;
import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.StringAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import org.hl7.fhir.instance.model.api.IBaseResource;
Expand All @@ -17,7 +20,6 @@
import org.hl7.fhir.r4.model.Patient.PatientLinkComponent;
import org.json.JSONArray;
import org.json.JSONObject;
import org.parboiled.common.StringUtils;
import org.sitenv.spring.configuration.AppConfig;
import org.sitenv.spring.model.DafPatient;
import org.sitenv.spring.service.PatientService;
Expand Down Expand Up @@ -67,23 +69,22 @@ public Class<? extends IBaseResource> getResourceType() {
public Patient readOrVread(@IdParam IdType theId) {
String id;
DafPatient dafPatient;
try {
id = theId.getIdPart();
} catch (NumberFormatException e) {
/*
* If we can't parse the ID as a long, it's not valid so this is an unknown resource
*/
throw new ResourceNotFoundException(theId);
}
id = theId.getIdPart();

if (theId.hasVersionIdPart()) {
// this is a vread
dafPatient = service.getPatientByVersionId(id, theId.getVersionIdPart());

} else {
// this is a read
dafPatient = service.getPatientById(id);
}
return createPatientObject(dafPatient);

if (dafPatient.getId() == null) {
throw new ResourceNotFoundException(theId);
}else{
return createPatientObject(dafPatient);

}
}

/**
Expand Down

0 comments on commit 9073069

Please sign in to comment.