Skip to content

Commit

Permalink
Merge pull request #3 from SALUD-AR/Iteracion-3
Browse files Browse the repository at this point in the history
Iteracion 3
  • Loading branch information
Miguel Amorese authored Sep 20, 2019
2 parents 4e22bab + 4fae19d commit 44bc03f
Show file tree
Hide file tree
Showing 48 changed files with 1,943 additions and 417 deletions.
9 changes: 8 additions & 1 deletion MnsInteropDemo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Msn.InteropDemo.Snowstorm",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Msn.InteropDemo.Snowstorm.Expressions", "Msn.InteropDemo.Snowstorm.Expressions\Msn.InteropDemo.Snowstorm.Expressions.csproj", "{9B53B72E-74A0-4347-B3C0-F9FE9A9F5461}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Msn.InteropDemo.Communication", "Msn.InteropDemo.Communication\Msn.InteropDemo.Communication.csproj", "{319F5146-DE42-4007-B945-56F3A5E1B800}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Msn.InteropDemo.Communication", "Msn.InteropDemo.Communication\Msn.InteropDemo.Communication.csproj", "{319F5146-DE42-4007-B945-56F3A5E1B800}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Msn.InteropDemo.Dfa", "Msn.InteropDemo.Dfa\Msn.InteropDemo.Dfa.csproj", "{9140330A-D988-4A66-8E0B-C363BBA7596A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -120,6 +122,10 @@ Global
{319F5146-DE42-4007-B945-56F3A5E1B800}.Debug|Any CPU.Build.0 = Debug|Any CPU
{319F5146-DE42-4007-B945-56F3A5E1B800}.Release|Any CPU.ActiveCfg = Release|Any CPU
{319F5146-DE42-4007-B945-56F3A5E1B800}.Release|Any CPU.Build.0 = Release|Any CPU
{9140330A-D988-4A66-8E0B-C363BBA7596A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9140330A-D988-4A66-8E0B-C363BBA7596A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9140330A-D988-4A66-8E0B-C363BBA7596A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9140330A-D988-4A66-8E0B-C363BBA7596A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -140,6 +146,7 @@ Global
{ABF37951-4736-45F4-96D4-F21FE86BD7B3} = {0710DC47-8B52-459E-A34A-3D0AA50606B2}
{9B53B72E-74A0-4347-B3C0-F9FE9A9F5461} = {0710DC47-8B52-459E-A34A-3D0AA50606B2}
{319F5146-DE42-4007-B945-56F3A5E1B800} = {E0EFA8A1-D0D1-4097-A308-48CA1882AE4B}
{9140330A-D988-4A66-8E0B-C363BBA7596A} = {75047E25-9AA1-4691-A119-CD2A9505DBF9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D3168AB5-DFEF-4290-816E-538D42CB6424}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Msn.InteropDemo.AppServices.Core;
using Msn.InteropDemo.Snowstorm;
using Msn.InteropDemo.ViewModel.Snomed;
using System;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -18,14 +19,26 @@ public Cie10AppService(ICurrentContext currentContext,
{
_snowstormManager = snowstormManager;
}

public IEnumerable<Cie10MapResultViewModel> GetCie10MappedItems(string conceptId,
string sexo,
int edad)
{
var lst = GetCie10MappedItems(conceptId);
var cie10Mapper = new Internal.SnomedToCie10Mapper();
cie10Mapper.SetMapeoPreferido(lst, sexo, edad);

return lst;
}


public IEnumerable<Cie10MapResultViewModel> GetCie10MappedItems(string conceptId)
{
var lst = new List<Cie10MapResultViewModel>();

var cie10lst = _snowstormManager.RunQueryCie10MapRefset(conceptId);

//se seleccionan solo aquellos que tienen un MapTarget, es decir, un Mapeo Esistente.
//se seleccionan solo aquellos que tienen un MapTarget, es decir, un Mapeo Existente.
cie10lst.Items = cie10lst.Items.Where(x => !string.IsNullOrWhiteSpace(x.additionalFields.mapTarget)).ToList();

//Customization para el formato de la codificacion de la DEIS
Expand All @@ -37,10 +50,10 @@ public IEnumerable<Cie10MapResultViewModel> GetCie10MappedItems(string conceptId
}
}

//Mapeo a nuestros ViewModels
//Mapeo a nuestros ViewModels
var cie10Maplst = Mapper.Map<List<Cie10MapResultViewModel>>(cie10lst.Items);

//Se seleccionadn los distintos MApTargue para is a buscar en la DB
//Se seleccionadn los distintos MapTarguet para is a buscar en la DB
var cie102search = cie10Maplst.Select(x => x.MapTarget).Distinct();

//obtenidos de la DB
Expand All @@ -55,7 +68,9 @@ public IEnumerable<Cie10MapResultViewModel> GetCie10MappedItems(string conceptId
item.SubcategoriaNombre = dbitem.SubcategoriaNombre;
item.CategoriaNombre = dbitem.CategoriaNombre;
}
}
}

