Skip to content

Commit

Permalink
Lookups local drug code before RxNorm, adds to A4
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleybot committed Jan 24, 2025
1 parent 29407b6 commit 8183d0d
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/UDS.Net.Forms.Tests/UDS.Net.Forms.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<ReleaseVersion>4.6.12</ReleaseVersion>
<ReleaseVersion>5.0.0-preview.1</ReleaseVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
Expand Down
1 change: 0 additions & 1 deletion src/UDS.Net.Forms/Pages/RxNorm/Search.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public async Task<IActionResult> OnPostAsync(int id)

try
{

var results = await _lookupService.LookupRxNormApproximateMatches(RxNormLookup.SearchTerm);

var count = results.Where(t => t.Name.ToLower().Contains(RxNormLookup.SearchTerm.ToLower())).Count();
Expand Down
48 changes: 30 additions & 18 deletions src/UDS.Net.Forms/Pages/RxNorm/Select.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,34 @@
ViewData["Title"] = "Select a medication";
}

@if (Model.RxNormLookup.SearchResults != null)
{
<table>
<tbody>
@foreach (var result in Model.RxNormLookup.SearchResults)
{
<tr>
<td>
<form method="post" asp-route-id="@Model.RxNormLookup.Id">
@result.Key
<div class="px-2 py-5">
<a asp-page="/UDS4/A4" asp-route-id="@Model.RxNormLookup.Id" class="rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Back</a>

@if (Model.RxNormLookup.SearchResults != null)
{

@foreach (var result in Model.RxNormLookup.SearchResults)
{
<div class="space-y-3">

<form method="post" asp-route-id="@Model.RxNormLookup.Id" class="rounded-md bg-white px-6 py-4 shadow-sm">
<div class="md:flex md:items-center md:justify-between gap-x-6 py-5">
<div class="min-w-0">
<p class="text-sm/6 text-gray-900">
@result.Key
</p>
<input type="hidden" name="rxCUI" value="@result.Value" />
<input type="submit" />
</form>
</td>
</tr>
}
</tbody>
</table>
}
<input type="hidden" name="drugName" value="@result.Key" />
<input type="hidden" asp-for="@Model.RxNormLookup.Id" />
</div>
<div class="flex flex-none items-center gap-x-4">
<button type="button" class="text-sm/6 font-semibold text-gray-900" disabled>@result.Value</button>
<button type="submit" class="inline-flex items-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-xs hover:bg-indigo-700 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600">Select</button>
</div>
</div>
</form>
</div>
}

}
</div>
64 changes: 52 additions & 12 deletions src/UDS.Net.Forms/Pages/RxNorm/Select.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using UDS.Net.Forms.Extensions;
Expand Down Expand Up @@ -37,22 +38,66 @@ public async Task<IActionResult> OnGet(int id, string searchTerm)
if (String.IsNullOrWhiteSpace(searchTerm))
return RedirectToPage("/RxNorm/Search", new { Id = id });

var results = await _lookupService.LookupRxNormApproximateMatches(searchTerm);
// search local storage before querying rxNorm
// we want to prevent as many duplicates as possible
var search = await _lookupService.SearchDrugCodes(10, 1, RxNormLookup.SearchTerm);

// WORKAROUND simplify results (rx norm has duplicate names)
foreach (var result in results)
if (search.TotalResultsCount > 0 && search.DrugCodes != null && search.DrugCodes.Count > 0)
{
if (!RxNormLookup.SearchResults.Where(s => s.Key == result.Name).Any())
RxNormLookup.SearchResults.Add(result.Name, result.RxCUI);
foreach (var drugCode in search.DrugCodes)
{
RxNormLookup.SearchResults.Add(drugCode.DrugName, drugCode.RxNormId);
}
}
else
{
var results = await _lookupService.LookupRxNormApproximateMatches(searchTerm);

foreach (var result in results)
{
// WORKAROUND simplify results (rx norm has duplicate names)
// Duplicate names with different casing like:
// Azithromycin
// azithromycin
// AZITHROMYCIN
if (!RxNormLookup.SearchResults.Where(s => s.Key.ToLower() == result.Name.ToLower()).Any() && !RxNormLookup.SearchResults.Where(s => s.Value == result.RxCUI).Any())
RxNormLookup.SearchResults.Add(result.Name, result.RxCUI);
}
}

return Page();
}

