forked from chpladmin/chpl-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Standard duplicate data check
OCD-4333
- Loading branch information
Todd Young
committed
Nov 27, 2023
1 parent
d7ff8ca
commit ee68ca3
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...va/gov/healthit/chpl/validation/listing/reviewer/duplicate/StandardDuplicateReviewer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package gov.healthit.chpl.validation.listing.reviewer.duplicate; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.function.BiPredicate; | ||
import java.util.stream.Collectors; | ||
|
||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
import gov.healthit.chpl.domain.CertificationResult; | ||
import gov.healthit.chpl.domain.CertifiedProductSearchDetails; | ||
import gov.healthit.chpl.standard.CertificationResultStandard; | ||
import gov.healthit.chpl.util.ErrorMessageUtil; | ||
import gov.healthit.chpl.util.Util; | ||
import gov.healthit.chpl.validation.DuplicateReviewResult; | ||
|
||
@Component(value = "standardDuplicateReviewer") | ||
public class StandardDuplicateReviewer { | ||
private ErrorMessageUtil errorMessageUtil; | ||
|
||
@Autowired | ||
public StandardDuplicateReviewer(ErrorMessageUtil errorMessageUtil) { | ||
this.errorMessageUtil = errorMessageUtil; | ||
} | ||
|
||
public void review(CertifiedProductSearchDetails listing, CertificationResult certificationResult) { | ||
|
||
DuplicateReviewResult<CertificationResultStandard> standardDuplicateResults = | ||
new DuplicateReviewResult<CertificationResultStandard>(getPredicate()); | ||
|
||
if (certificationResult.getStandards() != null) { | ||
for (CertificationResultStandard crs : certificationResult.getStandards()) { | ||
standardDuplicateResults.addObject(crs); | ||
} | ||
} | ||
|
||
if (standardDuplicateResults.duplicatesExist()) { | ||
listing.addAllWarningMessages( | ||
getWarnings( | ||
standardDuplicateResults.getDuplicateList(), | ||
Util.formatCriteriaNumber(certificationResult.getCriterion())) | ||
.stream() | ||
.collect(Collectors.toSet())); | ||
certificationResult.setStandards(standardDuplicateResults.getUniqueList()); | ||
} | ||
} | ||
|
||
private List<String> getWarnings(List<CertificationResultStandard> duplicates, | ||
String criteria) { | ||
List<String> warnings = new ArrayList<String>(); | ||
for (CertificationResultStandard duplicate : duplicates) { | ||
String warning = errorMessageUtil.getMessage("listing.criteria.duplicateStandard", | ||
criteria, duplicate.getStandard().getRegulatoryTextCitation()); | ||
warnings.add(warning); | ||
} | ||
return warnings; | ||
} | ||
|
||
private BiPredicate<CertificationResultStandard, CertificationResultStandard> getPredicate() { | ||
return new BiPredicate<CertificationResultStandard, CertificationResultStandard>() { | ||
@Override | ||
public boolean test(CertificationResultStandard s1, CertificationResultStandard s2) { | ||
return (ObjectUtils.allNotNull(s1.getStandard().getId(), s2.getStandard().getId()) | ||
&& Objects.equals(s1.getStandard().getId(), s2.getStandard().getId())) | ||
|| Objects.equals(s1.getStandard().getRegulatoryTextCitation(), s2.getStandard().getRegulatoryTextCitation()); | ||
} | ||
}; | ||
} | ||
|
||
} |