diff --git a/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/entity/CodeSetGroupMetadatum.java b/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/entity/CodeSetGroupMetadatum.java index 40625bbd32..f4e62edb96 100644 --- a/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/entity/CodeSetGroupMetadatum.java +++ b/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/entity/CodeSetGroupMetadatum.java @@ -1,20 +1,13 @@ package gov.cdc.nbs.questionbank.entity; -import java.util.LinkedHashSet; -import java.util.Set; +import gov.cdc.nbs.questionbank.valueset.command.ValueSetCommand.Update; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Id; -import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import gov.cdc.nbs.questionbank.valueset.command.ValueSetCommand.Update; -import lombok.AllArgsConstructor; import lombok.Getter; -import lombok.NoArgsConstructor; import lombok.Setter; -@AllArgsConstructor -@NoArgsConstructor @Getter @Setter @Entity @@ -42,12 +35,7 @@ public class CodeSetGroupMetadatum { @Column(name = "phin_std_val_ind") private Character phinStdValInd; - @SuppressWarnings( - // Bidirectional mappings require knowledge of each other - "javaarchitecture:S7027" - ) - @OneToMany(mappedBy = "codeSetGroup") - private Set codesets = new LinkedHashSet<>(); + protected CodeSetGroupMetadatum() {} public CodeSetGroupMetadatum(Long id, String codeSetDescTxt, String codeSetShortDescTxt, String codeSetName) { this.id = id; diff --git a/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/entity/Codeset.java b/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/entity/Codeset.java index fb1d7930b9..2ede04ce5b 100644 --- a/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/entity/Codeset.java +++ b/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/entity/Codeset.java @@ -1,6 +1,6 @@ package gov.cdc.nbs.questionbank.entity; -import java.time.Instant; +import gov.cdc.nbs.questionbank.valueset.command.ValueSetCommand; import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.EmbeddedId; @@ -9,13 +9,14 @@ import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; -import gov.cdc.nbs.questionbank.valueset.command.ValueSetCommand; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import java.time.Instant; + @AllArgsConstructor @NoArgsConstructor @Getter @@ -61,8 +62,9 @@ public class Codeset { private Instant statusToTime; @SuppressWarnings( - // Bidirectional mappings require knowledge of each other - "javaarchitecture:S7027") + // Bidirectional mappings require knowledge of each other + "javaarchitecture:S7027" + ) @ManyToOne(fetch = FetchType.LAZY, cascade = { CascadeType.MERGE, CascadeType.REMOVE, diff --git a/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/filter/querydsl/QueryDSLFilterApplier.java b/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/filter/querydsl/QueryDSLFilterApplier.java index 5bf03881c8..642c80dff7 100644 --- a/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/filter/querydsl/QueryDSLFilterApplier.java +++ b/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/filter/querydsl/QueryDSLFilterApplier.java @@ -19,13 +19,6 @@ public interface CriteriaResolver { Stream resolve(final Filter filter, final Expression expression); } - @SuppressWarnings("javaarchitecture:S7027") // static method uses default implementation - public static Stream apply( - final ExpressionResolver expressionResolver, - final Collection filters) { - return apply(expressionResolver, new DefaultQueryDSLCriteriaResolver(), filters); - } - public static Stream apply( final ExpressionResolver expressionResolver, final CriteriaResolver criteriaResolver, diff --git a/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/page/content/reorder/models/ReorderablePage.java b/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/page/content/reorder/models/ReorderablePage.java index d0b62ae419..333c0bdaff 100644 --- a/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/page/content/reorder/models/ReorderablePage.java +++ b/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/page/content/reorder/models/ReorderablePage.java @@ -6,8 +6,14 @@ import gov.cdc.nbs.questionbank.page.content.reorder.ReorderException; public class ReorderablePage { - private List tabs = new ArrayList<>(); - private Long id; + + public static final int PAGE_TYPE = 1002; + public static final int TAB = 1010; + public static final int SECTION = 1015; + public static final int SUBSECTION = 1016; + + private final List tabs = new ArrayList<>(); + private final Long id; public ReorderablePage(Long id) { this.id = id; @@ -37,13 +43,13 @@ public void move(long toMove, long afterId) { public List toPageEntries() { List entries = new ArrayList<>(); int orderNumber = 1; - entries.add(new PageEntry(id, SimplePageMapper.PAGE_TYPE, orderNumber++)); + entries.add(new PageEntry(id, PAGE_TYPE, orderNumber++)); for (Tab t : tabs) { - entries.add(new PageEntry(t.getId(), SimplePageMapper.TAB, orderNumber++)); + entries.add(new PageEntry(t.getId(), TAB, orderNumber++)); for (Section s : t.getSections()) { - entries.add(new PageEntry(s.getId(), SimplePageMapper.SECTION, orderNumber++)); + entries.add(new PageEntry(s.getId(), SECTION, orderNumber++)); for (Subsection ss : s.getSubsections()) { - entries.add(new PageEntry(ss.getId(), SimplePageMapper.SUBSECTION, orderNumber++)); + entries.add(new PageEntry(ss.getId(), SUBSECTION, orderNumber++)); for (Element e : ss.getElements()) { entries.add(new PageEntry(e.getId(), e.getType(), orderNumber++)); } diff --git a/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/page/content/reorder/models/SimplePageMapper.java b/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/page/content/reorder/models/SimplePageMapper.java index 4de569899c..aa784c6d1f 100644 --- a/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/page/content/reorder/models/SimplePageMapper.java +++ b/apps/question-bank/src/main/java/gov/cdc/nbs/questionbank/page/content/reorder/models/SimplePageMapper.java @@ -9,10 +9,6 @@ import gov.cdc.nbs.questionbank.page.content.reorder.models.ReorderablePage.Tab; public class SimplePageMapper { - public static final int PAGE_TYPE = 1002; - public static final int TAB = 1010; - public static final int SECTION = 1015; - public static final int SUBSECTION = 1016; private List tabs = new ArrayList<>(); private Tab currentTab = null; @@ -23,20 +19,20 @@ public ReorderablePage toPage(List entries) { ReorderablePage page = null; for (PageEntry e : entries) { switch (e.component()) { - case PAGE_TYPE: + case ReorderablePage.PAGE_TYPE: page = new ReorderablePage(e.id()); break; - case TAB: { + case ReorderablePage.TAB: { rollUpTab(); currentTab = new Tab(e.id()); break; } - case SECTION: { + case ReorderablePage.SECTION: { rollUpSection(); currentSection = new Section(e.id()); break; } - case SUBSECTION: { + case ReorderablePage.SUBSECTION: { rollUpSubsection(); currentSubsection = new Subsection(e.id()); break; diff --git a/apps/question-bank/src/test/java/gov/cdc/nbs/questionbank/support/condition/ConditionMother.java b/apps/question-bank/src/test/java/gov/cdc/nbs/questionbank/support/condition/ConditionMother.java index b915422173..a1042213de 100644 --- a/apps/question-bank/src/test/java/gov/cdc/nbs/questionbank/support/condition/ConditionMother.java +++ b/apps/question-bank/src/test/java/gov/cdc/nbs/questionbank/support/condition/ConditionMother.java @@ -20,7 +20,7 @@ public class ConditionMother { @Autowired private LdfPageSetRepository ldfPageSetRepository; - private List allConditions = new ArrayList<>(); + private final List allConditions = new ArrayList<>(); public void clean() { conditionCodeRepository.deleteAll(); @@ -28,12 +28,6 @@ public void clean() { allConditions.clear(); } - public ConditionCode conditionCode() { - return allConditions.stream() - .filter(c -> c instanceof ConditionCode).findFirst() - .orElseGet(this::createCondition); - } - public ConditionCode one() { return allConditions.stream().findFirst() .orElseThrow(() -> new IllegalStateException("No conditions are available")); diff --git a/apps/question-bank/src/test/java/gov/cdc/nbs/questionbank/support/valueset/ValueSetMother.java b/apps/question-bank/src/test/java/gov/cdc/nbs/questionbank/support/valueset/ValueSetMother.java index 711e287fb4..ab5b6b4c43 100644 --- a/apps/question-bank/src/test/java/gov/cdc/nbs/questionbank/support/valueset/ValueSetMother.java +++ b/apps/question-bank/src/test/java/gov/cdc/nbs/questionbank/support/valueset/ValueSetMother.java @@ -159,11 +159,13 @@ private Codeset valueSetWithConcepts() { } public Codeset createMetadataEntry(Codeset valueset) { - CodeSetGroupMetadatum codeGrp = new CodeSetGroupMetadatum(); - codeGrp.setId(getCodeSetGroupID()); - codeGrp.setCodeSetDescTxt(valueset.getCodeSetDescTxt()); - codeGrp.setCodeSetNm(valueset.getValueSetNm()); - codeGrp.setCodeSetShortDescTxt(valueset.getValueSetNm()); + CodeSetGroupMetadatum codeGrp = new CodeSetGroupMetadatum( + getCodeSetGroupID(), + valueset.getCodeSetDescTxt(), + valueset.getValueSetNm(), + valueset.getValueSetNm() + ); + codeGrp.setLdfPicklistIndCd(valueset.getLdfPicklistIndCd()); codeGrp = codeSetGrpMetaRepository.save(codeGrp); valueset.setCodeSetGroup(codeGrp); diff --git a/libs/authentication/src/main/java/gov/cdc/nbs/authentication/entity/AuthBusObjRt.java b/libs/authentication/src/main/java/gov/cdc/nbs/authentication/entity/AuthBusObjRt.java index 3330991d55..30103c654e 100644 --- a/libs/authentication/src/main/java/gov/cdc/nbs/authentication/entity/AuthBusObjRt.java +++ b/libs/authentication/src/main/java/gov/cdc/nbs/authentication/entity/AuthBusObjRt.java @@ -32,6 +32,10 @@ public class AuthBusObjRt { @JoinColumn(name = "auth_bus_obj_type_uid", nullable = false) private AuthBusObjType authBusObjTypeUid; + @SuppressWarnings( + // Bidirectional mappings require knowledge of each other + "javaarchitecture:S7027" + ) @OneToOne( mappedBy = "authBusObjRtUid", cascade = { @@ -45,7 +49,7 @@ public class AuthBusObjRt { @Embedded private AuthAudit audit; - AuthBusObjRt() { + protected AuthBusObjRt() { } diff --git a/libs/authentication/src/main/java/gov/cdc/nbs/authentication/entity/AuthBusOpRt.java b/libs/authentication/src/main/java/gov/cdc/nbs/authentication/entity/AuthBusOpRt.java index 793c23c4b0..f84cb7019d 100644 --- a/libs/authentication/src/main/java/gov/cdc/nbs/authentication/entity/AuthBusOpRt.java +++ b/libs/authentication/src/main/java/gov/cdc/nbs/authentication/entity/AuthBusOpRt.java @@ -11,6 +11,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToOne; import jakarta.persistence.Table; @Entity @@ -25,8 +26,12 @@ public class AuthBusOpRt { @JoinColumn(name = "auth_bus_op_type_uid", nullable = false) private AuthBusOpType authBusOpTypeUid; + @SuppressWarnings( + // Bidirectional mappings require knowledge of each other + "javaarchitecture:S7027" + ) @JsonIgnore - @ManyToOne(fetch = FetchType.LAZY, optional = false) + @OneToOne(fetch = FetchType.LAZY, optional = false) @JoinColumn(name = "auth_bus_obj_rt_uid", nullable = false) private AuthBusObjRt authBusObjRtUid; @@ -39,7 +44,7 @@ public class AuthBusOpRt { @Embedded private AuthAudit audit; - AuthBusOpRt() { + protected AuthBusOpRt() { } diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/EntityId.java b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/EntityId.java index a859f38c93..7f09665d94 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/EntityId.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/EntityId.java @@ -18,7 +18,7 @@ @Table(name = "Entity_id") @SuppressWarnings( // The PatientIdentificationHistoryListener is an entity listener specifically for instances of this class - "javaarchitecture:S7027" + {"javaarchitecture:S7027", "javaarchitecture:S7091"} ) @EntityListeners(PatientIdentificationHistoryListener.class) public class EntityId { diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/EntityLocatorParticipation.java b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/EntityLocatorParticipation.java index 6e1eefb4fa..6672017d9a 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/EntityLocatorParticipation.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/EntityLocatorParticipation.java @@ -19,7 +19,7 @@ @Table(name = "Entity_locator_participation") @SuppressWarnings( // The PatientEntityLocatorHistoryListener is an entity listener specifically for instances of this class - "javaarchitecture:S7027" + {"javaarchitecture:S7027", "javaarchitecture:S7091"} ) @EntityListeners(PatientEntityLocatorHistoryListener.class) @Inheritance(strategy = InheritanceType.SINGLE_TABLE) diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PersonEthnicGroup.java b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PersonEthnicGroup.java index a38e83ff46..de0b771f3e 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PersonEthnicGroup.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PersonEthnicGroup.java @@ -15,8 +15,11 @@ @Setter @Entity @Table(name = "Person_ethnic_group") +@SuppressWarnings( + // The PatientEthnicityHistoryListener is an entity listener specifically for instances of this class + {"javaarchitecture:S7027","javaarchitecture:S7091"} +) @EntityListeners(PatientEthnicityHistoryListener.class) -@SuppressWarnings("javaarchitecture:S7027") // Bidirectional mappings require knowledge of each other public class PersonEthnicGroup { @EmbeddedId private PersonEthnicGroupId id; diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PersonName.java b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PersonName.java index f06d025f92..fe2f456f07 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PersonName.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PersonName.java @@ -30,7 +30,7 @@ @Table(name = "Person_name") @SuppressWarnings( // The PatientNameHistoryListener is an entity listener specifically for instances of this class - "javaarchitecture:S7027" + {"javaarchitecture:S7027","javaarchitecture:S7091"} ) @EntityListeners(PatientNameHistoryListener.class) public class PersonName { diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PersonRace.java b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PersonRace.java index bdc9377b48..df802824a2 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PersonRace.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PersonRace.java @@ -18,7 +18,7 @@ @IdClass(PersonRaceId.class) @SuppressWarnings( // The PatientRaceHistoryListener is an entity listener specifically for instances of this class - "javaarchitecture:S7027" + {"javaarchitecture:S7027","javaarchitecture:S7091"} ) @EntityListeners(PatientRaceHistoryListener.class) public class PersonRace { diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PostalEntityLocatorParticipation.java b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PostalEntityLocatorParticipation.java index 4337bbcc70..b147aa4aaf 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PostalEntityLocatorParticipation.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/PostalEntityLocatorParticipation.java @@ -14,8 +14,11 @@ @Entity @DiscriminatorValue(PostalEntityLocatorParticipation.POSTAL_CLASS_CODE) +@SuppressWarnings( + // The PatientPostalLocatorHistoryListener is an entity listener specifically for instances of this class + {"javaarchitecture:S7027","javaarchitecture:S7091"} +) @EntityListeners(PatientPostalLocatorHistoryListener.class) -@SuppressWarnings("javaarchitecture:S7027") // Bidirectional mappings require knowledge of each other public class PostalEntityLocatorParticipation extends EntityLocatorParticipation { static final String POSTAL_CLASS_CODE = "PST"; diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/TeleEntityLocatorParticipation.java b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/TeleEntityLocatorParticipation.java index c75016e8a4..4032779173 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/TeleEntityLocatorParticipation.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/entity/odse/TeleEntityLocatorParticipation.java @@ -8,6 +8,10 @@ @Entity @DiscriminatorValue(TeleEntityLocatorParticipation.TELECOM_CLASS_CODE) +@SuppressWarnings( + // The PatientPhoneLocatorHistoryListener is an entity listener specifically for instances of this class + {"javaarchitecture:S7027","javaarchitecture:S7091"} +) @EntityListeners(PatientPhoneLocatorHistoryListener.class) public class TeleEntityLocatorParticipation extends EntityLocatorParticipation { diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientEntityLocatorHistoryListener.java b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientEntityLocatorHistoryListener.java index 6b8cd4e7e8..780ef494f5 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientEntityLocatorHistoryListener.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientEntityLocatorHistoryListener.java @@ -14,7 +14,10 @@ public PatientEntityLocatorHistoryListener(PatientEntityLocatorHistoryCreator en } @PreUpdate - @SuppressWarnings("javaarchitecture:S7027") + @SuppressWarnings( + // The PatientEntityLocatorHistoryListener is an entity listener specifically for instances of EntityLocatorParticipation + {"javaarchitecture:S7027", "javaarchitecture:S7091"} + ) void preUpdate(final EntityLocatorParticipation entityLocatorParticipation) { int version = entityLocatorParticipation.getVersionCtrlNbr() - 1; this.creator.createEntityLocatorHistory(entityLocatorParticipation.getId().getEntityUid(), diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientEthnicityHistoryListener.java b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientEthnicityHistoryListener.java index be92018e2e..88cbc0f114 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientEthnicityHistoryListener.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientEthnicityHistoryListener.java @@ -8,6 +8,12 @@ @Component public class PatientEthnicityHistoryListener { + + private static final String QUERY = + "SELECT MAX(version_ctrl_nbr) FROM Person_ethnic_group_hist WHERE person_uid = ? and ethnic_group_cd = ?"; + private static final int IDENTIFIER_PARAMETER = 1; + private static final int GROUP_PARAMETER = 2; + private final PatientEthnicityHistoryCreator creator; private final JdbcTemplate template; @@ -17,7 +23,10 @@ public PatientEthnicityHistoryListener(PatientEthnicityHistoryCreator creator, J } @PreRemove - @SuppressWarnings("javaarchitecture:S7027") + @SuppressWarnings( + // The PatientEthnicityHistoryListener is an entity listener specifically for instances of PersonEthnicGroup + {"javaarchitecture:S7027","javaarchitecture:S7091"} + ) void preRemove(final PersonEthnicGroup personEthnicGroup) { long personUid = personEthnicGroup.getPersonUid().getId(); String personEthnicityGroupCd = personEthnicGroup.getId().getEthnicGroupCd(); @@ -26,9 +35,15 @@ void preRemove(final PersonEthnicGroup personEthnicGroup) { } - private int getCurrentVersionNumber(long personUid, String ethnicityGroupCd) { - String query = "SELECT MAX(version_ctrl_nbr) FROM Person_ethnic_group_hist WHERE person_uid = ? and ethnic_group_cd = ?"; - Integer maxVersionControlNumber = template.queryForObject(query, Integer.class, personUid, ethnicityGroupCd); - return maxVersionControlNumber != null ? maxVersionControlNumber : 0; + private int getCurrentVersionNumber(final long identifier, final String group) { + return template.query( + QUERY, statement -> { + statement.setLong(IDENTIFIER_PARAMETER, identifier); + statement.setString(GROUP_PARAMETER, group); + }, + (resultSet, row) -> resultSet.getInt(1)) + .stream() + .findFirst() + .orElse(0); } } diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientIdentificationHistoryListener.java b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientIdentificationHistoryListener.java index cead799bf8..ad404d4db6 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientIdentificationHistoryListener.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientIdentificationHistoryListener.java @@ -1,7 +1,6 @@ package gov.cdc.nbs.patient; import gov.cdc.nbs.entity.odse.EntityId; -import gov.cdc.nbs.entity.odse.EntityIdId; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Component; @@ -9,6 +8,11 @@ @Component public class PatientIdentificationHistoryListener { + + private static final String QUERY = "SELECT MAX(version_ctrl_nbr) FROM Entity_id_hist WHERE entity_uid = ? and entity_id_seq = ?"; + private static final int IDENTIFIER_PARAMETER = 1; + private static final int SEQUENCE_PARAMETER = 2; + private final PatientIdentificationHistoryCreator creator; private final JdbcTemplate template; @@ -18,18 +22,27 @@ public PatientIdentificationHistoryListener(PatientIdentificationHistoryCreator } @PreUpdate - @SuppressWarnings("javaarchitecture:S7027") + @SuppressWarnings( + // The PatientIdentificationHistoryListener is an entity listener specifically for instances of EntityId + {"javaarchitecture:S7027", "javaarchitecture:S7091"} + ) void preUpdate(final EntityId entityId) { - int entityIdSequence = entityId.getId().getEntityIdSeq(); - int currentVersion = getCurrentVersionNumber(entityId.getId(), entityIdSequence); - this.creator.createEntityIdHistory(entityId.getId().getEntityUid(), currentVersion + 1, entityIdSequence); + long identifier = entityId.getId().getEntityUid(); + int sequence = entityId.getId().getEntityIdSeq(); + int currentVersion = getCurrentVersionNumber(identifier, sequence); + this.creator.createEntityIdHistory(identifier, currentVersion + 1, sequence); } - private int getCurrentVersionNumber(EntityIdId id, int entityIdSequence) { - long entityUid = id.getEntityUid(); - String query = "SELECT MAX(version_ctrl_nbr) FROM Entity_id_hist WHERE entity_uid = ? and entity_id_seq = ?"; - Integer maxVersionControlNumber = template.queryForObject(query, Integer.class, entityUid, entityIdSequence); - return maxVersionControlNumber != null ? maxVersionControlNumber : 0; + private int getCurrentVersionNumber(long identifier, int sequence) { + return template.query( + QUERY, statement -> { + statement.setLong(IDENTIFIER_PARAMETER, identifier); + statement.setInt(SEQUENCE_PARAMETER, sequence); + }, + (resultSet, row) -> resultSet.getInt(1)) + .stream() + .findFirst() + .orElse(0); } } diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientNameHistoryListener.java b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientNameHistoryListener.java index 04777ad461..4c5ae02af6 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientNameHistoryListener.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientNameHistoryListener.java @@ -1,34 +1,47 @@ package gov.cdc.nbs.patient; -import gov.cdc.nbs.entity.odse.Person; import gov.cdc.nbs.entity.odse.PersonName; +import jakarta.persistence.PreUpdate; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Component; -import jakarta.persistence.PreUpdate; - @Component public class PatientNameHistoryListener { - private PatientNameHistoryCreator creator; - private final JdbcTemplate template; - public PatientNameHistoryListener(final PatientNameHistoryCreator creator, JdbcTemplate template) { - this.creator = creator; - this.template = template; - } + private static final String QUERY = + "SELECT max(version_ctrl_nbr) FROM Person_name_hist WHERE person_uid = ? and person_name_seq = ?"; + private static final int IDENTIFIER_PARAMETER = 1; + private static final int SEQUENCE_PARAMETER = 2; + + private final PatientNameHistoryCreator creator; + private final JdbcTemplate template; + + public PatientNameHistoryListener(final PatientNameHistoryCreator creator, JdbcTemplate template) { + this.creator = creator; + this.template = template; + } - @PreUpdate - @SuppressWarnings("javaarchitecture:S7027") - void preUpdate(PersonName personName) { - int personNameSequence = personName.getId().getPersonNameSeq(); - int currentVersion = getCurrentVersionNumber(personName.getPersonUid(), personNameSequence); - this.creator.createPersonNameHistory(personName.getPersonUid().getId(), currentVersion + 1, personNameSequence); - } + @PreUpdate + @SuppressWarnings( + // The PatientNameHistoryListener is an entity listener specifically for instances of PersonName + {"javaarchitecture:S7027", "javaarchitecture:S7091"} + ) + void preUpdate(final PersonName personName) { + long identifier = personName.getPersonUid().getId(); + int sequence = personName.getId().getPersonNameSeq(); + int currentVersion = getCurrentVersionNumber(identifier, sequence); + this.creator.createPersonNameHistory(identifier, currentVersion + 1, sequence); + } - private int getCurrentVersionNumber(Person id, int personNameSequence) { - long personUid = id.getId(); - String query = "SELECT MAX(version_ctrl_nbr) FROM Person_name_hist WHERE person_uid = ? and person_name_seq = ?"; - Integer maxVersionControlNumber = template.queryForObject(query, Integer.class, personUid, personNameSequence); - return maxVersionControlNumber != null ? maxVersionControlNumber : 0; - } + private int getCurrentVersionNumber(long identifier, int sequence) { + return template.query( + QUERY, statement -> { + statement.setLong(IDENTIFIER_PARAMETER, identifier); + statement.setInt(SEQUENCE_PARAMETER, sequence); + }, + (resultSet, row) -> resultSet.getInt(1)) + .stream() + .findFirst() + .orElse(0); + } } diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientPhoneLocatorHistoryListener.java b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientPhoneLocatorHistoryListener.java index acf8d6e626..7497301edf 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientPhoneLocatorHistoryListener.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientPhoneLocatorHistoryListener.java @@ -17,7 +17,10 @@ public PatientPhoneLocatorHistoryListener(PatientPhoneLocatorHistoryCreator crea } @PreUpdate - @SuppressWarnings("javaarchitecture:S7027") + @SuppressWarnings( + // The PatientPhoneLocatorHistoryListener is an entity listener specifically for instances of TeleEntityLocatorParticipation + {"javaarchitecture:S7027","javaarchitecture:S7091"} + ) void preUpdate(final TeleEntityLocatorParticipation teleEntityLocatorParticipation) { long locatorId = teleEntityLocatorParticipation.getId().getLocatorUid(); int currentVersion = getCurrentVersionNumber(locatorId); diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientPostalLocatorHistoryListener.java b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientPostalLocatorHistoryListener.java index d6adf06083..e6ad653dec 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientPostalLocatorHistoryListener.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientPostalLocatorHistoryListener.java @@ -17,7 +17,10 @@ public PatientPostalLocatorHistoryListener(PatientPostalLocatorHistoryCreator cr } @PreUpdate - @SuppressWarnings("javaarchitecture:S7027") + @SuppressWarnings( + // The PatientPostalLocatorHistoryListener is an entity listener specifically for instances of PostalEntityLocatorParticipation + {"javaarchitecture:S7027","javaarchitecture:S7091"} + ) void preUpdate(final PostalEntityLocatorParticipation postalEntityLocatorParticipation) { long locatorId = postalEntityLocatorParticipation.getId().getLocatorUid(); int currentVersion = getCurrentVersionNumber(locatorId); diff --git a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientRaceHistoryListener.java b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientRaceHistoryListener.java index db655c8b04..1e8735cb8d 100644 --- a/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientRaceHistoryListener.java +++ b/libs/database-entities/src/main/java/gov/cdc/nbs/patient/PatientRaceHistoryListener.java @@ -17,7 +17,7 @@ public PatientRaceHistoryListener(PatientRaceHistoryCreator creator, JdbcTemplat } @PreRemove - @SuppressWarnings("javaarchitecture:S7027") + @SuppressWarnings({"javaarchitecture:S7027","javaarchitecture:S7091"}) void preRemove(final PersonRace personRace) { long personUid = personRace.getPersonUid().getId(); String raceCode = personRace.getRaceCd();