Skip to content

Commit

Permalink
Options API Jurisdictions and Program Areas (#1519)
Browse files Browse the repository at this point in the history
* jurisdiction api

* Program Areas
  • Loading branch information
adamloup-enquizit authored Jul 3, 2024
1 parent b5a18a6 commit 85965c1
Show file tree
Hide file tree
Showing 16 changed files with 596 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/modernization-ui/src/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export { ConditionOptionsService } from './services/ConditionOptionsService';
export { ConfigurationControllerService } from './services/ConfigurationControllerService';
export { EncryptionControllerService } from './services/EncryptionControllerService';
export { FacilityOptionsService } from './services/FacilityOptionsService';
export { JurisdictionOptionsService } from './services/JurisdictionOptionsService';
export { LoginService } from './services/LoginService';
export { PatientRaceService } from './services/PatientRaceService';
export { ProgramAreaOptionsService } from './services/ProgramAreaOptionsService';
export { ProviderOptionsService } from './services/ProviderOptionsService';
export { ResultedTestOptionsService } from './services/ResultedTestOptionsService';
export { UserService } from './services/UserService';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { Option } from '../models/Option';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
export class JurisdictionOptionsService {
/**
* NBS Jurisdiction Option Autocomplete
* Provides options from Facilities that have a name matching a criteria.
* @returns Option OK
* @throws ApiError
*/
public static jurisdictionAutocomplete({
criteria,
limit = 15,
}: {
criteria: string,
limit?: number,
}): CancelablePromise<Array<Option>> {
return __request(OpenAPI, {
method: 'GET',
url: '/nbs/api/options/jurisdictions/search',
query: {
'criteria': criteria,
'limit': limit,
},
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* generated using openapi-typescript-codegen -- do not edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */
import type { Option } from '../models/Option';
import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
import { request as __request } from '../core/request';
export class ProgramAreaOptionsService {
/**
* NBS Program Area Option Autocomplete
* Provides options from Facilities that have a name matching a criteria.
* @returns Option OK
* @throws ApiError
*/
public static programAreaAutocomplete({
criteria,
limit = 15,
}: {
criteria: string,
limit?: number,
}): CancelablePromise<Array<Option>> {
return __request(OpenAPI, {
method: 'GET',
url: '/nbs/api/options/program-areas/search',
query: {
'criteria': criteria,
'limit': limit,
},
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package gov.cdc.nbs.option.jurisdictions.autocomplete;

import gov.cdc.nbs.option.Option;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;

@RestController
@RequestMapping("nbs/api/options/jurisdictions/search")
class JurisdictionOptionAutocompleteController {

private final JurisdictionOptionResolver resolver;

JurisdictionOptionAutocompleteController(final JurisdictionOptionResolver finder) {
this.resolver = finder;
}

@Operation(
operationId = "jurisdiction-autocomplete",
summary = "NBS Jurisdiction Option Autocomplete",
description = "Provides options from Facilities that have a name matching a criteria.",
tags = "JurisdictionOptions"
)
@GetMapping
Collection<Option> complete(
@RequestParam final String criteria,
@RequestParam(defaultValue = "15"
) final int limit) {
return this.resolver.resolve(criteria, limit);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package gov.cdc.nbs.option.jurisdictions.autocomplete;

import gov.cdc.nbs.option.jdbc.autocomplete.SQLBasedOptionResolver;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

@Component
class JurisdictionOptionResolver extends SQLBasedOptionResolver {

private static final String QUERY = """
select
code as [value],
code_short_desc_txt as [name],
indent_level_nbr as [order]
from [NBS_SRTE].[dbo].Jurisdiction_code
where status_cd = 'A'
and code_short_desc_txt like :criteria
order by
indent_level_nbr
offset 0 rows
fetch next :limit rows only
""";

JurisdictionOptionResolver(final NamedParameterJdbcTemplate template) {
super(QUERY, template);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package gov.cdc.nbs.option.program.area.autocomplete;

import gov.cdc.nbs.option.Option;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;

@RestController
@RequestMapping("nbs/api/options/program-areas/search")
class ProgramAreaOptionAutocompleteController {

private final ProgramAreaOptionResolver resolver;

ProgramAreaOptionAutocompleteController(final ProgramAreaOptionResolver finder) {
this.resolver = finder;
}

@Operation(
operationId = "program-area-autocomplete",
summary = "NBS Program Area Option Autocomplete",
description = "Provides options from Facilities that have a name matching a criteria.",
tags = "ProgramAreaOptions"
)
@GetMapping
Collection<Option> complete(
@RequestParam final String criteria,
@RequestParam(defaultValue = "15") final int limit
) {
return this.resolver.resolve(criteria, limit);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package gov.cdc.nbs.option.program.area.autocomplete;

import gov.cdc.nbs.option.jdbc.autocomplete.SQLBasedOptionResolver;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

@Component
class ProgramAreaOptionResolver extends SQLBasedOptionResolver {

private static final String QUERY = """
select
prog_area_cd as [value],
prog_area_desc_txt as [name],
nbs_uid as [order]
from [NBS_SRTE].[dbo].Program_area_code
where status_cd = 'A'
and prog_area_desc_txt like :criteria
order by
nbs_uid
offset 0 rows
fetch next :limit rows only
""";

ProgramAreaOptionResolver(final NamedParameterJdbcTemplate template) {
super(QUERY, template);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package gov.cdc.nbs.option;

import org.springframework.stereotype.Component;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;

@Component
public class AutocompleteRequester {

private final MockMvc mvc;

AutocompleteRequester(final MockMvc mvc) {
this.mvc = mvc;
}

public ResultActions complete(final String name, final String criteria) throws Exception {
return mvc.perform(
get("/nbs/api/options/{name}/search", name)
.param("criteria", criteria))
.andDo(print());
}

public ResultActions complete(final String name, final String criteria, final int limit) throws Exception {
return mvc.perform(
get("/nbs/api/options/{name}/search", name)
.param("criteria", criteria)
.param("limit", String.valueOf(limit)))
.andDo(print());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package gov.cdc.nbs.option.jurisdiction;

import gov.cdc.nbs.option.Option;
import gov.cdc.nbs.testing.support.Available;
import io.cucumber.spring.ScenarioScope;
import jakarta.annotation.PreDestroy;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.sql.PreparedStatement;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Component
@ScenarioScope
class JurisdictionMother {

private static final String DELETE_IN = """
delete
from NBS_SRTE.[dbo].Jurisdiction_code
where code in (:codes)
""";

private static final String CREATE = """
insert into NBS_SRTE.[dbo].Jurisdiction_code(
code,
code_short_desc_txt,
indent_level_nbr,
status_cd,
type_cd
)
values (:identifier, :name, :order, 'A', 'ALL')
""";

private final NamedParameterJdbcTemplate template;
private final Available<Option> availalbe;

JurisdictionMother(final JdbcTemplate template) {
this.template = new NamedParameterJdbcTemplate(template);
this.availalbe = new Available<>();
}

@PreDestroy
void reset() {

List<String> codes = this.availalbe.all()
.map(Option::value)
.toList();

if (!codes.isEmpty()) {

Map<String, List<String>> parameters = Map.of("codes", codes);

template.execute(
DELETE_IN,
new MapSqlParameterSource(parameters),
PreparedStatement::executeUpdate);

this.availalbe.reset();
}
}

void create(final String name) {

String code = UUID.randomUUID().toString()
.replace("-", "")
.substring(0, 20);

int order = this.availalbe.all()
.map(Option::order)
.max(Comparator.naturalOrder())
.orElse(1) + 1;

Map<String, ? extends Serializable> parameters = Map.of(
"identifier", code,
"name", name,
"order", order);

template.execute(
CREATE,
new MapSqlParameterSource(parameters),
PreparedStatement::executeUpdate
);

this.availalbe.available(new Option(code, name, name, order));

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package gov.cdc.nbs.option.jurisdiction;

import io.cucumber.java.en.Given;

public class JurisdictionOptionSteps {

private final JurisdictionMother mother;


JurisdictionOptionSteps(final JurisdictionMother mother) {
this.mother = mother;
}

@Given("there is a {string} jurisdiction")
public void the_jurisdiction_exists_in_the_value_set(final String name) {
mother.create(name);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package gov.cdc.nbs.option.jurisdiction.autocomplete;

import gov.cdc.nbs.option.AutocompleteRequester;
import gov.cdc.nbs.testing.support.Active;
import io.cucumber.java.en.When;
import org.springframework.test.web.servlet.ResultActions;

public class JurisdictionAutocompleteSteps {

private static final String NAME = "jurisdictions";
private final AutocompleteRequester request;
private final Active<ResultActions> response;

JurisdictionAutocompleteSteps(
final AutocompleteRequester request,
final Active<ResultActions> response
) {
this.request = request;
this.response = response;
}

@When("I am trying to find jurisdictions that start with {string}")
public void i_am_trying_to_find_jurisdiction_that_start_with(final String criteria) throws Exception {
response.active(request.complete(NAME, criteria));
}

@When("I am trying to find at most {int} jurisdiction(s) that start with {string}")
public void i_am_trying_to_find_n_jurisdiction_that_start_with(
final int limit,
final String criteria
) throws Exception {
response.active(request.complete("jurisdictions", criteria, limit));
}

}
Loading

0 comments on commit 85965c1

Please sign in to comment.