Skip to content

Commit

Permalink
CNFT1-3400 API: Update API to handle Operators for City (#2002)
Browse files Browse the repository at this point in the history
* CNFT1-3400 API: Update API to handle Operators for City

* coverage

---------

Co-authored-by: Steven Urciuoli <[email protected]>
  • Loading branch information
stevegsa and Steven Urciuoli authored Nov 7, 2024
1 parent b966779 commit 67fd564
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,22 @@ NameCriteria withFirst(final TextCriteria first) {
}
}

public record LocationCriteria(TextCriteria street) {
public record LocationCriteria(TextCriteria street, TextCriteria city) {

Optional<TextCriteria> maybeStreet() {
return Optional.ofNullable(street());
}

Optional<TextCriteria> maybeCity() {
return Optional.ofNullable(city());
}

LocationCriteria withStreet(final TextCriteria street) {
return new LocationCriteria(street);
return new LocationCriteria(street, city());
}

LocationCriteria withCity(final TextCriteria city) {
return new LocationCriteria(street(), city);
}
}

Expand Down Expand Up @@ -299,7 +307,6 @@ public PatientFilter withLastName(final TextCriteria criteria) {

public PatientFilter withFirstName(final TextCriteria criteria) {
if (this.name == null) {

this.name = new NameCriteria(criteria, null);
} else {
this.name = this.name.withFirst(criteria);
Expand All @@ -312,7 +319,20 @@ public Optional<LocationCriteria> maybeLocation() {
}

public PatientFilter withStreet(final TextCriteria criteria) {
this.location = new LocationCriteria(criteria);
if (this.location == null) {
this.location = new LocationCriteria(criteria, null);
} else {
this.location = this.location.withStreet(criteria);
}
return this;
}

public PatientFilter withCity(final TextCriteria criteria) {
if (this.location == null) {
this.location = new LocationCriteria(null, criteria);
} else {
this.location = this.location.withCity(criteria);
}
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
class PatientLocationQueryResolver {
private static final String ADDRESS = "address";
private static final String STREET = "address.streetAddr1";
private static final String CITY = "address.city";

Stream<QueryVariant> resolve(final PatientFilter criteria) {
return criteria.maybeLocation().stream().flatMap(this::resolveLocationCriteria);
Expand All @@ -22,7 +23,10 @@ private Stream<QueryVariant> resolveLocationCriteria(final PatientFilter.Locatio
return Stream.of(
applyStreetEquals(criteria),
applyStreetContains(criteria),
applyStreetNotEquals(criteria))
applyStreetNotEquals(criteria),
applyCityEquals(criteria),
applyCityContains(criteria),
applyCityNotEquals(criteria))
.flatMap(Optional::stream);
}

Expand All @@ -44,4 +48,22 @@ private Optional<QueryVariant> applyStreetContains(final PatientFilter.LocationC
.map(value -> contains(ADDRESS, STREET, value));
}

private Optional<QueryVariant> applyCityEquals(final PatientFilter.LocationCriteria criteria) {
return criteria.maybeCity()
.flatMap(TextCriteria::maybeEquals)
.map(value -> equalTo(ADDRESS, CITY, value));
}

private Optional<QueryVariant> applyCityNotEquals(final PatientFilter.LocationCriteria criteria) {
return criteria.maybeCity()
.flatMap(TextCriteria::maybeNot)
.map(value -> notEquals(ADDRESS, CITY, value));
}

private Optional<QueryVariant> applyCityContains(final PatientFilter.LocationCriteria criteria) {
return criteria.maybeCity()
.flatMap(TextCriteria::maybeContains)
.map(value -> contains(ADDRESS, CITY, value));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ input PatientNameCriteria {

input LocationCriteria {
street: TextCriteria
city: TextCriteria
}

input PersonFilter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,19 @@ public void i_add_the_patient_criteria_for_a_street_address_that_contains(final
this.activeCriteria.active(criteria -> criteria.withStreet(TextCriteria.contains(value)));
}

@Given("I add the patient criteria for a city address that equals {string}")
public void i_add_the_patient_criteria_for_a_city_address_that_equals(final String value) {
this.activeCriteria.active(criteria -> criteria.withCity(TextCriteria.equals(value)));
}

@Given("I add the patient criteria for a city address that does not equal {string}")
public void i_add_the_patient_criteria_for_a_city_address_that_does_not_equal(final String value) {
this.activeCriteria.active(criteria -> criteria.withCity(TextCriteria.not(value)));
}

@Given("I add the patient criteria for a city address that contains {string}")
public void i_add_the_patient_criteria_for_a_city_address_that_contains(final String value) {
this.activeCriteria.active(criteria -> criteria.withCity(TextCriteria.contains(value)));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
@patient-search @patient-search-results
Feature: Searching patient's by street

Background:
Given I am logged into NBS
And I can "find" any "patient"
And I have a patient

Scenario: I can find the a patient with a city address that equals a value
And the patient has a "city" of "McLean"
Given I have another patient
And the patient has a "city" of "Chicago"
And patients are available for search
And I add the patient criteria for a city address that equals "McLean"
When I search for patients
Then search result 1 has a "city" of "McLean"
And there are 1 patient search results

Scenario: I can find the a patient with a city address that does not equal a value
And the patient has a "city" of "McLean"
Given I have another patient
And the patient has a "city" of "Chicago"
And patients are available for search
And I add the patient criteria for a city address that does not equal "McLean"
When I search for patients
Then search result 1 has a "city" of "Chicago"
And there are 1 patient search results

Scenario: I can find the a patient with a city address that contains a value
And the patient has a "city" of "McLean"
Given I have another patient
And the patient has a "city" of "Chicago"
And patients are available for search
And I add the patient criteria for a city address that contains "lea"
When I search for patients
Then search result 1 has a "city" of "McLean"
And there are 1 patient search results

Scenario: I can find the a patient with a city address and street address that equals a value
And the patient has a "city" of "McLean"
And the patient has an "address" of "124Street"
Given I have another patient
And the patient has a "city" of "Chicago"
And the patient has an "address" of "124Street"
And patients are available for search
And I add the patient criteria for a city address that equals "McLean"
And I add the patient criteria for a street address that equals "124Street"
When I search for patients
Then search result 1 has a "city" of "McLean"
And there are 1 patient search results
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,16 @@ Feature: Searching patient's by street
When I search for patients
Then search result 1 has a "address" of "123Street"
And there are 1 patient search results

Scenario: I can find the a patient with a street address and city address that equals a value
And the patient has a "city" of "McLean"
And the patient has an "address" of "124Street"
Given I have another patient
And the patient has a "city" of "Chicago"
And the patient has an "address" of "124Street"
And patients are available for search
And I add the patient criteria for a street address that equals "124Street"
And I add the patient criteria for a city address that equals "McLean"
When I search for patients
Then search result 1 has a "city" of "McLean"
And there are 1 patient search results
1 change: 1 addition & 0 deletions apps/modernization-ui/src/generated/graphql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ export enum LaboratoryReportStatus {
}

export type LocationCriteria = {
city?: InputMaybe<TextCriteria>;
street?: InputMaybe<TextCriteria>;
};

Expand Down
1 change: 1 addition & 0 deletions apps/modernization-ui/src/generated/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,7 @@ input PatientNameCriteria {

input LocationCriteria {
street: TextCriteria
city: TextCriteria
}

input PersonFilter {
Expand Down

0 comments on commit 67fd564

Please sign in to comment.