diff --git a/liquibase-service/src/main/resources/db/rdb/tables/017-create_nrt_observation-003.sql b/liquibase-service/src/main/resources/db/rdb/tables/017-create_nrt_observation-003.sql index cb0b491..1ca324b 100644 --- a/liquibase-service/src/main/resources/db/rdb/tables/017-create_nrt_observation-003.sql +++ b/liquibase-service/src/main/resources/db/rdb/tables/017-create_nrt_observation-003.sql @@ -45,7 +45,7 @@ IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'nrt_observation' and xtype = ' IF NOT EXISTS(SELECT 1 FROM sys.columns WHERE name = N'cd_system_desc_txt' AND object_id = Object_ID(N'nrt_observation')) BEGIN ALTER TABLE nrt_observation - ADD cd_system_desc_txt varchar(1000); + ADD cd_system_desc_txt varchar(100); END; IF NOT EXISTS(SELECT 1 FROM sys.columns WHERE name = N'ctrl_cd_user_defined_1' AND object_id = Object_ID(N'nrt_observation')) @@ -69,7 +69,7 @@ IF EXISTS (SELECT 1 FROM sysobjects WHERE name = 'nrt_observation' and xtype = ' IF NOT EXISTS(SELECT 1 FROM sys.columns WHERE name = N'alt_cd_system_cd' AND object_id = Object_ID(N'nrt_observation')) BEGIN ALTER TABLE nrt_observation - ADD alt_cd_system_cd varchar(1000); + ADD alt_cd_system_cd varchar(300); END; IF NOT EXISTS(SELECT 1 FROM sys.columns WHERE name = N'alt_cd_system_desc_txt' AND object_id = Object_ID(N'nrt_observation')) diff --git a/observation-service/src/main/java/gov/cdc/etldatapipeline/observation/util/ProcessObservationDataUtil.java b/observation-service/src/main/java/gov/cdc/etldatapipeline/observation/util/ProcessObservationDataUtil.java index 6e91475..995e026 100644 --- a/observation-service/src/main/java/gov/cdc/etldatapipeline/observation/util/ProcessObservationDataUtil.java +++ b/observation-service/src/main/java/gov/cdc/etldatapipeline/observation/util/ProcessObservationDataUtil.java @@ -42,32 +42,27 @@ private void transformPersonParticipations(String personParticipations, String o try { JsonNode personParticipationsJsonArray = parseJsonArray(personParticipations, objectMapper); - if(personParticipationsJsonArray != null) { - for(JsonNode jsonNode : personParticipationsJsonArray) { - String typeCd = getNodeValue(jsonNode.get(TYPE_CD)); - String subjectClassCd = getNodeValue(jsonNode.get(SUBJECT_CLASS_CD)); - - if(obsDomainCdSt1.equals(DOM_ORDER)) { - if(typeCd != null && subjectClassCd != null) { - if(typeCd.equals("ORD") && subjectClassCd.equals("PSN")) { - observationTransformed.setOrderingPersonId(jsonNode.get(ENTITY_ID).asLong()); - } - if (typeCd.equals("PATSBJ") && subjectClassCd.equals("PSN")) { - observationTransformed.setPatientId(jsonNode.get(ENTITY_ID).asLong()); - } + for (JsonNode jsonNode : personParticipationsJsonArray) { + String typeCd = getNodeValue(jsonNode.get(TYPE_CD)); + String subjectClassCd = getNodeValue(jsonNode.get(SUBJECT_CLASS_CD)); + + if(obsDomainCdSt1.equals(DOM_ORDER)) { + if(typeCd != null && subjectClassCd != null) { + if(typeCd.equals("ORD") && subjectClassCd.equals("PSN")) { + observationTransformed.setOrderingPersonId(jsonNode.get(ENTITY_ID).asLong()); } - else { - logger.error("Type_cd or subject_class_cd is null for the personParticipations: {}", personParticipations); + if (typeCd.equals("PATSBJ") && subjectClassCd.equals("PSN")) { + observationTransformed.setPatientId(jsonNode.get(ENTITY_ID).asLong()); } + } else { + logger.error("Type_cd or subject_class_cd is null for the personParticipations: {}", personParticipations); } - else { - logger.error("obsDomainCdSt1: {} is not valid for the personParticipations.", obsDomainCdSt1); - } + } else { + logger.error("obsDomainCdSt1: {} is not valid for the personParticipations.", obsDomainCdSt1); } } - else { - logger.info("PersonParticipations array is null."); - } + } catch (IllegalArgumentException ex) { + logger.info("PersonParticipations array is null."); } catch (Exception e) { logger.error("Error processing Person Participation JSON array from observation data: {}", e.getMessage()); } @@ -77,36 +72,33 @@ private void transformOrganizationParticipations(String organizationParticipatio try { JsonNode organizationParticipationsJsonArray = parseJsonArray(organizationParticipations, objectMapper); - if(organizationParticipationsJsonArray != null) { - for(JsonNode jsonNode : organizationParticipationsJsonArray) { - String typeCd = getNodeValue(jsonNode.get(TYPE_CD)); - String subjectClassCd = getNodeValue(jsonNode.get(SUBJECT_CLASS_CD)); + for(JsonNode jsonNode : organizationParticipationsJsonArray) { + String typeCd = getNodeValue(jsonNode.get(TYPE_CD)); + String subjectClassCd = getNodeValue(jsonNode.get(SUBJECT_CLASS_CD)); - if(typeCd != null && subjectClassCd != null) { - if(obsDomainCdSt1.equals(DOM_RESULT)) { - if(typeCd.equals("PRF") && subjectClassCd.equals("ORG")) { - observationTransformed.setPerformingOrganizationId(jsonNode.get(ENTITY_ID).asLong()); - } - } - else if(obsDomainCdSt1.equals(DOM_ORDER)) { - if(typeCd.equals("AUT") && subjectClassCd.equals("ORG")) { - observationTransformed.setAuthorOrganizationId(jsonNode.get(ENTITY_ID).asLong()); - } - if(typeCd.equals("ORD") && subjectClassCd.equals("ORG")) { - observationTransformed.setOrderingOrganizationId(jsonNode.get(ENTITY_ID).asLong()); - } - } - else { - logger.error("obsDomainCdSt1: {} is not valid for the organizationParticipations", obsDomainCdSt1); + if(typeCd != null && subjectClassCd != null) { + if(obsDomainCdSt1.equals(DOM_RESULT)) { + if(typeCd.equals("PRF") && subjectClassCd.equals("ORG")) { + observationTransformed.setPerformingOrganizationId(jsonNode.get(ENTITY_ID).asLong()); } - } else { - logger.error("Type_cd or subject_class_cd is null for the organizationParticipations: {}", organizationParticipations); } + else if(obsDomainCdSt1.equals(DOM_ORDER)) { + if(typeCd.equals("AUT") && subjectClassCd.equals("ORG")) { + observationTransformed.setAuthorOrganizationId(jsonNode.get(ENTITY_ID).asLong()); + } + if(typeCd.equals("ORD") && subjectClassCd.equals("ORG")) { + observationTransformed.setOrderingOrganizationId(jsonNode.get(ENTITY_ID).asLong()); + } + } + else { + logger.error("obsDomainCdSt1: {} is not valid for the organizationParticipations", obsDomainCdSt1); + } + } else { + logger.error("Type_cd or subject_class_cd is null for the organizationParticipations: {}", organizationParticipations); } } - else { - logger.info("OrganizationParticipations array is null."); - } + } catch (IllegalArgumentException ex) { + logger.info("OrganizationParticipations array is null."); } catch (Exception e) { logger.error("Error processing Organization Participation JSON array from observation data: {}", e.getMessage()); } @@ -116,29 +108,25 @@ private void transformMaterialParticipations(String materialParticipations, Stri try { JsonNode materialParticipationsJsonArray = parseJsonArray(materialParticipations, objectMapper); - if(materialParticipationsJsonArray != null) { - for(JsonNode jsonNode : materialParticipationsJsonArray) { - String typeCd = getNodeValue(jsonNode.get(TYPE_CD)); - String subjectClassCd = getNodeValue(jsonNode.get(SUBJECT_CLASS_CD)); + for(JsonNode jsonNode : materialParticipationsJsonArray) { + String typeCd = getNodeValue(jsonNode.get(TYPE_CD)); + String subjectClassCd = getNodeValue(jsonNode.get(SUBJECT_CLASS_CD)); - if(obsDomainCdSt1.equals(DOM_ORDER)) { - if(typeCd != null && subjectClassCd != null) { - if(typeCd.equals("SPC") && subjectClassCd.equals("MAT")) { - observationTransformed.setMaterialId(jsonNode.get(ENTITY_ID).asLong()); - } - } - else { - logger.error("Type_cd or subject_class_cd is null for the materialParticipations: {}", materialParticipations); + if(obsDomainCdSt1.equals(DOM_ORDER)) { + if(typeCd != null && subjectClassCd != null) { + if(typeCd.equals("SPC") && subjectClassCd.equals("MAT")) { + observationTransformed.setMaterialId(jsonNode.get(ENTITY_ID).asLong()); } - } - else { - logger.error("obsDomainCdSt1: {} is not valid for the materialParticipations", obsDomainCdSt1); + } else { + logger.error("Type_cd or subject_class_cd is null for the materialParticipations: {}", materialParticipations); } } + else { + logger.error("obsDomainCdSt1: {} is not valid for the materialParticipations", obsDomainCdSt1); + } } - else { - logger.info("MaterialParticipations array is null."); - } + } catch (IllegalArgumentException ex) { + logger.info("MaterialParticipations array is null."); } catch (Exception e) { logger.error("Error processing Material Participation JSON array from observation data: {}", e.getMessage()); } @@ -148,34 +136,31 @@ private void transformFollowupObservations(String followupObservations, String o try { JsonNode followupObservationsJsonArray = parseJsonArray(followupObservations, objectMapper); - if(followupObservationsJsonArray != null) { - List results = new ArrayList<>(); - List followUps = new ArrayList<>(); - for (JsonNode jsonNode : followupObservationsJsonArray) { - String domainCdSt1 = getNodeValue(jsonNode.get("domain_cd_st_1")); + List results = new ArrayList<>(); + List followUps = new ArrayList<>(); + for (JsonNode jsonNode : followupObservationsJsonArray) { + String domainCdSt1 = getNodeValue(jsonNode.get("domain_cd_st_1")); - if (obsDomainCdSt1.equals(DOM_ORDER)) { - if (DOM_RESULT.equals(domainCdSt1)) { - Optional.ofNullable(jsonNode.get("result_observation_uid")).ifPresent(r -> results.add(r.asText())); - } - else { - Optional.ofNullable(jsonNode.get("result_observation_uid")).ifPresent(r -> followUps.add(r.asText())); - } - } else { - logger.error("obsDomainCdSt1: {} is not valid for the followupObservations", obsDomainCdSt1); + if (obsDomainCdSt1.equals(DOM_ORDER)) { + if (DOM_RESULT.equals(domainCdSt1)) { + Optional.ofNullable(jsonNode.get("result_observation_uid")).ifPresent(r -> results.add(r.asText())); + } + else { + Optional.ofNullable(jsonNode.get("result_observation_uid")).ifPresent(r -> followUps.add(r.asText())); } + } else { + logger.error("obsDomainCdSt1: {} is not valid for the followupObservations", obsDomainCdSt1); } + } - if(!results.isEmpty()) { - observationTransformed.setResultObservationUid(String.join(",", results)); - } - if(!followUps.isEmpty()) { - observationTransformed.setFollowUpObservationUid(String.join(",", followUps)); - } + if(!results.isEmpty()) { + observationTransformed.setResultObservationUid(String.join(",", results)); } - else { - logger.info("FollowupObservations array is null."); + if(!followUps.isEmpty()) { + observationTransformed.setFollowUpObservationUid(String.join(",", followUps)); } + } catch (IllegalArgumentException ex) { + logger.info("FollowupObservations array is null."); } catch (Exception e) { logger.error("Error processing Followup Observations JSON array from observation data: {}", e.getMessage()); } @@ -185,41 +170,39 @@ private void transformParentObservations(String parentObservations, String obsDo try { JsonNode parentObservationsJsonArray = parseJsonArray(parentObservations, objectMapper); - if(parentObservationsJsonArray != null) { - for (JsonNode jsonNode : parentObservationsJsonArray) { - String typeCd = getNodeValue(jsonNode.get("parent_type_cd")); - Optional.ofNullable(jsonNode.get("report_observation_uid")).ifPresent(id -> observationTransformed.setReportObservationUid(id.asLong())); + for (JsonNode jsonNode : parentObservationsJsonArray) { + String typeCd = getNodeValue(jsonNode.get("parent_type_cd")); + Optional.ofNullable(jsonNode.get("report_observation_uid")).ifPresent(id -> observationTransformed.setReportObservationUid(id.asLong())); - if (obsDomainCdSt1.equals(DOM_ORDER)) { - Optional parentUid = Optional.ofNullable(jsonNode.get("parent_uid")); + if (obsDomainCdSt1.equals(DOM_ORDER)) { + Optional parentUid = Optional.ofNullable(jsonNode.get("parent_uid")); - if(typeCd != null) { - if (typeCd.equals("SPRT")) { - parentUid.ifPresent(id -> observationTransformed.setReportSprtUid(id.asLong())); - } else if (typeCd.equals("REFR")) { - parentUid.ifPresent(id -> observationTransformed.setReportRefrUid(id.asLong())); - } - } else { - logger.error("Parent_type_cd is null for the parentObservations: {}", parentObservations); + if(typeCd != null) { + if (typeCd.equals("SPRT")) { + parentUid.ifPresent(id -> observationTransformed.setReportSprtUid(id.asLong())); + } else if (typeCd.equals("REFR")) { + parentUid.ifPresent(id -> observationTransformed.setReportRefrUid(id.asLong())); } } else { - logger.error("obsDomainCdSt1: {} is not valid for the parentObservations", obsDomainCdSt1); + logger.error("Parent_type_cd is null for the parentObservations: {}", parentObservations); } + } else { + logger.error("obsDomainCdSt1: {} is not valid for the parentObservations", obsDomainCdSt1); } - } else { - logger.info("ParentObservations array is null."); } + } catch (IllegalArgumentException ex) { + logger.info("ParentObservations array is null."); } catch (Exception e) { logger.error("Error processing Parent Observations JSON array from observation data: {}", e.getMessage()); } } - private JsonNode parseJsonArray(String jsonString, ObjectMapper objectMapper) throws JsonProcessingException { + private JsonNode parseJsonArray(String jsonString, ObjectMapper objectMapper) throws JsonProcessingException, IllegalArgumentException { JsonNode jsonArray = jsonString != null ? objectMapper.readTree(jsonString) : null; - if (jsonArray != null) { - return jsonArray.isArray() ? jsonArray : null; + if (jsonArray != null && jsonArray.isArray()) { + return jsonArray; } else { - return null; + throw new IllegalArgumentException(); } }