Skip to content

Commit

Permalink
CNDE-1849 Hot fix for tombstone message calls (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
sveselev authored Oct 26, 2024
1 parent 197cb5c commit dcf4366
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

@Data
public class InvestigationTransformed {
private Long publicHealthCaseUid;
private Long investigatorId;
private Long physicianId;
private Long patientId;
Expand All @@ -13,4 +14,8 @@ public class InvestigationTransformed {
private String legacyCaseId;
private Long phcInvFormId;
private String rdbTableNameList;

public InvestigationTransformed(Long publicHealthCaseUid) {
this.publicHealthCaseUid = publicHealthCaseUid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public class ProcessInvestigationDataUtil {
@Transactional
public InvestigationTransformed transformInvestigationData(Investigation investigation) {

InvestigationTransformed investigationTransformed = new InvestigationTransformed();
InvestigationTransformed investigationTransformed = new InvestigationTransformed(investigation.getPublicHealthCaseUid());

transformPersonParticipations(investigation.getPersonParticipations(), investigationTransformed);
transformOrganizationParticipations(investigation.getOrganizationParticipations(), investigationTransformed);
transformActIds(investigation.getActIds(), investigationTransformed);
transformObservationIds(investigation.getObservationNotificationIds(), investigationTransformed);
transformInvestigationConfirmationMethod(investigation.getInvestigationConfirmationMethod());
transformInvestigationConfirmationMethod(investigation.getInvestigationConfirmationMethod(), investigationTransformed);
processInvestigationPageCaseAnswer(investigation.getInvestigationCaseAnswer(), investigationTransformed);

return investigationTransformed;
Expand Down Expand Up @@ -198,8 +198,13 @@ private void transformObservationIds(String observationNotificationIds, Investig
}
}

private void transformInvestigationConfirmationMethod(String investigationConfirmationMethod) {
private void transformInvestigationConfirmationMethod(String investigationConfirmationMethod, InvestigationTransformed investigationTransformed) {
try {
Long publicHealthCaseUid = investigationTransformed.getPublicHealthCaseUid();
// Tombstone message to delete all confirmation methods for specified phc uid
String jsonKey = jsonGenerator.generateStringJson(new InvestigationConfirmationMethodUidKey(publicHealthCaseUid));
kafkaTemplate.send(investigationConfirmationOutputTopicName, jsonKey, null);

JsonNode investigationConfirmationMethodJsonArray = parseJsonArray(investigationConfirmationMethod);

InvestigationConfirmationMethodKey investigationConfirmationMethodKey = new InvestigationConfirmationMethodKey();
Expand All @@ -209,7 +214,6 @@ private void transformInvestigationConfirmationMethod(String investigationConfir

// Redundant time variable in case if confirmation_method_time is null in all rows of the array
String phcLastChgTime = investigationConfirmationMethodJsonArray.get(0).get("phc_last_chg_time").asText();
Long publicHealthCaseUid = investigationConfirmationMethodJsonArray.get(0).get("public_health_case_uid").asLong();

for(JsonNode node : investigationConfirmationMethodJsonArray) {
JsonNode timeNode = node.get("confirmation_method_time");
Expand All @@ -224,10 +228,6 @@ private void transformInvestigationConfirmationMethod(String investigationConfir
investigationConfirmation.setConfirmationMethodTime(
confirmationMethodTime == null ? phcLastChgTime : confirmationMethodTime);

// Tombstone message to delete all confirmation methods for specified phc uid
String jsonKey = jsonGenerator.generateStringJson(new InvestigationConfirmationMethodUidKey(publicHealthCaseUid));
kafkaTemplate.send(investigationConfirmationOutputTopicName, jsonKey, null);

for(Map.Entry<String, String> entry : confirmationMethodMap.entrySet()) {
investigationConfirmation.setConfirmationMethodCd(entry.getKey());
investigationConfirmation.setConfirmationMethodDescTxt(entry.getValue());
Expand All @@ -237,24 +237,26 @@ private void transformInvestigationConfirmationMethod(String investigationConfir
kafkaTemplate.send(investigationConfirmationOutputTopicName, jsonKey, jsonValue);
}
} catch (IllegalArgumentException ex) {
logger.info(ex.getMessage(), "InvestigationObservationIds");
logger.info(ex.getMessage(), "InvestigationConfirmationMethod");
} catch (Exception e) {
logger.error("Error processing investigation confirmation method JSON array from investigation data: {}", e.getMessage());
}
}

private void processInvestigationPageCaseAnswer(String investigationCaseAnswer, InvestigationTransformed investigationTransformed) {
try {
JsonNode investigationCaseAnswerJsonArray = parseJsonArray(investigationCaseAnswer);

Long actUid = investigationCaseAnswerJsonArray.get(0).get("act_uid").asLong();
List<PageCaseAnswer> pageCaseAnswerList = new ArrayList<>();
Long publicHealthCaseUid = investigationTransformed.getPublicHealthCaseUid();

// Tombstone message to delete all page case answers for specified actUid
PageCaseAnswerUidKey pageCaseAnswerUidKey = new PageCaseAnswerUidKey(actUid);
PageCaseAnswerUidKey pageCaseAnswerUidKey = new PageCaseAnswerUidKey(publicHealthCaseUid);
String jsonKey = jsonGenerator.generateStringJson(pageCaseAnswerUidKey);
kafkaTemplate.send(pageCaseAnswerOutputTopicName, jsonKey, null);

JsonNode investigationCaseAnswerJsonArray = parseJsonArray(investigationCaseAnswer);

Long actUid = investigationCaseAnswerJsonArray.get(0).get("act_uid").asLong();
List<PageCaseAnswer> pageCaseAnswerList = new ArrayList<>();

PageCaseAnswerKey pageCaseAnswerKey = new PageCaseAnswerKey();
pageCaseAnswerKey.setActUid(actUid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ void testConfirmationMethod() throws JsonProcessingException {
confirmationMethod.setConfirmationMethodTime("2024-01-15T10:20:57.001");

transformer.transformInvestigationData(investigation);
verify(kafkaTemplate, times(3)).send(topicCaptor.capture(), keyCaptor.capture(), messageCaptor.capture());
assertEquals(CONFIRMATION_TOPIC, topicCaptor.getValue());
verify(kafkaTemplate, times(4)).send(topicCaptor.capture(), keyCaptor.capture(), messageCaptor.capture());
assertEquals(CONFIRMATION_TOPIC, topicCaptor.getAllValues().getFirst());

var actualConfirmationMethod = objectMapper.readValue(
objectMapper.readTree(messageCaptor.getValue()).path("payload").toString(), InvestigationConfirmationMethod.class);
objectMapper.readTree(messageCaptor.getAllValues().get(2)).path("payload").toString(), InvestigationConfirmationMethod.class);
var actualKey = objectMapper.readValue(
objectMapper.readTree(keyCaptor.getValue()).path("payload").toString(), InvestigationConfirmationMethodKey.class);
objectMapper.readTree(keyCaptor.getAllValues().get(2)).path("payload").toString(), InvestigationConfirmationMethodKey.class);

assertEquals(confirmationMethodKey, actualKey);
assertEquals(confirmationMethod, actualConfirmationMethod);
Expand Down Expand Up @@ -134,14 +134,14 @@ void testObservationNotificationIds() throws JsonProcessingException {

InvestigationObservation observation = new InvestigationObservation();
observation.setPublicHealthCaseUid(investigationUid);
observation.setObservationId(263748599L);
observation.setObservationId(263748596L);

transformer.transformInvestigationData(investigation);
verify(kafkaTemplate, times(2)).send(topicCaptor.capture(), keyCaptor.capture(), messageCaptor.capture());
assertEquals(OBSERVATION_TOPIC, topicCaptor.getValue());
verify(kafkaTemplate, times(4)).send(topicCaptor.capture(), keyCaptor.capture(), messageCaptor.capture());
assertEquals(OBSERVATION_TOPIC, topicCaptor.getAllValues().getFirst());

var actualObservation = objectMapper.readValue(
objectMapper.readTree(messageCaptor.getValue()).path("payload").toString(), InvestigationObservation.class);
objectMapper.readTree(messageCaptor.getAllValues().getFirst()).path("payload").toString(), InvestigationObservation.class);

assertEquals(observation, actualObservation);
}
Expand Down Expand Up @@ -207,13 +207,13 @@ void testPageCaseAnswer() throws JsonProcessingException {
PageCaseAnswer pageCaseAnswer = constructCaseAnswer();

transformer.transformInvestigationData(investigation);
verify(kafkaTemplate, times(4)).send(topicCaptor.capture(), keyCaptor.capture(), messageCaptor.capture());
verify(kafkaTemplate, times(5)).send(topicCaptor.capture(), keyCaptor.capture(), messageCaptor.capture());
assertEquals(PAGE_CASE_ANSWER_TOPIC, topicCaptor.getValue());

var actualPageCaseAnswer = objectMapper.readValue(
objectMapper.readTree(messageCaptor.getAllValues().get(2)).path("payload").toString(), PageCaseAnswer.class);
objectMapper.readTree(messageCaptor.getAllValues().get(3)).path("payload").toString(), PageCaseAnswer.class);
var actualKey = objectMapper.readValue(
objectMapper.readTree(keyCaptor.getAllValues().get(2)).path("payload").toString(), PageCaseAnswerKey.class);
objectMapper.readTree(keyCaptor.getAllValues().get(3)).path("payload").toString(), PageCaseAnswerKey.class);

assertEquals(pageCaseAnswerKey, actualKey);
assertEquals(pageCaseAnswer, actualPageCaseAnswer);
Expand Down

0 comments on commit dcf4366

Please sign in to comment.