Browse Source

Death certificate gather informant

Andrew Grant 2 months ago
parent
commit
8a2561feb0

+ 19 - 2
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/GatherDeathCertificateTimeLineDataImpl.java

@@ -12,6 +12,7 @@ import scot.carricksoftware.grantswriter.domains.certificates.deathcertificate.D
 import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.services.certificates.deathcertificate.DeathCertificateService;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.deathcertificate.GatherDeathCertificateDeceasedTimeLineData;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.deathcertificate.GatherDeathCertificateInformantTimeLineData;
 
 import java.util.List;
 
@@ -22,19 +23,35 @@ public class GatherDeathCertificateTimeLineDataImpl implements GatherDeathCertif
 
     private final DeathCertificateService deathCertificateService;
     private final GatherDeathCertificateDeceasedTimeLineData gatherDeathCertificateDeceasedTimeLineData;
+    private final GatherDeathCertificateInformantTimeLineData gatherDeathCertificateInformantTimeLineData;
 
-    public GatherDeathCertificateTimeLineDataImpl(DeathCertificateService deathCertificateService, GatherDeathCertificateDeceasedTimeLineData gatherDeathCertificateDeceasedTimeLineData) {
+    public GatherDeathCertificateTimeLineDataImpl(DeathCertificateService deathCertificateService, GatherDeathCertificateDeceasedTimeLineData gatherDeathCertificateDeceasedTimeLineData, GatherDeathCertificateInformantTimeLineData gatherDeathCertificateInformantTimeLineData) {
         this.deathCertificateService = deathCertificateService;
         this.gatherDeathCertificateDeceasedTimeLineData = gatherDeathCertificateDeceasedTimeLineData;
+        this.gatherDeathCertificateInformantTimeLineData = gatherDeathCertificateInformantTimeLineData;
     }
 
     @Override
     public void gather(Person person) {
-       logger.debug("GatherDeathCertificateTimeLineDataImpl::gather");
+        logger.debug("GatherDeathCertificateTimeLineDataImpl::gather");
+        gatherDeceased(person);
+        gatherInformant(person);
+    }
+
+    private void gatherDeceased(Person person) {
+        logger.debug("GatherDeathCertificateTimeLineDataImpl::gatherDeceased");
         List<DeathCertificate> deathCertificates = deathCertificateService.findAllByDeceased(person);
         if (!deathCertificates.isEmpty()) {
             gatherDeathCertificateDeceasedTimeLineData.gather(deathCertificates);
         }
     }
 
+    private void gatherInformant(Person person) {
+        logger.debug("GatherDeathCertificateTimeLineDataImpl::gatherInformant");
+        List<DeathCertificate> deathCertificates = deathCertificateService.findAllByInformant(person);
+        if (!deathCertificates.isEmpty()) {
+            gatherDeathCertificateInformantTimeLineData.gather(deathCertificates);
+        }
+    }
+
 }

+ 15 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/level2/deathcertificate/GatherDeathCertificateInformantTimeLineData.java

@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.deathcertificate;
+
+import scot.carricksoftware.grantswriter.domains.certificates.deathcertificate.DeathCertificate;
+
+import java.util.List;
+
+public interface GatherDeathCertificateInformantTimeLineData {
+   void gather(List<DeathCertificate> deathCertificates);
+
+}

+ 75 - 0
src/main/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/level2/deathcertificate/GatherDeathCertificateInformantTimeLineDataImpl.java

