Skip to content

Commit

Permalink
Implement _id for /Patient
Browse files Browse the repository at this point in the history
Plus some minor code simplification.
  • Loading branch information
shabiel committed Nov 15, 2019
1 parent fa30ce1 commit 1bacb96
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.Path;
import javax.ws.rs.Produces;
Expand Down Expand Up @@ -317,6 +318,7 @@ public List<CarePlan> findCarePlans(@IdParam IdType theId) {

@Search
public Bundle getAllPatients(
@OptionalParam(name = "_id") final StringParam _id,
@OptionalParam(name = Patient.SP_IDENTIFIER) final StringParam identifier,
@OptionalParam(name = Patient.SP_NAME) final StringParam name,
@OptionalParam(name = Patient.SP_GENDER) final StringParam gender,
Expand All @@ -333,15 +335,9 @@ public Bundle getAllPatients(
Bundle bundle = createBundle(String.format("%s/%s", request.getFhirServerBase(), request.getRequestPath()));

HashMap<String, String> options = new HashMap<String, String>();
if (identifier != null) options.put(Patient.SP_IDENTIFIER, identifier.getValue());
if (name != null) options.put(Patient.SP_NAME, name.getValue());
if (gender != null) options.put(Patient.SP_GENDER, gender.getValue());
if (family != null) options.put(Patient.SP_FAMILY, family.getValue());
if (given != null) options.put(Patient.SP_GIVEN, given.getValue());
if (dob != null) options.put(Patient.SP_BIRTHDATE, dob.getValueAsString());
if (count != null) options.put(Constants.PARAM_COUNT, count.getValue().toPlainString());
// page is not a FHIR standard thing; but our own. FHIR doesn't have it.
if (page != null) options.put("_page", page.getValue().toPlainString());
for (Map.Entry<String, String[]> entry: request.getParameters().entrySet()) {
options.put(entry.getKey(), entry.getValue()[0]);
}

List<Patient> results = service.getAllPatients(options);

Expand All @@ -357,14 +353,17 @@ public Bundle getAllPatients(

bundle.setTotal(results.size());

// if a single patient was requested, no reason to try to return next/
// prev page links
if (_id != null || identifier != null) return bundle;

Bundle.BundleLinkComponent nextlink = new Bundle.BundleLinkComponent();
Bundle.BundleLinkComponent prevlink = new Bundle.BundleLinkComponent();
List<Bundle.BundleLinkComponent> links = new ArrayList<>();
String baseUrl = bundle.getLink(Constants.LINK_SELF).getUrl();
String urlWithParameters = baseUrl + "?";

FhirContext c = getFhirContext();
if (identifier != null) urlWithParameters += Patient.SP_IDENTIFIER + "=" + identifier.getValueAsQueryToken(c) + "&";
if (name != null) urlWithParameters += Patient.SP_NAME + "=" + name.getValueAsQueryToken(c) + "&";
if (gender != null) urlWithParameters += Patient.SP_GENDER + "=" + gender.getValueAsQueryToken(c) + "&";
if (family != null) urlWithParameters += Patient.SP_FAMILY + "=" + family.getValueAsQueryToken(c) + "&";
Expand Down

0 comments on commit 1bacb96

Please sign in to comment.