From a21d40e030b3857a8fcbf5a140a1437b7ffd3fd2 Mon Sep 17 00:00:00 2001 From: Joseph Kotanchik Date: Mon, 28 Oct 2024 14:50:48 -0400 Subject: [PATCH] MAT-7859: Guard against unexpected Value Set Status values by mapping them to FHIRPublication.UNKNOWN. --- .../terminology/mapper/VsacToFhirValueSetMapper.java | 12 ++++++++++-- .../mapper/VsacToFhirValueSetMapperTest.java | 9 +++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/gov/cms/madie/terminology/mapper/VsacToFhirValueSetMapper.java b/src/main/java/gov/cms/madie/terminology/mapper/VsacToFhirValueSetMapper.java index e6c9854..c33eec9 100644 --- a/src/main/java/gov/cms/madie/terminology/mapper/VsacToFhirValueSetMapper.java +++ b/src/main/java/gov/cms/madie/terminology/mapper/VsacToFhirValueSetMapper.java @@ -7,6 +7,7 @@ import gov.cms.madie.terminology.service.MappingService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r4.model.Enumerations.PublicationStatus; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.r4.model.Identifier; @@ -55,8 +56,7 @@ protected ValueSet setFhirMainAttributes( fhirValueSet.setName(vsacDescribedValueSet.getDisplayName()); fhirValueSet.setTitle(vsacDescribedValueSet.getDisplayName()); fhirValueSet.setVersion(vsacDescribedValueSet.getVersion()); - fhirValueSet.setStatus( - PublicationStatus.fromCode(vsacDescribedValueSet.getStatus().toLowerCase())); + fhirValueSet.setStatus(mapVsacValueSetStatusToFhir(vsacDescribedValueSet.getStatus())); fhirValueSet.setDate(vsacDescribedValueSet.getRevisionDate().toGregorianCalendar().getTime()); fhirValueSet.setPublisher(vsacDescribedValueSet.getSource()); // ?? @@ -65,6 +65,14 @@ protected ValueSet setFhirMainAttributes( return fhirValueSet; } + private PublicationStatus mapVsacValueSetStatusToFhir(String vsacStatus) { + try { + return PublicationStatus.fromCode(vsacStatus.toLowerCase()); + } catch (FHIRException | NullPointerException e) { + return PublicationStatus.UNKNOWN; + } + } + protected void addFhirValueSetComposeComponent( List vsacConceptList, ValueSet fhirValueSet) { ValueSetComposeComponent fhirValueSetComposeComponent = new ValueSetComposeComponent(); diff --git a/src/test/java/gov/cms/madie/terminology/mapper/VsacToFhirValueSetMapperTest.java b/src/test/java/gov/cms/madie/terminology/mapper/VsacToFhirValueSetMapperTest.java index 7a7fdff..3c8d93f 100644 --- a/src/test/java/gov/cms/madie/terminology/mapper/VsacToFhirValueSetMapperTest.java +++ b/src/test/java/gov/cms/madie/terminology/mapper/VsacToFhirValueSetMapperTest.java @@ -13,6 +13,7 @@ import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.XMLGregorianCalendar; +import org.hl7.fhir.r4.model.Enumerations; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent; import org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent; @@ -143,6 +144,14 @@ public void testSetFhirMainAttributes() { assertEquals(vs.getDate(), today); } + @Test + public void testMapMainAttributesUnknownStatus() { + ValueSet vs = new ValueSet(); + describedValueSet.setStatus("Not Maintained"); + vs = mapper.setFhirMainAttributes(vs, describedValueSet, TEST); + assertEquals(Enumerations.PublicationStatus.UNKNOWN.getDisplay(), vs.getStatus().getDisplay()); + } + @Test public void testGetVsacCodeMap() {