@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2025.  Andrew Grant Carrick Software. All rights reserved
+ *
+ */
+
+package scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.deathcertificate;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.springframework.stereotype.Component;
+import scot.carricksoftware.grantswriter.data.DMY;
+import scot.carricksoftware.grantswriter.data.DMYImpl;
+import scot.carricksoftware.grantswriter.data.TimeLineData;
+import scot.carricksoftware.grantswriter.domains.certificates.deathcertificate.DeathCertificate;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.TreeMap;
+
+@Component
+public class GatherDeathCertificateInformantTimeLineDataImpl implements GatherDeathCertificateInformantTimeLineData {
+
+    private final TimeLineData timelineData;
+
+    private static final Logger logger = LogManager.getLogger(GatherDeathCertificateInformantTimeLineDataImpl.class);
+
+    public GatherDeathCertificateInformantTimeLineDataImpl(TimeLineData timelineData) {
+        this.timelineData = timelineData;
+    }
+
+    @Override
+    public void gather(List<DeathCertificate> deathCertificates) {
+        logger.info("GatherDeathCertificateInformantTimeLineDataImpl::Gather");
+        for (DeathCertificate deathCertificate : deathCertificates) {
+            addRegisteredTheDeath(timelineData.getTimeLine(), deathCertificate);
+            addRefs(deathCertificate);
+        }
+    }
+
+    @SuppressWarnings("unused")
+    private void addRefs(DeathCertificate deathCertificate) {
+        timelineData.getRefs().add("Death Certificate for : " + deathCertificate.getDeceased().toString());
+    }
+
+
+    @SuppressWarnings("unused")
+    private void addRegisteredTheDeath(TreeMap<DMY, List<String>> timeLine, DeathCertificate deathCertificate) {
+        logger.info("GatherDeathCertificateInformantTimeLineDataImpl::AddWhenRegistered");
+
+        if (deathCertificate.getWhenRegistered() != null  && !deathCertificate.getWhenRegistered().isEmpty()) {
+
+            List<String> existingValues = timeLine.get(getDMY(deathCertificate.getWhenRegistered()));
+            if (existingValues == null) {
+                existingValues = new ArrayList<>();
+            }
+
+            String whereRegistered;
+
+            if (deathCertificate.getWhereRegistered() != null  && !deathCertificate.getWhereRegistered().isEmpty()) {
+                whereRegistered = deathCertificate.getWhereRegistered();
+            } else {
+                whereRegistered = deathCertificate.getRegistrationAuthority().toString();
+            }
+
+            existingValues.add("Registered the death of " + deathCertificate.getDeceased() + " at " + whereRegistered);
+            timeLine.put(getDMY(deathCertificate.getWhenRegistered()), existingValues);
+        }
+    }
+
+    private DMY getDMY(String dateKey) {
+        DMY dmyKey = new DMYImpl();
+        dmyKey.parse(dateKey);
+        return dmyKey;
+    }
+}

+ 9 - 4
src/test/java/scot/carricksoftware/grantswriter/writer/latex/parts/people/subsections/helpers/GatherDeathCertificateTimeLineDataTest.java

@@ -14,6 +14,7 @@ import scot.carricksoftware.grantswriter.domains.certificates.deathcertificate.D
 import scot.carricksoftware.grantswriter.domains.people.Person;
 import scot.carricksoftware.grantswriter.services.certificates.deathcertificate.DeathCertificateService;
 import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.deathcertificate.GatherDeathCertificateDeceasedTimeLineData;
+import scot.carricksoftware.grantswriter.writer.latex.parts.people.subsections.helpers.level2.deathcertificate.GatherDeathCertificateInformantTimeLineData;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -32,7 +33,10 @@ class GatherDeathCertificateTimeLineDataTest {
     private DeathCertificateService deathCertificateServiceMock;
 
     @Mock
-    private GatherDeathCertificateDeceasedTimeLineData gatherDeathCertificateNewBornTimeLineDataMock;
+    private GatherDeathCertificateDeceasedTimeLineData gatherDeathCertificateDeceasedTimeLineDataMock;
+
+    @Mock
+    private GatherDeathCertificateInformantTimeLineData gatherDeathCertificateInformantTimeLineDataMock;
 
 
     List<DeathCertificate> deathCertificates;
@@ -42,7 +46,8 @@ class GatherDeathCertificateTimeLineDataTest {
     void setUp() {
         gatherDeathCertificateTimeLineData = new GatherDeathCertificateTimeLineDataImpl(
                 deathCertificateServiceMock,
-                gatherDeathCertificateNewBornTimeLineDataMock);
+                gatherDeathCertificateDeceasedTimeLineDataMock,
+                gatherDeathCertificateInformantTimeLineDataMock);
         deathCertificates = new ArrayList<>();
 
         person = GetRandomPerson();
@@ -55,14 +60,14 @@ class GatherDeathCertificateTimeLineDataTest {
         when(deathCertificateServiceMock.findAllByDeceased(person)).thenReturn(deathCertificates);
 
         gatherDeathCertificateTimeLineData.gather(person);
-        verify(gatherDeathCertificateNewBornTimeLineDataMock).gather(deathCertificates);
+        verify(gatherDeathCertificateDeceasedTimeLineDataMock).gather(deathCertificates);
     }
 
     @Test
     void nullDeceasedTest() {
         when(deathCertificateServiceMock.findAllByDeceased(person)).thenReturn(deathCertificates);
         gatherDeathCertificateTimeLineData.gather(person);
-        verifyNoInteractions(gatherDeathCertificateNewBornTimeLineDataMock);
+        verifyNoInteractions(gatherDeathCertificateDeceasedTimeLineDataMock);
     }
 
 }