diff --git a/db/upgrade/odse/routines/021-sp_treatment_event.sql b/db/upgrade/odse/routines/021-sp_treatment_event.sql index 59160171..3bb318f9 100644 --- a/db/upgrade/odse/routines/021-sp_treatment_event.sql +++ b/db/upgrade/odse/routines/021-sp_treatment_event.sql @@ -47,12 +47,12 @@ BEGIN par1.subject_entity_uid AS provider_uid, viewPatientKeys.treatment_uid AS patient_treatment_uid, act2.target_act_uid AS morbidity_uid, - rx1.LOCAL_ID, - rx1.ADD_TIME, - rx1.ADD_USER_ID, - rx1.LAST_CHG_TIME, - rx1.LAST_CHG_USER_ID, - rx1.VERSION_CTRL_NBR + rx1.local_id, + rx1.add_time, + rx1.add_user_id, + rx1.last_chg_time, + rx1.last_chg_user_id, + rx1.version_ctrl_nbr INTO #TREATMENT_UIDS FROM NBS_ODSE.dbo.treatment AS rx1 WITH (NOLOCK) INNER JOIN NBS_ODSE.dbo.Treatment_administered AS rx2 WITH (NOLOCK) @@ -117,31 +117,27 @@ BEGIN t.provider_uid, t.patient_treatment_uid, t.morbidity_uid, - rx1.cd_desc_txt AS Treatment_nm, - rx1.program_jurisdiction_oid AS Treatment_oid, - REPLACE(REPLACE(rx1.txt, CHAR(13) + CHAR(10), ' '), CHAR(10), ' ') AS Treatment_comments, - rx1.shared_ind AS Treatment_shared_ind, + rx1.cd_desc_txt AS treatment_name, + rx1.program_jurisdiction_oid AS treatment_oid, + REPLACE(REPLACE(rx1.txt, CHAR(13) + CHAR(10), ' '), CHAR(10), ' ') AS treatment_comments, + rx1.shared_ind AS treatment_shared_ind, rx1.cd, - rx2.effective_from_time AS Treatment_dt, - rx2.cd AS Treatment_drug, - rx2.cd_desc_txt AS Treatment_drug_nm, - rx2.dose_qty AS Treatment_dosage_strength, - rx2.dose_qty_unit_cd AS Treatment_dosage_strength_unit, - rx2.interval_cd AS Treatment_frequency, - rx2.effective_duration_amt AS Treatment_duration, - rx2.effective_duration_unit_cd AS Treatment_duration_unit, - rx2.route_cd AS Treatment_route, - t.LOCAL_ID, - CASE - WHEN rx1.record_status_cd = '' THEN 'ACTIVE' - WHEN rx1.record_status_cd = 'LOG_DEL' THEN 'INACTIVE' - ELSE rx1.record_status_cd - END as record_status_cd, - t.ADD_TIME, - t.ADD_USER_ID, - t.LAST_CHG_TIME, - t.LAST_CHG_USER_ID, - t.VERSION_CTRL_NBR + rx2.effective_from_time AS treatment_date, + rx2.cd AS treatment_drug, + rx2.cd_desc_txt AS treatment_drug_name, + rx2.dose_qty AS treatment_dosage_strength, + rx2.dose_qty_unit_cd AS treatment_dosage_strength_unit, + rx2.interval_cd AS treatment_frequency, + rx2.effective_duration_amt AS treatment_duration, + rx2.effective_duration_unit_cd AS treatment_duration_unit, + rx2.route_cd AS treatment_route, + t.local_id, + dbo.fn_get_record_status(rx1.record_status_cd) as record_status_cd, + t.add_time, + t.add_user_id, + t.last_chg_time, + t.last_chg_user_id, + t.version_ctrl_nbr INTO #TREATMENT_DETAILS FROM #TREATMENT_UIDS t INNER JOIN NBS_ODSE.dbo.treatment rx1 WITH (NOLOCK) @@ -176,27 +172,27 @@ BEGIN t.provider_uid, t.morbidity_uid, t.patient_treatment_uid, - t.Treatment_nm, - t.Treatment_oid, - t.Treatment_comments, - t.Treatment_shared_ind, + t.treatment_name, + t.treatment_oid, + t.treatment_comments, + t.treatment_shared_ind, t.cd, - t.Treatment_dt, - t.Treatment_drug, - t.Treatment_drug_nm, - t.Treatment_dosage_strength, - t.Treatment_dosage_strength_unit, - t.Treatment_frequency, - t.Treatment_duration, - t.Treatment_duration_unit, - t.Treatment_route, - t.LOCAL_ID, + t.treatment_date, + t.treatment_drug, + t.treatment_drug_name, + t.treatment_dosage_strength, + t.treatment_dosage_strength_unit, + t.treatment_frequency, + t.treatment_duration, + t.treatment_duration_unit, + t.treatment_route, + t.local_id, t.record_status_cd, - t.ADD_TIME, - t.ADD_USER_ID, - t.LAST_CHG_TIME, - t.LAST_CHG_USER_ID, - t.VERSION_CTRL_NBR + t.add_time, + t.add_user_id, + t.last_chg_time, + t.last_chg_user_id, + t.version_ctrl_nbr FROM #TREATMENT_DETAILS t; diff --git a/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/controller/InvestigationController.java b/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/controller/InvestigationController.java index 40b73249..2282d04d 100644 --- a/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/controller/InvestigationController.java +++ b/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/controller/InvestigationController.java @@ -29,6 +29,9 @@ public class InvestigationController { @Value("${spring.kafka.input.topic-name-vac}") private String vaccinationTopic; + @Value("${spring.kafka.input.topic-name-tmt}") + private String treatmentTopic; + @GetMapping("/reporting/investigation-svc/status") public ResponseEntity getDataPipelineStatusHealth() { @@ -60,4 +63,9 @@ public void postContact(@RequestBody String jsonData) { public void postVaccination(@RequestBody String jsonData) { producerService.sendMessage(vaccinationTopic, jsonData); } + + @PostMapping("/reporting/investigation-svc/treatment") + public void postTreatment(@RequestBody String jsonData) + {producerService.sendMessage(treatmentTopic, jsonData);} + } diff --git a/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/repository/TreatmentRepository.java b/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/repository/TreatmentRepository.java new file mode 100644 index 00000000..5274e9ac --- /dev/null +++ b/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/repository/TreatmentRepository.java @@ -0,0 +1,14 @@ +package gov.cdc.etldatapipeline.investigation.repository; + +import gov.cdc.etldatapipeline.investigation.repository.model.dto.Treatment; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.Optional; + +public interface TreatmentRepository extends JpaRepository { + + @Query(nativeQuery = true, value = "exec sp_treatment_event :treatment_uid") + Optional computeTreatment(@Param("treatment_uid") String treatmentUid); +} diff --git a/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/repository/model/dto/Treatment.java b/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/repository/model/dto/Treatment.java new file mode 100644 index 00000000..56f24d57 --- /dev/null +++ b/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/repository/model/dto/Treatment.java @@ -0,0 +1,92 @@ +package gov.cdc.etldatapipeline.investigation.repository.model.dto; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; +import lombok.Data; + +@Entity +@Data +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class Treatment { + @Id + @Column(name = "treatment_uid") + private String treatmentUid; + + @Column(name = "public_health_case_uid") + private String publicHealthCaseUid; + + @Column(name = "organization_uid") + private String organizationUid; + + @Column(name = "provider_uid") + private String providerUid; + + @Column(name = "patient_treatment_uid") + private String patientTreatmentUid; + + @Column(name = "treatment_name") + private String treatmentName; + + @Column(name = "treatment_oid") + private String treatmentOid; + + @Column(name = "treatment_comments") + private String treatmentComments; + + @Column(name = "treatment_shared_ind") + private String treatmentSharedInd; + + @Column(name = "cd") + private String cd; + + @Column(name = "treatment_date") + private String treatmentDate; + + @Column(name = "treatment_drug") + private String treatmentDrug; + + @Column(name = "treatment_drug_name") + private String treatmentDrugName; + + @Column(name = "treatment_dosage_strength") + private String treatmentDosageStrength; + + @Column(name = "treatment_dosage_strength_unit") + private String treatmentDosageStrengthUnit; + + @Column(name = "treatment_frequency") + private String treatmentFrequency; + + @Column(name = "treatment_duration") + private String treatmentDuration; + + @Column(name = "treatment_duration_unit") + private String treatmentDurationUnit; + + @Column(name = "treatment_route") + private String treatmentRoute; + + @Column(name = "local_id") + private String localId; + + @Column(name = "record_status_cd") + private String recordStatusCd; + + @Column(name = "add_time") + private String addTime; + + @Column(name = "add_user_id") + private String addUserId; + + @Column(name = "last_chg_time") + private String lastChangeTime; + + @Column(name = "last_chg_user_id") + private String lastChangeUserId; + + @Column(name = "version_ctrl_nbr") + private String versionControlNumber; +} diff --git a/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/repository/model/reporting/TreatmentReportingKey.java b/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/repository/model/reporting/TreatmentReportingKey.java new file mode 100644 index 00000000..9a14f8a4 --- /dev/null +++ b/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/repository/model/reporting/TreatmentReportingKey.java @@ -0,0 +1,17 @@ +package gov.cdc.etldatapipeline.investigation.repository.model.reporting; + +import com.fasterxml.jackson.databind.PropertyNamingStrategies; +import com.fasterxml.jackson.databind.annotation.JsonNaming; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.AllArgsConstructor; +import lombok.NonNull; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) +public class TreatmentReportingKey { + @NonNull + private String treatmentUid; +} diff --git a/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/service/InvestigationService.java b/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/service/InvestigationService.java index f5ca2c79..603af6e0 100644 --- a/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/service/InvestigationService.java +++ b/investigation-service/src/main/java/gov/cdc/etldatapipeline/investigation/service/InvestigationService.java @@ -6,6 +6,7 @@ import gov.cdc.etldatapipeline.investigation.repository.model.dto.*; import gov.cdc.etldatapipeline.investigation.repository.model.reporting.InvestigationKey; import gov.cdc.etldatapipeline.investigation.repository.model.reporting.InvestigationReporting; +import gov.cdc.etldatapipeline.investigation.repository.model.reporting.TreatmentReportingKey; import gov.cdc.etldatapipeline.investigation.util.ProcessInvestigationDataUtil; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; @@ -60,6 +61,12 @@ public class InvestigationService { @Value("${spring.kafka.input.topic-name-vac}") private String vaccinationTopic; + @Value("${spring.kafka.input.topic-name-tmt}") + private String treatmentTopic; + + @Value("${spring.kafka.output.topic-name-treatment}") + private String treatmentOutputTopicName; + @Value("${spring.kafka.output.topic-name-reporting}") private String investigationTopicReporting; @@ -77,6 +84,7 @@ public class InvestigationService { private final InterviewRepository interviewRepository; private final ContactRepository contactRepository; private final VaccinationRepository vaccinationRepository; + private final TreatmentRepository treatmentRepository; private final KafkaTemplate kafkaTemplate; private final ProcessInvestigationDataUtil processDataUtil; @@ -132,6 +140,8 @@ public void processMessage(ConsumerRecord rec, processContact(message); } else if (topic.equals(vaccinationTopic)) { processVaccination(message); + } else if (topic.equals(treatmentTopic)) { + processTreatment(message); } consumer.commitSync(); } @@ -260,6 +270,36 @@ private void processVaccination(String value) { } } + private void processTreatment(String value) { + String treatmentUid = ""; + try { + treatmentUid = extractUid(value, "treatment_uid"); + + logger.info(topicDebugLog, "Treatment", treatmentUid, treatmentTopic); + Optional treatmentData = treatmentRepository.computeTreatment(treatmentUid); + if(treatmentData.isPresent()) { + Treatment treatment = treatmentData.get(); + + // Using Treatment directly as the reporting object + TreatmentReportingKey treatmentReportingKey = new TreatmentReportingKey(treatment.getTreatmentUid()); + + String jsonKey = jsonGenerator.generateStringJson(treatmentReportingKey); + String jsonValue = jsonGenerator.generateStringJson(treatment); + + kafkaTemplate.send(treatmentOutputTopicName, jsonKey, jsonValue) + .whenComplete((res, e) -> logger.info("Treatment data (uid={}) sent to {}", + treatment.getTreatmentUid(), treatmentOutputTopicName)); + + } else { + throw new EntityNotFoundException("Unable to find treatment with id: " + treatmentUid); + } + } catch (EntityNotFoundException ex) { + throw new NoDataException(ex.getMessage(), ex); + } catch (Exception e) { + throw new RuntimeException(errorMessage("Treatment", treatmentUid, e), e); + } + } + // This same method can be used for elastic search as well and that is why the generic model is present private CompletableFuture> pushKeyValuePairToKafka(InvestigationKey investigationKey, Object model, String topicName) { String jsonKey = jsonGenerator.generateStringJson(investigationKey); diff --git a/investigation-service/src/main/resources/application.yaml b/investigation-service/src/main/resources/application.yaml index c9c62a49..2f454e0b 100644 --- a/investigation-service/src/main/resources/application.yaml +++ b/investigation-service/src/main/resources/application.yaml @@ -6,6 +6,7 @@ spring: topic-name-int: nbs_Interview topic-name-ctr: nbs_CT_contact topic-name-vac: nbs_Intervention + topic-name-tmt: nbs_Treatment output: topic-name-reporting: nrt_investigation topic-name-confirmation: nrt_investigation_confirmation @@ -21,6 +22,7 @@ spring: topic-name-contact-answer: nrt_contact_answer topic-name-vaccination: nrt_vaccination topic-name-vaccination-answer: nrt_vaccination_answer + topic-name-treatment: nrt_treatment dlq: retry-suffix: _retry dlq-suffix: _dlt diff --git a/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/InvestigationDataProcessingTests.java b/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/InvestigationDataProcessingTests.java index f04dd123..b30bcdd9 100644 --- a/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/InvestigationDataProcessingTests.java +++ b/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/InvestigationDataProcessingTests.java @@ -77,6 +77,8 @@ class InvestigationDataProcessingTests { ProcessInvestigationDataUtil transformer; + + @BeforeEach void setUp() { closeable = MockitoAnnotations.openMocks(this); diff --git a/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/controller/InvestigationControllerTest.java b/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/controller/InvestigationControllerTest.java index 3d38114c..9a0eff94 100644 --- a/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/controller/InvestigationControllerTest.java +++ b/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/controller/InvestigationControllerTest.java @@ -50,7 +50,8 @@ public void tearDown() throws Exception { "/reporting/investigation-svc/notification", "/reporting/investigation-svc/interview", "/reporting/investigation-svc/contact", - "/reporting/investigation-svc/vaccination" + "/reporting/investigation-svc/vaccination", + "/reporting/investigation-svc/treatment" }) void testControllerMethods(String endpoint) throws Exception { String jsonData = "{\"key\":\"value\"}"; diff --git a/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/service/InvestigationServiceTest.java b/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/service/InvestigationServiceTest.java index 662657ab..a84e4a17 100644 --- a/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/service/InvestigationServiceTest.java +++ b/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/service/InvestigationServiceTest.java @@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test; import org.mockito.*; import org.springframework.kafka.core.KafkaTemplate; +import org.springframework.kafka.support.SendResult; import java.util.List; import java.util.NoSuchElementException; @@ -47,6 +48,9 @@ class InvestigationServiceTest { @Mock private ContactRepository contactRepository; + @Mock + private TreatmentRepository treatmentRepository; + @Mock private VaccinationRepository vaccinationRepository; @@ -75,6 +79,7 @@ class InvestigationServiceTest { private final String interviewTopic = "Interview"; private final String contactTopic = "Contact"; private final String vaccinationTopic = "Vaccination"; + private final String treatmentTopic = "Treatment"; //output topics private final String investigationTopicOutput = "InvestigationOutput"; @@ -82,6 +87,8 @@ class InvestigationServiceTest { private final String interviewTopicOutput = "InterviewOutput"; private final String contactTopicOutput = "ContactOutput"; private final String vaccinationTopicOutput = "VaccinationOutput"; + private final String treatmentTopicOutput = "TreatmentOutput"; + @@ -90,7 +97,7 @@ void setUp() { closeable = MockitoAnnotations.openMocks(this); ProcessInvestigationDataUtil transformer = new ProcessInvestigationDataUtil(kafkaTemplate, investigationRepository); - investigationService = new InvestigationService(investigationRepository, notificationRepository, interviewRepository, contactRepository, vaccinationRepository, kafkaTemplate, transformer); + investigationService = new InvestigationService(investigationRepository, notificationRepository, interviewRepository, contactRepository, vaccinationRepository,treatmentRepository, kafkaTemplate, transformer); investigationService.setPhcDatamartEnable(true); investigationService.setBmirdCaseEnable(true); @@ -101,6 +108,8 @@ void setUp() { investigationService.setInterviewTopic(interviewTopic); investigationService.setContactTopic(contactTopic); investigationService.setVaccinationTopic(vaccinationTopic); + investigationService.setTreatmentTopic(treatmentTopic); + investigationService.setTreatmentOutputTopicName(treatmentTopicOutput); transformer.setInvestigationConfirmationOutputTopicName("investigationConfirmation"); transformer.setInvestigationObservationOutputTopicName("investigationObservation"); @@ -418,6 +427,60 @@ private void validateInvestigationData(String payload, Investigation investigati assertEquals(reportingModel, actualReporting); } + @Test + void testProcessTreatmentMessage() throws JsonProcessingException { + Long treatmentUid = 234567890L; + String payload = "{\"payload\": {\"after\": {\"treatment_uid\": \"" + treatmentUid + "\"}}}"; + + final Treatment treatment = constructTreatment(treatmentUid); + + when(treatmentRepository.computeTreatment(String.valueOf(treatmentUid))).thenReturn(Optional.of(treatment)); + + CompletableFuture> future = new CompletableFuture<>(); + when(kafkaTemplate.send(anyString(), anyString(), anyString())).thenReturn(future); + + // Create a ConsumerRecord object + ConsumerRecord rec = getRecord(treatmentTopic, payload); + investigationService.processMessage(rec, consumer); + future.complete(null); + + verify(treatmentRepository).computeTreatment(String.valueOf(treatmentUid)); + verify(kafkaTemplate).send(topicCaptor.capture(), keyCaptor.capture(), messageCaptor.capture()); + + assertEquals(treatmentTopicOutput, topicCaptor.getValue()); + + String treatmentJson = messageCaptor.getValue(); + Treatment actualTreatment = objectMapper.readValue( + objectMapper.readTree(treatmentJson).path("payload").toString(), + Treatment.class); + + String keyJson = keyCaptor.getValue(); + TreatmentReportingKey keyObject = objectMapper.readValue( + objectMapper.readTree(keyJson).path("payload").toString(), + TreatmentReportingKey.class); + assertEquals(treatment.getTreatmentUid(), keyObject.getTreatmentUid()); + + assertEquals(treatment, actualTreatment); + } + + @Test + void testProcessTreatmentException() { + String invalidPayload = "{\"payload\": {\"after\": {}}}"; + // Create a ConsumerRecord object + ConsumerRecord rec = getRecord(treatmentTopic, invalidPayload); + RuntimeException ex = assertThrows(RuntimeException.class, + () -> investigationService.processMessage(rec, consumer)); + assertEquals(NoSuchElementException.class, ex.getCause().getClass()); + } + + @Test + void testProcessTreatmentNoDataException() { + String payload = "{\"payload\": {\"after\": {\"treatment_uid\": \"\"}}}"; + // Create a ConsumerRecord object + ConsumerRecord rec = getRecord(treatmentTopic, payload); + assertThrows(NoDataException.class, () -> investigationService.processMessage(rec, consumer)); + } + private ConsumerRecord getRecord(String topic, String payload) { return new ConsumerRecord<>(topic, 0, 11L, null, payload); } diff --git a/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/utils/TestUtils.java b/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/utils/TestUtils.java index 862b092c..995a6d90 100644 --- a/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/utils/TestUtils.java +++ b/investigation-service/src/test/java/gov/cdc/etldatapipeline/investigation/utils/TestUtils.java @@ -369,4 +369,35 @@ public static VaccinationReporting constructVaccinationReporting(Long vaccinatio vaccinationReporting.setVaccineManufacturerNm("test"); return vaccinationReporting; } + + public static Treatment constructTreatment(Long treatmentUid) { + Treatment treatment = new Treatment(); + treatment.setTreatmentUid(String.valueOf(treatmentUid)); + treatment.setPublicHealthCaseUid("12345"); + treatment.setOrganizationUid("67890"); + treatment.setProviderUid("11111"); + treatment.setPatientTreatmentUid("22222"); + treatment.setTreatmentName("Test Treatment"); + treatment.setTreatmentOid("33333"); + treatment.setTreatmentComments("Test Comments"); + treatment.setTreatmentSharedInd("Y"); + treatment.setCd("TEST_CD"); + treatment.setTreatmentDate("2024-01-01T10:00:00"); + treatment.setTreatmentDrug("Drug123"); + treatment.setTreatmentDrugName("Test Drug"); + treatment.setTreatmentDosageStrength("100"); + treatment.setTreatmentDosageStrengthUnit("mg"); + treatment.setTreatmentFrequency("Daily"); + treatment.setTreatmentDuration("7"); + treatment.setTreatmentDurationUnit("days"); + treatment.setTreatmentRoute("Oral"); + treatment.setLocalId("LOC123"); + treatment.setRecordStatusCd("Active"); + treatment.setAddTime("2024-01-01T10:00:00"); + treatment.setAddUserId("44444"); + treatment.setLastChangeTime("2024-01-01T10:00:00"); + treatment.setLastChangeUserId("55555"); + treatment.setVersionControlNumber("1"); + return treatment; + } } diff --git a/liquibase-service/src/main/resources/db/odse/routines/026-sp_treatment_event-001.sql b/liquibase-service/src/main/resources/db/odse/routines/026-sp_treatment_event-001.sql index 59160171..3bb318f9 100644 --- a/liquibase-service/src/main/resources/db/odse/routines/026-sp_treatment_event-001.sql +++ b/liquibase-service/src/main/resources/db/odse/routines/026-sp_treatment_event-001.sql @@ -47,12 +47,12 @@ BEGIN par1.subject_entity_uid AS provider_uid, viewPatientKeys.treatment_uid AS patient_treatment_uid, act2.target_act_uid AS morbidity_uid, - rx1.LOCAL_ID, - rx1.ADD_TIME, - rx1.ADD_USER_ID, - rx1.LAST_CHG_TIME, - rx1.LAST_CHG_USER_ID, - rx1.VERSION_CTRL_NBR + rx1.local_id, + rx1.add_time, + rx1.add_user_id, + rx1.last_chg_time, + rx1.last_chg_user_id, + rx1.version_ctrl_nbr INTO #TREATMENT_UIDS FROM NBS_ODSE.dbo.treatment AS rx1 WITH (NOLOCK) INNER JOIN NBS_ODSE.dbo.Treatment_administered AS rx2 WITH (NOLOCK) @@ -117,31 +117,27 @@ BEGIN t.provider_uid, t.patient_treatment_uid, t.morbidity_uid, - rx1.cd_desc_txt AS Treatment_nm, - rx1.program_jurisdiction_oid AS Treatment_oid, - REPLACE(REPLACE(rx1.txt, CHAR(13) + CHAR(10), ' '), CHAR(10), ' ') AS Treatment_comments, - rx1.shared_ind AS Treatment_shared_ind, + rx1.cd_desc_txt AS treatment_name, + rx1.program_jurisdiction_oid AS treatment_oid, + REPLACE(REPLACE(rx1.txt, CHAR(13) + CHAR(10), ' '), CHAR(10), ' ') AS treatment_comments, + rx1.shared_ind AS treatment_shared_ind, rx1.cd, - rx2.effective_from_time AS Treatment_dt, - rx2.cd AS Treatment_drug, - rx2.cd_desc_txt AS Treatment_drug_nm, - rx2.dose_qty AS Treatment_dosage_strength, - rx2.dose_qty_unit_cd AS Treatment_dosage_strength_unit, - rx2.interval_cd AS Treatment_frequency, - rx2.effective_duration_amt AS Treatment_duration, - rx2.effective_duration_unit_cd AS Treatment_duration_unit, - rx2.route_cd AS Treatment_route, - t.LOCAL_ID, - CASE - WHEN rx1.record_status_cd = '' THEN 'ACTIVE' - WHEN rx1.record_status_cd = 'LOG_DEL' THEN 'INACTIVE' - ELSE rx1.record_status_cd - END as record_status_cd, - t.ADD_TIME, - t.ADD_USER_ID, - t.LAST_CHG_TIME, - t.LAST_CHG_USER_ID, - t.VERSION_CTRL_NBR + rx2.effective_from_time AS treatment_date, + rx2.cd AS treatment_drug, + rx2.cd_desc_txt AS treatment_drug_name, + rx2.dose_qty AS treatment_dosage_strength, + rx2.dose_qty_unit_cd AS treatment_dosage_strength_unit, + rx2.interval_cd AS treatment_frequency, + rx2.effective_duration_amt AS treatment_duration, + rx2.effective_duration_unit_cd AS treatment_duration_unit, + rx2.route_cd AS treatment_route, + t.local_id, + dbo.fn_get_record_status(rx1.record_status_cd) as record_status_cd, + t.add_time, + t.add_user_id, + t.last_chg_time, + t.last_chg_user_id, + t.version_ctrl_nbr INTO #TREATMENT_DETAILS FROM #TREATMENT_UIDS t INNER JOIN NBS_ODSE.dbo.treatment rx1 WITH (NOLOCK) @@ -176,27 +172,27 @@ BEGIN t.provider_uid, t.morbidity_uid, t.patient_treatment_uid, - t.Treatment_nm, - t.Treatment_oid, - t.Treatment_comments, - t.Treatment_shared_ind, + t.treatment_name, + t.treatment_oid, + t.treatment_comments, + t.treatment_shared_ind, t.cd, - t.Treatment_dt, - t.Treatment_drug, - t.Treatment_drug_nm, - t.Treatment_dosage_strength, - t.Treatment_dosage_strength_unit, - t.Treatment_frequency, - t.Treatment_duration, - t.Treatment_duration_unit, - t.Treatment_route, - t.LOCAL_ID, + t.treatment_date, + t.treatment_drug, + t.treatment_drug_name, + t.treatment_dosage_strength, + t.treatment_dosage_strength_unit, + t.treatment_frequency, + t.treatment_duration, + t.treatment_duration_unit, + t.treatment_route, + t.local_id, t.record_status_cd, - t.ADD_TIME, - t.ADD_USER_ID, - t.LAST_CHG_TIME, - t.LAST_CHG_USER_ID, - t.VERSION_CTRL_NBR + t.add_time, + t.add_user_id, + t.last_chg_time, + t.last_chg_user_id, + t.version_ctrl_nbr FROM #TREATMENT_DETAILS t;