public async Task<IActionResult> OnPost(int id, string rxCUI)
public async Task<IActionResult> OnPost(int id, string rxCUI, string drugName)
{
if (!String.IsNullOrWhiteSpace(rxCUI))
{
A4DFormFields newDrug = new A4DFormFields()
{
CreatedAt = DateTime.Now,
CreatedBy = User.Identity.Name
};

var lookup = await _lookupService.FindDrugCode(rxCUI);
if (lookup.TotalResultsCount > 0 && lookup.DrugCodes != null && lookup.DrugCodes.Count() > 0)
{
// Drug code already exists in local lookup
lookup.DrugCodes.FirstOrDefault();
newDrug.RxNormId = rxCUI;
}
else
{
// Drug code isn't in local db, so we need to add it before assigning to A4
await _lookupService.AddDrugCodeToLookup(new Services.LookupModels.DrugCode
{
RxNormId = rxCUI,
DrugName = drugName,
BrandName = "",
IsOverTheCounter = false,
IsPopular = false
});
}

var visit = await _visitService.GetByIdWithForm(User.Identity.IsAuthenticated ? User.Identity.Name : "username", id, "A4");
if (visit != null)
{
Expand All @@ -65,12 +110,7 @@ public async Task<IActionResult> OnPost(int id, string rxCUI)
if (!fields.A4Ds.Where(a => a.RxNormId == rxCUI).Any())
{
fields.ANYMEDS = 1;
fields.A4Ds.Add(new A4DFormFields
{
RxNormId = rxCUI,
CreatedAt = DateTime.Now,
CreatedBy = User.Identity.Name
});
fields.A4Ds.Add(newDrug);
await _visitService.UpdateForm(User.Identity.IsAuthenticated ? User.Identity.Name : "username", visit, "A4");
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/UDS.Net.Forms/UDS.Net.Forms.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
<ImplicitUsings>enable</ImplicitUsings>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<PackageId>UDS.Net.Forms</PackageId>
<Version>4.6.12</Version>
<Version>5.0.0-preview.1</Version>
<Authors>Sanders-Brown Center on Aging</Authors>
<Description>UDS Forms razor class library</Description>
<Owners>UK-SBCoA</Owners>
<PackageDescription>Razor class library for rendering UDS forms</PackageDescription>
<RepositoryUrl>https://github.com/UK-SBCoA/uniform-data-set-dotnet-web</RepositoryUrl>
<ReleaseVersion>4.6.12</ReleaseVersion>
<ReleaseVersion>5.0.0-preview.1</ReleaseVersion>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
Expand Down
2 changes: 1 addition & 1 deletion src/UDS.Net.Services.Test/UDS.Net.Services.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<ReleaseVersion>4.6.12</ReleaseVersion>
<ReleaseVersion>5.0.0-preview.1</ReleaseVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
Expand Down
2 changes: 2 additions & 0 deletions src/UDS.Net.Services/ILookupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface ILookupService : IService<DrugCodeLookup>

Task<DrugCodeLookup> SearchDrugCodes(int pageSize = 10, int pageIndex = 1, string? searchTerm = "");

Check warning on line 12 in src/UDS.Net.Services/ILookupService.cs

View workflow job for this annotation

GitHub Actions / Package and publish

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Task<DrugCodeLookup> FindDrugCode(string rxCUI);

Task<LookupCountryCodeDto> LookupCountryCode(string countryCode);

Task<List<string>> LookupRxNormDisplayTerms();
Expand Down
4 changes: 2 additions & 2 deletions src/UDS.Net.Services/UDS.Net.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
<TargetFramework>netstandard2.1</TargetFramework>
<OutputType>Library</OutputType>
<PackageId>UDS.Net.Services</PackageId>
<Version>4.6.12</Version>
<Version>5.0.0-preview.1</Version>
<Authors>Sanders-Brown Center on Aging</Authors>
<Description>Service contracts for implmenting your own back-end with MVC web app</Description>
<Owners>UK-SBCoA</Owners>
<PackageDescription>Service contracts required by MVC web app</PackageDescription>
<RepositoryUrl>https://github.com/UK-SBCoA/uniform-data-set-dotnet-web</RepositoryUrl>
<ReleaseVersion>4.6.12</ReleaseVersion>
<ReleaseVersion>5.0.0-preview.1</ReleaseVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="UDS.Net.Dto" Version="4.4.0" />
Expand Down
49 changes: 43 additions & 6 deletions src/UDS.Net.Web.MVC.Services/LookupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,48 @@ public async Task<DrugCodeLookup> SearchDrugCodes(int pageSize = 10, int pageInd
};
}

public async Task<DrugCodeLookup> FindDrugCode(string rxCUI)
{
if (Int32.TryParse(rxCUI, out int rxNormId))
{
var dto = await _apiClient.LookupClient.FindDrugCode(rxNormId);
if (dto != null)
{
if (dto.TotalResultsCount > 0 && dto.Results != null && dto.Results.Count() > 0)
{
var result = dto.Results.FirstOrDefault();
return new DrugCodeLookup
{
PageSize = 1,
PageIndex = 1,
TotalResultsCount = 1,
DrugCodes = new List<DrugCode>()
{
result.ToDomain()
}
};
}
}
}

return new DrugCodeLookup
{
PageSize = 1,
PageIndex = 1,
TotalResultsCount = 0,
DrugCodes = new List<DrugCode>()
};
}

public async Task<DrugCode> AddDrugCodeToLookup(DrugCode newDrugCode)
{
var dto = newDrugCode.ToDto();

var added = await _apiClient.LookupClient.AddDrugCode(dto);

return added.ToDomain();
}

public async Task<LookupCountryCodeDto> LookupCountryCode(string countryCode)
{
var dto = await _apiClient.LookupClient.LookupCountryCode(countryCode);
Expand Down Expand Up @@ -89,12 +131,6 @@ public async Task<List<RxNorm>> LookupRxNormApproximateMatches(string searchTerm
return new List<RxNorm>();
}

public async Task<DrugCode> AddDrugCodeToLookup(DrugCode newDrugCode)
{
var added = await _apiClient.LookupClient.AddDrugCode(newDrugCode.ToDto());

return added.ToDomain();
}

[Obsolete]
public Task<DrugCodeLookup> Add(string username, DrugCodeLookup entity)
Expand Down Expand Up @@ -137,6 +173,7 @@ public Task<DrugCodeLookup> Update(string username, DrugCodeLookup entity)
{
throw new NotImplementedException();
}

}
}

8 changes: 4 additions & 4 deletions src/UDS.Net.Web.MVC.Services/UDS.Net.Web.MVC.Services.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
<TargetFramework>netstandard2.1</TargetFramework>
<OutputType>Library</OutputType>
<PackageId>UDS.Net.MVC.Services</PackageId>
<Version>4.6.12</Version>
<Version>5.0.0-preview.1</Version>
<Authors>Sanders-Brown Center on Aging</Authors>
<Description>Implemented service layer for using MVC front-end with API back-end</Description>
<Owners>UK-SBCoA</Owners>
<PackageDescription>Implemented service contract</PackageDescription>
<RepositoryUrl>https://github.com/UK-SBCoA/uniform-data-set-dotnet-web</RepositoryUrl>
<ReleaseVersion>4.6.12</ReleaseVersion>
<ReleaseVersion>5.0.0-preview.1</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " />
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="8.0.5" />
<PackageReference Include="UDS.Net.Dto" Version="4.5.0-preview.1" />
<PackageReference Include="UDS.Net.API.Client" Version="4.5.0-preview.1" />
<PackageReference Include="UDS.Net.Dto" Version="4.5.0-preview.2" />
<PackageReference Include="UDS.Net.API.Client" Version="4.5.0-preview.2" />
<PackageReference Include="rxNorm.Net.Api.Wrapper" Version="1.0.3" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions src/UDS.Net.Web.MVC/UDS.Net.Web.MVC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-UDS.Net.Web.MVC-F92C0881-61B6-4292-8635-0004DE84CFE6</UserSecretsId>
<DockerComposeProjectPath>../docker-compose.dcproj</DockerComposeProjectPath>
<ReleaseVersion>4.6.12</ReleaseVersion>
<ReleaseVersion>5.0.0-preview.1</ReleaseVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " />
Expand All @@ -20,8 +20,8 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.10" />
<PackageReference Include="UDS.Net.API.Client" Version="4.5.0-preview.1" />
<PackageReference Include="UDS.Net.Dto" Version="4.5.0-preview.1" />
<PackageReference Include="UDS.Net.API.Client" Version="4.5.0-preview.2" />
<PackageReference Include="UDS.Net.Dto" Version="4.5.0-preview.2" />
<PackageReference Include="rxNorm.Net.Api.Wrapper" Version="1.0.3" />
</ItemGroup>
<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions src/UDS.Net.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UDS.Net.Web.MVC.Services",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UDS.Net.Services.Test", "UDS.Net.Services.Test\UDS.Net.Services.Test.csproj", "{395296FB-4036-4FC9-A8DC-A50F96D35623}"
EndProject
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "docker-compose", "docker-compose.dcproj", "{C22F1898-8F70-49DF-B8D2-872F2CDDE162}"
Project("{9344BDBB-3E7F-41FC-A0DD-8665D75EE146}") = "docker-compose", "docker-compose.dcproj", "{661AC429-95F4-4D4A-9F1C-FC88522DB728}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -47,10 +47,10 @@ Global
{395296FB-4036-4FC9-A8DC-A50F96D35623}.Debug|Any CPU.Build.0 = Debug|Any CPU
{395296FB-4036-4FC9-A8DC-A50F96D35623}.Release|Any CPU.ActiveCfg = Release|Any CPU
{395296FB-4036-4FC9-A8DC-A50F96D35623}.Release|Any CPU.Build.0 = Release|Any CPU
{C22F1898-8F70-49DF-B8D2-872F2CDDE162}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C22F1898-8F70-49DF-B8D2-872F2CDDE162}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C22F1898-8F70-49DF-B8D2-872F2CDDE162}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C22F1898-8F70-49DF-B8D2-872F2CDDE162}.Release|Any CPU.Build.0 = Release|Any CPU
{661AC429-95F4-4D4A-9F1C-FC88522DB728}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{661AC429-95F4-4D4A-9F1C-FC88522DB728}.Debug|Any CPU.Build.0 = Debug|Any CPU
{661AC429-95F4-4D4A-9F1C-FC88522DB728}.Release|Any CPU.ActiveCfg = Release|Any CPU
{661AC429-95F4-4D4A-9F1C-FC88522DB728}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -59,6 +59,6 @@ Global
SolutionGuid = {3268D734-1592-4E39-88A2-3A53468CC430}
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
version = 4.6.12
version = 5.0.0-preview.1
EndGlobalSection
EndGlobal

0 comments on commit 8183d0d

Please sign in to comment.