|
2 | 2 | using LantanaGroup.Link.Shared.Application.SerDes; |
3 | 3 | using LantanaGroup.Link.Terminology.Application.Interfaces; |
4 | 4 | using LantanaGroup.Link.Terminology.Application.Models; |
5 | | -using LantanaGroup.Link.Terminology.Application.Settings; |
6 | 5 | using LantanaGroup.Link.Terminology.Services; |
7 | | -using Microsoft.Extensions.Caching.Memory; |
8 | 6 | using Microsoft.Extensions.Logging; |
9 | | -using Microsoft.Extensions.Options; |
10 | 7 | using Moq; |
11 | 8 | using Code = LantanaGroup.Link.Terminology.Application.Models.Code; |
12 | 9 |
|
@@ -1174,6 +1171,140 @@ public void ValidateCodeInCodeSystem_WithCodeableConcept_InParameters_ReturnsTru |
1174 | 1171 | Assert.True(resultParameter.Value); |
1175 | 1172 | } |
1176 | 1173 |
|
| 1174 | + [Fact] |
| 1175 | + public void LookupCodeInCodeSystem_WithCodeAndSystem_ReturnsNameVersionDisplay() |
| 1176 | + { |
| 1177 | + // Arrange |
| 1178 | + var codeSystemId = "lookup-cs-id"; |
| 1179 | + var codeSystemUrl = "http://lookup.system"; |
| 1180 | + var codeSystemVersion = "2.0.0"; |
| 1181 | + var code = "lookup-code"; |
| 1182 | + var display = "Lookup Display"; |
| 1183 | + var name = "LookupCodeSystem"; |
| 1184 | + |
| 1185 | + var mockCodeGroup = new CodeGroup |
| 1186 | + { |
| 1187 | + Id = codeSystemId, |
| 1188 | + Url = codeSystemUrl, |
| 1189 | + Name = name, |
| 1190 | + Version = codeSystemVersion, |
| 1191 | + Type = CodeGroup.CodeGroupTypes.CodeSystem, |
| 1192 | + Codes = new Dictionary<string, List<Code>> |
| 1193 | + { |
| 1194 | + { codeSystemUrl, new List<Code> { new() { Value = code, Display = display } } } |
| 1195 | + } |
| 1196 | + }; |
| 1197 | + |
| 1198 | + _mockCacheService |
| 1199 | + .Setup(x => x.GetCodeGroup(CodeGroup.CodeGroupTypes.CodeSystem, codeSystemUrl, codeSystemVersion)) |
| 1200 | + .Returns(mockCodeGroup); |
| 1201 | + |
| 1202 | + // Act |
| 1203 | + var result = _service.LookupCodeInCodeSystem(null, null, codeSystemUrl, code, codeSystemVersion, null); |
| 1204 | + |
| 1205 | + // Assert |
| 1206 | + Assert.Equal(name, result.GetSingleValue<FhirString>("name")?.Value); |
| 1207 | + Assert.Equal(codeSystemVersion, result.GetSingleValue<FhirString>("version")?.Value); |
| 1208 | + Assert.Equal(display, result.GetSingleValue<FhirString>("display")?.Value); |
| 1209 | + } |
| 1210 | + |
| 1211 | + [Fact] |
| 1212 | + public void LookupCodeInCodeSystem_WithCodingParameter_ReturnsNameVersionDisplay() |
| 1213 | + { |
| 1214 | + // Arrange |
| 1215 | + var codeSystemId = "lookup-cs-id"; |
| 1216 | + var codeSystemUrl = "http://lookup.system"; |
| 1217 | + var codeSystemVersion = "3.1.4"; |
| 1218 | + var code = "lookup-code"; |
| 1219 | + var display = "Lookup Display"; |
| 1220 | + var name = "LookupCodeSystem"; |
| 1221 | + |
| 1222 | + var mockCodeGroup = new CodeGroup |
| 1223 | + { |
| 1224 | + Id = codeSystemId, |
| 1225 | + Url = codeSystemUrl, |
| 1226 | + Name = name, |
| 1227 | + Version = codeSystemVersion, |
| 1228 | + Type = CodeGroup.CodeGroupTypes.CodeSystem, |
| 1229 | + Codes = new Dictionary<string, List<Code>> |
| 1230 | + { |
| 1231 | + { codeSystemUrl, new List<Code> { new() { Value = code, Display = display } } } |
| 1232 | + } |
| 1233 | + }; |
| 1234 | + |
| 1235 | + _mockCacheService |
| 1236 | + .Setup(x => x.GetCodeGroup(CodeGroup.CodeGroupTypes.CodeSystem, codeSystemUrl, codeSystemVersion)) |
| 1237 | + .Returns(mockCodeGroup); |
| 1238 | + |
| 1239 | + var parameters = new Parameters(); |
| 1240 | + parameters.Add("version", new FhirString(codeSystemVersion)); |
| 1241 | + parameters.Add("coding", new Coding(codeSystemUrl, code, null)); |
| 1242 | + |
| 1243 | + // Act |
| 1244 | + var result = _service.LookupCodeInCodeSystem(null, null, null, null, null, parameters); |
| 1245 | + |
| 1246 | + // Assert |
| 1247 | + Assert.Equal(name, result.GetSingleValue<FhirString>("name")?.Value); |
| 1248 | + Assert.Equal(codeSystemVersion, result.GetSingleValue<FhirString>("version")?.Value); |
| 1249 | + Assert.Equal(display, result.GetSingleValue<FhirString>("display")?.Value); |
| 1250 | + } |
| 1251 | + |
| 1252 | + [Fact] |
| 1253 | + public void LookupCodeInCodeSystem_WithVersionNoMatch_ThrowsKeyNotFoundException() |
| 1254 | + { |
| 1255 | + // Arrange |
| 1256 | + var codeSystemUrl = "http://lookup.system"; |
| 1257 | + var requestedVersion = "9.9.9"; |
| 1258 | + var fallbackCodeGroup = new CodeGroup |
| 1259 | + { |
| 1260 | + Id = "lookup-cs-id", |
| 1261 | + Url = codeSystemUrl, |
| 1262 | + Name = "LookupCodeSystem", |
| 1263 | + Version = "1.0.0", |
| 1264 | + Type = CodeGroup.CodeGroupTypes.CodeSystem, |
| 1265 | + Codes = new Dictionary<string, List<Code>> |
| 1266 | + { |
| 1267 | + { codeSystemUrl, new List<Code> { new() { Value = "lookup-code", Display = "Lookup Display" } } } |
| 1268 | + } |
| 1269 | + }; |
| 1270 | + |
| 1271 | + _mockCacheService |
| 1272 | + .Setup(x => x.GetCodeGroup(CodeGroup.CodeGroupTypes.CodeSystem, codeSystemUrl, requestedVersion)) |
| 1273 | + .Returns(fallbackCodeGroup); |
| 1274 | + |
| 1275 | + // Act / Assert |
| 1276 | + Assert.Throws<KeyNotFoundException>(() => |
| 1277 | + _service.LookupCodeInCodeSystem(null, null, codeSystemUrl, "lookup-code", requestedVersion, null)); |
| 1278 | + } |
| 1279 | + |
| 1280 | + [Fact] |
| 1281 | + public void LookupCodeInCodeSystem_WithCodeSystemAndCoding_ThrowsArgumentException() |
| 1282 | + { |
| 1283 | + // Arrange |
| 1284 | + var parameters = new Parameters(); |
| 1285 | + parameters.Add("coding", new Coding("http://lookup.system", "lookup-code", null)); |
| 1286 | + |
| 1287 | + // Act / Assert |
| 1288 | + Assert.Throws<ArgumentException>(() => |
| 1289 | + _service.LookupCodeInCodeSystem(null, null, "http://lookup.system", "lookup-code", null, parameters)); |
| 1290 | + } |
| 1291 | + |
| 1292 | + [Fact] |
| 1293 | + public void GetMetaData_CodeSystemOperations_IncludesLookupOperation() |
| 1294 | + { |
| 1295 | + // Act |
| 1296 | + var result = _service.GetMetaData(); |
| 1297 | + |
| 1298 | + // Assert |
| 1299 | + var codeSystemResource = result.Rest |
| 1300 | + .SelectMany(rest => rest.Resource) |
| 1301 | + .First(resource => resource.Type == "CodeSystem"); |
| 1302 | + |
| 1303 | + Assert.Contains(codeSystemResource.Operation, operation => |
| 1304 | + operation.Name == "lookup" && |
| 1305 | + operation.Definition == "http://hl7.org/fhir/OperationDefinition/CodeSystem-lookup"); |
| 1306 | + } |
| 1307 | + |
1177 | 1308 | #endregion |
1178 | 1309 |
|
1179 | 1310 | #region ExpandValueSet Tests |
|
0 commit comments