Template
148 lines
6.9 KiB
C#
148 lines
6.9 KiB
C#
using Strata.ApiCommunication.Http;
|
|
using Strata.ApiLib.Standard.Models;
|
|
using Strata.ContinuousImprovement.Api.Test.Integration.Mapperly;
|
|
using Strata.ContinuousImprovement.Biz.Dtos;
|
|
using Strata.ContinuousImprovement.Biz.Encounter.Opportunities;
|
|
using Strata.ContinuousImprovement.Biz.OrgDefined.Queries;
|
|
using Strata.ContinuousImprovement.Biz.Shared;
|
|
using System.Net.Http.Json;
|
|
using System.Text.Json;
|
|
|
|
namespace Strata.ContinuousImprovement.Api.Test.Integration.Tests
|
|
{
|
|
[TestFixture, Category("Integration"), Category("API")]
|
|
|
|
public class TestEncounterOpportunitiesController : ApiTestBase
|
|
{
|
|
private const string EncounterOpportunitiesEndpoint = "api/v1/encounter-opportunities";
|
|
|
|
[Test]
|
|
public async Task OpportunityMetricCohortDataTest()
|
|
{
|
|
// Arrange
|
|
var request = new HttpRequestMessage(HttpMethod.Get, "api/v1/configurations");
|
|
var response = await HttpClient.SendAsync(request);
|
|
response.EnsureSuccessStatusCode();
|
|
var options = new JsonSerializerOptions
|
|
{
|
|
PropertyNameCaseInsensitive = true,
|
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
|
};
|
|
var configurations = await response.Content
|
|
.ReadFromJsonAsync<List<ConfigurationInfo>>(options, CancellationToken.None);
|
|
var configuration = configurations.SingleOrDefault(c => c.DisplayOrder == 0);
|
|
if (configuration == null) Assert.Inconclusive("Unable to obtain configuration");
|
|
request = new HttpRequestMessage(HttpMethod.Post, EncounterOpportunitiesEndpoint);
|
|
await request.SetContentAsJsonAsync(
|
|
new
|
|
{
|
|
pagingOptions = new
|
|
{
|
|
sortField = "IdentifiedSavings",
|
|
sortOrder = "Asc",
|
|
first = 0,
|
|
rows = 1
|
|
},
|
|
filters = new
|
|
{
|
|
configurationGuid = configuration.ConfigurationGuid,
|
|
identifiedSavings = 0,
|
|
viewVisible = true,
|
|
excludeInitiaves = false,
|
|
opportunitySearch = "",
|
|
cases = 0,
|
|
opportunityLevels = Array.Empty<string>(),
|
|
encounterGroups = "CaseType",
|
|
seasonality = "Without"
|
|
}
|
|
});
|
|
response = await HttpClient.SendAsync(request);
|
|
response.EnsureSuccessStatusCode();
|
|
var opportunityPage =
|
|
await response.Content.ReadFromJsonAsync<PagedApiResponse<ENOpportunity>>(options, CancellationToken.None);
|
|
var opportunity = opportunityPage?.Data.FirstOrDefault(opp => opp.OpportunityLevel == nameof(OpportunityLevel.Entity));
|
|
if (opportunity == null) Assert.Ignore("No Encounter Opportunity found to work with");
|
|
request = new HttpRequestMessage(HttpMethod.Get, EncounterOpportunitiesEndpoint + $"/{opportunity.OpportunityGuid}");
|
|
response = await HttpClient.SendAsync(request);
|
|
response.EnsureSuccessStatusCode();
|
|
var opportunityDto = await response.Content.ReadFromJsonAsync<ENOpportunityDto>(options, CancellationToken.None);
|
|
if (opportunityDto == null) Assert.Ignore("Unable to retrieve opportunity data");
|
|
var data = opportunityDto.Map();
|
|
var caseTypeCategorySql = string.Empty;
|
|
/*
|
|
var CaseTypeCategories = await jazzDbContext.DimCaseTypes
|
|
.GroupBy(ct => ct.CaseTypeCategory, (g, d) => new
|
|
{
|
|
CaseTypeCategory = g,
|
|
CaseTypeIds = d.Select(x => x.CaseTypeId).ToList()
|
|
}).ToListAsync(CancellationToken.None);
|
|
var CaseTypeCategorySql = CaseTypeCategories
|
|
.Select(ct => string.Format(CaseTypeFamilyIdExists.Exists[ct.CaseTypeCategory], string.Join(",", ct.CaseTypeIds)))
|
|
.Aggregate("", (x, y) => $"{x}\r\nOR\r\n{y}");
|
|
*/
|
|
var requestInfo = new OpportunityMetricCohortOptions
|
|
{
|
|
ConfigurationGuid = configuration.ConfigurationGuid,
|
|
Data = data,
|
|
InnerJoin = caseTypeCategorySql
|
|
};
|
|
request = new HttpRequestMessage(HttpMethod.Post, $"{EncounterOpportunitiesEndpoint}/opportunity-metric-cohort-data");
|
|
await request.SetContentAsJsonAsync(requestInfo, CancellationToken.None);
|
|
|
|
// Act
|
|
response = await HttpClient.SendAsync(request);
|
|
|
|
// Assert
|
|
response.EnsureSuccessStatusCode();
|
|
}
|
|
}
|
|
|
|
public class ConfigurationInfo
|
|
{
|
|
public string Name { get; set; }
|
|
public Guid ConfigurationGuid { get; set; }
|
|
public int DisplayOrder { get; set; }
|
|
public int FiscalYearId { get; set; }
|
|
}
|
|
|
|
public class ENOpportunityInfo
|
|
{
|
|
public Guid OpportunityGuid { get; set; }
|
|
public Guid ConfigurationGuid { get; set; }
|
|
public string OpportunityKey { get; set; }
|
|
public double IdentifiedSavings { get; set; }
|
|
public Guid InitiativeGuid { get; set; }
|
|
public bool HasInitiative => InitiativeGuid != Guid.Empty;
|
|
public string Initiative { get; set; }
|
|
public bool IsHidden { get; set; }
|
|
public string Note { get; set; } = String.Empty;
|
|
public string Name { get; set; }
|
|
public double Cases { get; set; }
|
|
public string EncounterGroup { get; set; }
|
|
public string EncounterGroupValue { get; set; }
|
|
public string OpportunityLevel { get; set; }
|
|
public bool IsSeasonal { get; set; }
|
|
public long OpportunityId { get; set; }
|
|
}
|
|
|
|
public static class CaseTypeFamilyIdExists
|
|
{
|
|
public static string[] Exists => new[]
|
|
{
|
|
@" EXISTS(SELECT 1 FROM dss.CaseTypeFamilyMappingICD10 msdrg
|
|
INNER JOIN dss.DimCaseType dct ON dct.CaseTypeFamilyID = msdrg.CaseTypeFamilyID AND dct.CaseTypeId in ({0}) AND dct.CaseTypeCategory = 0
|
|
WHERE msdrg.CaseTypeFamilyID = fpes.MSDRGCaseTypeFamilyID)",
|
|
@" EXISTS(SELECT 1 FROM dss.CaseTypeFamilyMappingAPRDRG aprdrg
|
|
INNER JOIN dss.DimCaseType dct ON dct.CaseTypeFamilyID = aprdrg.CaseTypeFamilyID AND dct.CaseTypeId in ({0}) AND dct.CaseTypeCategory = 1
|
|
WHERE aprdrg.CaseTypeFamilyID = fpes.APRDRGCaseTypeFamilyID)",
|
|
@"AND EXISTS(SELECT 1 FROM dss.FactPatientEncounterClinicalIndicator ci
|
|
WHERE ci.EncounterID = fpes.EncounterID AND ci.ClinicalIndicatorID in ({0}) and ci.IsDeleted = 0)",
|
|
@" EXISTS(SELECT 1 FROM dss.CaseTypeFamilyMappingCPT cpt
|
|
INNER JOIN dss.DimCaseType dct ON dct.CaseTypeFamilyID = cpt.CaseTypeFamilyID AND dct.CaseTypeId in ({0}) AND dct.CaseTypeCategory = 3
|
|
WHERE cpt.CaseTypeFamilyID = fpes.CPTCodeCaseTypeFamilyID)"
|
|
};
|
|
|
|
}
|
|
|
|
}
|