cie10Maplst = cie10Maplst.OrderBy(x => x.MapGroup).ThenBy(x => x.MapPriority).ToList();

return cie10Maplst;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using Msn.InteropDemo.AppServices.Core;
using Msn.InteropDemo.Entities.Evoluciones;
using Msn.InteropDemo.Snowstorm;
using Msn.InteropDemo.ViewModel.Evoluciones;
using System;
Expand All @@ -22,9 +23,39 @@ public EvolucionAppService(Snowstorm.ISnowstormManager snowstormManager,

public EvolucionViewModel GetById(int evolucionId)
{
var entity = GetById<EvolucionViewModel>(criteria: x => x.Id == evolucionId,
includeProperties: "Diagnosticos,Medicamentos,Vacunas,CreatedUser");
return entity;
var entity_old = GetById<EvolucionViewModel>(criteria: x => x.Id == evolucionId,
includeProperties: "Diagnosticos.Cie10Mapeos,Medicamentos,Vacunas,CreatedUser");

var entity = Get(filter: x => x.Id == evolucionId, includeProperties: "Diagnosticos.Cie10Mapeos,Medicamentos,Vacunas,CreatedUser").First();

//conversion al nuevo formato de mapeo multiple
if (entity.Diagnosticos.Any(x => x.Cie10SubcategoriaId != null))
{
foreach (var item in entity.Diagnosticos)
{
//si existe un mapeo de la vieja forma, lo paso a la forma nueva
if (!string.IsNullOrWhiteSpace(item.Cie10SubcategoriaId))
{
item.Cie10Mapeos = new List<EvolucionDiagnosticoCie10>
{
new EvolucionDiagnosticoCie10
{
Cie10SubcategoriaId = item.Cie10SubcategoriaId,
Cie10SubcategoriaNombre = item.Cie10SubcategoriaNombre
}
};

item.Cie10SubcategoriaId = null;
item.Cie10SubcategoriaNombre = null;
};
}

CurrentContext.DataContext.SaveChanges();
}

var model = Mapper.Map<EvolucionViewModel>(entity);

return model;
}

public IEnumerable<EvolucionDiagnosticoViewModel> GetDiagnosticos(int evolucionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Common.OperationResults.OperationResult FederarPaciente(int pacienteId)
}
else
{
op.AddError("El registro en el BUS noha devuelto resultados.");
op.AddError("El Federador no ha devuelto resultados.");
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
using Msn.InteropDemo.ViewModel.Snomed;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Msn.InteropDemo.AppServices.Implementation.Internal
{
internal class SnomedToCie10Mapper
{
Lazy<Dfa.Dfas.ComparizonDfa> dfaComparizon;
Lazy<Dfa.Dfas.IntegerNumberDfa> dfaNumber;
Lazy<Dfa.Notifications.MatchCollector> matchCollector;

public SnomedToCie10Mapper()
{
dfaComparizon = new Lazy<Dfa.Dfas.ComparizonDfa>();
dfaNumber = new Lazy<Dfa.Dfas.IntegerNumberDfa>();
matchCollector = new Lazy<Dfa.Notifications.MatchCollector>();
}

public void SetMapeoPreferido(IEnumerable<Cie10MapResultViewModel> items,
string sexo,
int edad)
{
var groups = from i in items
group i by i.MapGroup into newGroup
orderby newGroup.Key
select newGroup;

foreach (var g in groups)
{
foreach (var item in g)
{
//Rancking por Sexo
SetRankingSexo(item, sexo);

//Rancking por Edad
SetRankingEdad(item, edad);
}

var maxRank = g.Max(x => x.RankingPreferido);
if((maxRank == 0) && (g.Count() > 1)) //ninguno item tiene Ranking en el Grupo
{
var ot = g.Where(x => x.MapRule.Contains("OTHERWISE TRUE"));
foreach (var item in ot)
{
item.RankingPreferido++;
}

maxRank = 1;
}

var preferidos = g.Where(x => x.RankingPreferido == maxRank);

foreach (var item in preferidos)
{
item.EsMapeoPreferido = true;
}
}
}

private void SetRankingSexo(Cie10MapResultViewModel item, string sexo)
{
if (((item.MapRule.Contains("248153007") && sexo == "M") || (item.MapRule.Contains("248152002") && sexo == "F")))
{
item.RankingPreferido++;
}
}

private void SetRankingEdad(Cie10MapResultViewModel item, int edad)
{
string ruleSimbol;
string ruleAge;

if (item.MapRule.Contains("424144002"))
{
var textToParse = item.MapRule.Split('|')[2].ToCharArray();

matchCollector.Value.CollectorResult = string.Empty;
dfaComparizon.Value.CollectTokens(textToParse, matchCollector.Value);
ruleSimbol = matchCollector.Value.CollectorResult;

matchCollector.Value.CollectorResult = string.Empty;
dfaNumber.Value.CollectTokens(textToParse, matchCollector.Value);
ruleAge = matchCollector.Value.CollectorResult;

if(CompareEdad(ruleSimbol, ruleAge, edad))
{
item.RankingPreferido++;
}
}
}

private bool CompareEdad(string ruleSimbol, string ruleAge, int edad)
{
if (ruleSimbol is null)
{
throw new ArgumentNullException(nameof(ruleSimbol));
}

if (ruleAge is null)
{
throw new ArgumentNullException(nameof(ruleAge));
}

if (!int.TryParse(ruleAge, out var ruleEdad))
{
throw new Exception($"No se pudo parsear la Edad del la Rule:{ruleAge}");
}
if(ruleEdad >= 100)
{
ruleEdad = ruleEdad / 10;
}

switch (ruleSimbol)
{
case "<":
return edad < ruleEdad;
case "<=":
return edad <= ruleEdad;
case "=":
return edad == ruleEdad;
case ">=":
return edad >= ruleEdad;
case ">":
return edad > ruleEdad;
case "!":
return edad != ruleEdad;
case "<>":
return edad != ruleEdad;
}

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public EvolucionProfile()
.ForMember(dest => dest.FechaEvolucion, orig => orig.MapFrom(x => x.CreatedDateTime.ToString("dd/MM/yyyy")));

CreateMap<Entities.Evoluciones.EvolucionDiagnostico, ViewModel.Evoluciones.EvolucionDiagnosticoViewModel>();
CreateMap<Entities.Evoluciones.EvolucionDiagnosticoCie10, ViewModel.Evoluciones.EvolucionDiagnosticoCie10ViewModel>();
CreateMap<Entities.Evoluciones.EvolucionMedicamento, ViewModel.Evoluciones.EvolucionMedicamentoViewModel>();
CreateMap<Entities.Evoluciones.EvolucionVacunaAplicacion, ViewModel.Evoluciones.EvolucionVacunaAplicacionViewModel>();
///////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -35,6 +36,7 @@ public EvolucionProfile()
///////////////////////////////////////////////////////////////////////////////////////////////////////
CreateMap<ViewModel.Evoluciones.EvolucionViewModel, Entities.Evoluciones.Evolucion>();
CreateMap<ViewModel.Evoluciones.EvolucionDiagnosticoViewModel, Entities.Evoluciones.EvolucionDiagnostico>();
CreateMap<ViewModel.Evoluciones.EvolucionDiagnosticoCie10ViewModel, Entities.Evoluciones.EvolucionDiagnosticoCie10>();
CreateMap<ViewModel.Evoluciones.EvolucionMedicamentoViewModel, Entities.Evoluciones.EvolucionMedicamento>();
CreateMap<ViewModel.Evoluciones.EvolucionVacunaAplicacionViewModel, Entities.Evoluciones.EvolucionVacunaAplicacion>();
///////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\Msn.InteropDemo.AppServices\Msn.InteropDemo.AppServices.csproj" />
<ProjectReference Include="..\Msn.InteropDemo.Common\Msn.InteropDemo.Common.csproj" />
<ProjectReference Include="..\Msn.InteropDemo.Dfa\Msn.InteropDemo.Dfa.csproj" />
<ProjectReference Include="..\Msn.InteropDemo.Entities\Msn.InteropDemo.Entities.csproj" />
<ProjectReference Include="..\Msn.InteropDemo.Fhir\Msn.InteropDemo.Fhir.csproj" />
<ProjectReference Include="..\Msn.InteropDemo.Snowstorm.Expressions\Msn.InteropDemo.Snowstorm.Expressions.csproj" />
Expand Down
10 changes: 8 additions & 2 deletions Msn.InteropDemo.AppServices/ICie10AppService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
namespace Msn.InteropDemo.AppServices
using Msn.InteropDemo.ViewModel.Snomed;
using System.Collections.Generic;

namespace Msn.InteropDemo.AppServices
{
public interface ICie10AppService : Core.IGenericServiceReadOnly<Entities.Codificacion.Cie10>
{
System.Collections.Generic.IEnumerable<ViewModel.Snomed.Cie10MapResultViewModel> GetCie10MappedItems(string conceptId);
IEnumerable<Cie10MapResultViewModel> GetCie10MappedItems(string conceptId);
IEnumerable<Cie10MapResultViewModel> GetCie10MappedItems(string conceptId,
string sexo,
int edad);
}
}
33 changes: 33 additions & 0 deletions Msn.InteropDemo.Data/DataInitialization/Initializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,46 @@ public async Task SeedAsync()
await SeedRoles();
await SeedDefaultAdminUser();
await SeedActivityTypeDescriptorsAsync();
await SeedPacientesPrueba();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error inicializando datos:");
}
}

private async Task SeedPacientesPrueba()
{
await InsertPacientePrueba("Matilde", 1111111, "F", 75);
await InsertPacientePrueba("Juan", 1111112, "M", 50);
await InsertPacientePrueba("Mateo", 1111113, "M", 17);
await InsertPacientePrueba("Valentina", 1111114, "F", 3);
}

private async Task InsertPacientePrueba(string nombre, int nroDocumento, string sexo, int edad)
{
var apellido = "Prueba";

if (!_dataContext.Pacientes.Any(x => x.PrimerApellido == apellido
&& x.PrimerNombre == nombre
&& x.NroDocumento == nroDocumento))
{
var p = new Paciente
{
PrimerApellido = apellido,
PrimerNombre = nombre,
TipoDocumentoId = 1, //DNI
NroDocumento = nroDocumento,
FechaNacimiento = DateTime.Today.AddYears(edad * (-1)),
Sexo = sexo,
CreatedUserId = "1"
};

_dataContext.Pacientes.Add(p);
await _dataContext.SaveChangesAsync();
}
}

private async Task SeedRoles()
{
if (!_dataContext.Roles.Any())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Msn.InteropDemo.Data.EntitiesConfiguration.Pacientes
{
public class EvolucionDiagnosticoCie10Configuration : IEntityTypeConfiguration<Entities.Evoluciones.EvolucionDiagnosticoCie10>
{
public void Configure(EntityTypeBuilder<Entities.Evoluciones.EvolucionDiagnosticoCie10> builder)
{
builder.Property(x => x.Cie10SubcategoriaId)
.HasMaxLength(4)
.HasColumnType("char(4)")
.IsRequired(false)
.IsUnicode(false);

builder.Property(x => x.Cie10SubcategoriaNombre)
.HasMaxLength(300)
.IsRequired(false)
.IsUnicode();
}
}
}
Loading

0 comments on commit 44bc03f

Please sign in to comment.