From 904a73a2943845696f6358ab155ced98ce706304 Mon Sep 17 00:00:00 2001 From: weskubo-cgi Date: Tue, 11 Feb 2025 16:19:35 -0800 Subject: [PATCH] Added CHC/UPCC. Added ASCII conversion. --- .../processor/PcdChcPCPSApiProcessor.java | 10 ++++++++++ .../PcdChcPCPSApiResponseProcessor.java | 12 +++++++++--- .../route/ChcPcpsFormRoute.java | 18 ++++++++++++++++++ .../HaMappingAggregationStrategy.java | 3 +++ .../processor/PcdUpccPCPSApiProcessor.java | 10 ++++++++++ .../PcdUpccPCPSApiResponseProcessor.java | 12 +++++++++--- .../route/UpccPcpsFormRoute.java | 18 ++++++++++++++++++ 7 files changed, 77 insertions(+), 6 deletions(-) diff --git a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/chc/pcPatientServices/processor/PcdChcPCPSApiProcessor.java b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/chc/pcPatientServices/processor/PcdChcPCPSApiProcessor.java index 4dba9156..eb27c074 100644 --- a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/chc/pcPatientServices/processor/PcdChcPCPSApiProcessor.java +++ b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/chc/pcPatientServices/processor/PcdChcPCPSApiProcessor.java @@ -1,10 +1,20 @@ package ca.bc.gov.chefs.etl.forms.pcd.chc.pcPatientServices.processor; +import static ca.bc.gov.chefs.etl.constant.Constants.PROPERTY_CHEFS_PAYLOAD; + +import org.apache.camel.Exchange; + import ca.bc.gov.chefs.etl.constant.PCDConstants; +import ca.bc.gov.chefs.etl.core.model.ChefsRequestPayload; import ca.bc.gov.chefs.etl.core.processor.BaseApiProcessor; public class PcdChcPCPSApiProcessor extends BaseApiProcessor { public PcdChcPCPSApiProcessor() { this.formPropertyName = PCDConstants.PCD_CHC_PCPS_PROPERTY; } + + @Override + protected ChefsRequestPayload loadChefsPayload(Exchange exchange) { + return exchange.getProperty(PROPERTY_CHEFS_PAYLOAD, ChefsRequestPayload.class); + } } diff --git a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/chc/pcPatientServices/processor/PcdChcPCPSApiResponseProcessor.java b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/chc/pcPatientServices/processor/PcdChcPCPSApiResponseProcessor.java index 3c0c273e..eb5237f5 100644 --- a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/chc/pcPatientServices/processor/PcdChcPCPSApiResponseProcessor.java +++ b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/chc/pcPatientServices/processor/PcdChcPCPSApiResponseProcessor.java @@ -5,6 +5,7 @@ import java.util.Map; import org.apache.camel.Exchange; +import org.apache.commons.lang3.StringUtils; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -17,10 +18,12 @@ import ca.bc.gov.chefs.etl.forms.pcd.chc.pcPatientServices.json.Root; import ca.bc.gov.chefs.etl.forms.pcd.chc.pcPatientServices.model.PCPSChcSubmission; import ca.bc.gov.chefs.etl.forms.pcd.chc.pcPatientServices.model.PCPSChcSubmissionData; +import ca.bc.gov.chefs.etl.forms.pcd.haMapping.json.HaMapping; import ca.bc.gov.chefs.etl.util.CSVUtil; import ca.bc.gov.chefs.etl.util.FileUtil; import ca.bc.gov.chefs.etl.util.JsonUtil; +import static ca.bc.gov.chefs.etl.constant.PCDConstants.HA_MAPPING_TYPE_CHC; import static ca.bc.gov.chefs.etl.util.JsonUtil.getPeriodicField; public class PcdChcPCPSApiResponseProcessor extends BaseApiResponseProcessor { @@ -33,7 +36,9 @@ public void process(Exchange exchange) throws Exception { ObjectMapper mapper = new ObjectMapper(); List pcpsChcModels = mapper.readValue(payload, new TypeReference>() { }); - List parsedChcPCPS = parsePCPSRequest(pcpsChcModels); + + List haMappings = (List)exchange.getProperties().get(Constants.PROPERTY_HA_MAPPING); + List parsedChcPCPS = parsePCPSRequest(pcpsChcModels, haMappings); validateRecordCount(pcpsChcModels, parsedChcPCPS); @@ -66,7 +71,7 @@ && getPeriodicField(o, "deliveredVirtually", index) == null && getPeriodicField(o, "outsideBusinessHours", index) == null; } - private List parsePCPSRequest(List pcpsModels) + private List parsePCPSRequest(List pcpsModels, List haMappings) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { List parsedChcPCPS = new ArrayList<>(); @@ -83,7 +88,8 @@ private List parsePCPSRequest(List pcpsModels) pcpsSubmission.setSubmissionVersion("" + root.getForm().getVersion()); pcpsSubmission.setSubmissionFormName(root.getForm().getFormName()); pcpsSubmission.setChcName(root.getChcName()); - pcpsSubmission.setChcCode(root.getChcId()); + String chcCode = StringUtils.defaultIfBlank(root.getChcId(), JsonUtil.fixHierarchyCode(haMappings, HA_MAPPING_TYPE_CHC, root.getChcName())); + pcpsSubmission.setChcCode(chcCode); pcpsSubmission.setPcnCommunityName(root.getPcnCommunity()); pcpsSubmission.setHealthAuthority(root.getHealthAuthority()); pcpsSubmission.setFiscalYear(root.getFiscalYear()); diff --git a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/chc/pcPatientServices/route/ChcPcpsFormRoute.java b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/chc/pcPatientServices/route/ChcPcpsFormRoute.java index 62fc128c..5dbd1325 100644 --- a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/chc/pcPatientServices/route/ChcPcpsFormRoute.java +++ b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/chc/pcPatientServices/route/ChcPcpsFormRoute.java @@ -4,12 +4,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ca.bc.gov.chefs.etl.core.processor.ChefsPayloadProcessor; import ca.bc.gov.chefs.etl.core.routes.BaseRoute; import ca.bc.gov.chefs.etl.forms.pcd.chc.pcPatientServices.processor.PcdChcPCPSApiProcessor; import ca.bc.gov.chefs.etl.forms.pcd.chc.pcPatientServices.processor.PcdChcPCPSApiResponseProcessor; +import ca.bc.gov.chefs.etl.forms.pcd.haMapping.aggregation.HaMappingAggregationStrategy; +import ca.bc.gov.chefs.etl.forms.pcd.haMapping.processor.PcdHAMappingApiProcessor; public class ChcPcpsFormRoute extends BaseRoute{ private static final Logger logger = LoggerFactory.getLogger(ChcPcpsFormRoute.class); + @Override public void configure() throws Exception { super.configure(); @@ -21,6 +25,7 @@ public void configure() throws Exception { // trigger from("jetty:http://{{hostname}}:{{port}}/pcd/chc-pcps").routeId("pcd-chc-pcps-form") .log("CHEFS-ETL received a request for CHC Primary Care Patient Services Form extraction") + .process(new ChefsPayloadProcessor()) .to("direct:pcd-chc-pcps").end(); // process @@ -29,10 +34,23 @@ public void configure() throws Exception { .toD("${header.RequestUri}") .log("This is the status code from the response: ${header.CamelHttpResponseCode}") .log("Trying to convert the received body OK").convertBodyTo(String.class) + + // Enrich with HA Mapping data + .enrich("direct:ha-hierarchy-mapping-chc-pcps", new HaMappingAggregationStrategy()) .process(new PcdChcPCPSApiResponseProcessor()) + // Clean up the headers returned to the caller .removeHeaders("*") .setHeader(Exchange.CONTENT_TYPE, constant("text/json;charset=utf-8")) .end(); + + from("direct:ha-hierarchy-mapping-chc-pcps") + // to the http uri + .process(new PcdHAMappingApiProcessor()) + .toD("${header.RequestUri}") + .log("This is the status code from the response: ${header.CamelHttpResponseCode}") + .log("Trying to convert the received body OK").convertBodyTo(String.class) + .end(); + } } \ No newline at end of file diff --git a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/haMapping/aggregation/HaMappingAggregationStrategy.java b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/haMapping/aggregation/HaMappingAggregationStrategy.java index 6fceb4c1..a2c66565 100644 --- a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/haMapping/aggregation/HaMappingAggregationStrategy.java +++ b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/haMapping/aggregation/HaMappingAggregationStrategy.java @@ -16,6 +16,7 @@ import ca.bc.gov.chefs.etl.forms.pcd.haMapping.json.HaMapping; import ca.bc.gov.chefs.etl.forms.pcd.haMapping.json.Root; +import ca.bc.gov.chefs.etl.util.JsonUtil; public class HaMappingAggregationStrategy implements AggregationStrategy { @@ -26,6 +27,8 @@ public Exchange aggregate(Exchange original, Exchange resource) { ObjectMapper mapper = new ObjectMapper(); String payload = resource.getIn().getBody(String.class); + // Payload needs to be converted to ASCII to match converted submissions + payload = JsonUtil.fixUnicodeCharacters(payload); List haMapping = new ArrayList(); try { diff --git a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/upcc/pcPatientServices/processor/PcdUpccPCPSApiProcessor.java b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/upcc/pcPatientServices/processor/PcdUpccPCPSApiProcessor.java index 4e2bff6d..7e8395de 100644 --- a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/upcc/pcPatientServices/processor/PcdUpccPCPSApiProcessor.java +++ b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/upcc/pcPatientServices/processor/PcdUpccPCPSApiProcessor.java @@ -1,10 +1,20 @@ package ca.bc.gov.chefs.etl.forms.pcd.upcc.pcPatientServices.processor; +import static ca.bc.gov.chefs.etl.constant.Constants.PROPERTY_CHEFS_PAYLOAD; + +import org.apache.camel.Exchange; + import ca.bc.gov.chefs.etl.constant.PCDConstants; +import ca.bc.gov.chefs.etl.core.model.ChefsRequestPayload; import ca.bc.gov.chefs.etl.core.processor.BaseApiProcessor; public class PcdUpccPCPSApiProcessor extends BaseApiProcessor { public PcdUpccPCPSApiProcessor() { this.formPropertyName = PCDConstants.PCD_UPCC_PCPS_PROPERTY; } + + @Override + protected ChefsRequestPayload loadChefsPayload(Exchange exchange) { + return exchange.getProperty(PROPERTY_CHEFS_PAYLOAD, ChefsRequestPayload.class); + } } diff --git a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/upcc/pcPatientServices/processor/PcdUpccPCPSApiResponseProcessor.java b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/upcc/pcPatientServices/processor/PcdUpccPCPSApiResponseProcessor.java index 2a510c2f..3f3dfa28 100644 --- a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/upcc/pcPatientServices/processor/PcdUpccPCPSApiResponseProcessor.java +++ b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/upcc/pcPatientServices/processor/PcdUpccPCPSApiResponseProcessor.java @@ -1,5 +1,6 @@ package ca.bc.gov.chefs.etl.forms.pcd.upcc.pcPatientServices.processor; +import static ca.bc.gov.chefs.etl.constant.PCDConstants.HA_MAPPING_TYPE_UPCC; import static ca.bc.gov.chefs.etl.util.JsonUtil.getPeriodicField; import java.util.ArrayList; @@ -7,6 +8,7 @@ import java.util.Map; import org.apache.camel.Exchange; +import org.apache.commons.lang3.StringUtils; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; @@ -16,6 +18,7 @@ import ca.bc.gov.chefs.etl.core.model.IModel; import ca.bc.gov.chefs.etl.core.model.SuccessResponse; import ca.bc.gov.chefs.etl.core.processor.BaseApiResponseProcessor; +import ca.bc.gov.chefs.etl.forms.pcd.haMapping.json.HaMapping; import ca.bc.gov.chefs.etl.forms.pcd.upcc.pcPatientServices.json.Root; import ca.bc.gov.chefs.etl.forms.pcd.upcc.pcPatientServices.model.PCPSUpccSubmission; import ca.bc.gov.chefs.etl.forms.pcd.upcc.pcPatientServices.model.PCPSUpccSubmissionData; @@ -33,7 +36,9 @@ public void process(Exchange exchange) throws Exception { ObjectMapper mapper = new ObjectMapper(); List pcpsModels = mapper.readValue(payload, new TypeReference>() {}); - List parsedUpccPCPS = parsePCPSRequest(pcpsModels); + + List haMappings = (List)exchange.getProperties().get(Constants.PROPERTY_HA_MAPPING); + List parsedUpccPCPS = parsePCPSRequest(pcpsModels, haMappings); validateRecordCount(pcpsModels, parsedUpccPCPS); @@ -66,7 +71,7 @@ && getPeriodicField(o, "deliveredVirtually", index) == null && getPeriodicField(o, "outsideBusinessHours", index) == null; } - private List parsePCPSRequest(List pcpsModels) + private List parsePCPSRequest(List pcpsModels, List haMappings) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { List parsedUpccPCPS = new ArrayList<>(); @@ -83,7 +88,8 @@ private List parsePCPSRequest(List pcpsModels) pcpsSubmission.setSubmissionVersion("" + root.getForm().getVersion()); pcpsSubmission.setSubmissionFormName(root.getForm().getFormName()); pcpsSubmission.setUpccName(root.getUpccName()); - pcpsSubmission.setUpccCode(root.getUpccId()); + String upccCode = StringUtils.defaultIfBlank(root.getUpccId(), JsonUtil.fixHierarchyCode(haMappings, HA_MAPPING_TYPE_UPCC, root.getUpccName())); + pcpsSubmission.setUpccCode(upccCode); pcpsSubmission.setPcnCommunityName(root.getPcnCommunity()); pcpsSubmission.setHealthAuthority(root.getHealthAuthority()); pcpsSubmission.setUpccTypeOfCare(root.getUpccTypeOfCare()); diff --git a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/upcc/pcPatientServices/route/UpccPcpsFormRoute.java b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/upcc/pcPatientServices/route/UpccPcpsFormRoute.java index 145f57e7..5b13ab1a 100644 --- a/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/upcc/pcPatientServices/route/UpccPcpsFormRoute.java +++ b/src/main/java/ca/bc/gov/chefs/etl/forms/pcd/upcc/pcPatientServices/route/UpccPcpsFormRoute.java @@ -4,7 +4,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ca.bc.gov.chefs.etl.core.processor.ChefsPayloadProcessor; import ca.bc.gov.chefs.etl.core.routes.BaseRoute; +import ca.bc.gov.chefs.etl.forms.pcd.haMapping.aggregation.HaMappingAggregationStrategy; +import ca.bc.gov.chefs.etl.forms.pcd.haMapping.processor.PcdHAMappingApiProcessor; import ca.bc.gov.chefs.etl.forms.pcd.upcc.pcPatientServices.processor.PcdUpccPCPSApiProcessor; import ca.bc.gov.chefs.etl.forms.pcd.upcc.pcPatientServices.processor.PcdUpccPCPSApiResponseProcessor; @@ -21,6 +24,7 @@ public void configure() throws Exception { // trigger from("jetty:http://{{hostname}}:{{port}}/pcd/upcc-pcps").routeId("pcd-upcc-pcps-form") .log("CHEFS-ETL received a request for UPCC Primary Care Patient Services Form extraction") + .process(new ChefsPayloadProcessor()) .to("direct:pcd-upcc-pcps-form").end(); // process @@ -29,9 +33,23 @@ public void configure() throws Exception { .toD("${header.RequestUri}") .log("This is the status code from the response: ${header.CamelHttpResponseCode}") .log("Trying to convert the received body OK").convertBodyTo(String.class) + + // Enrich with HA Mapping data + .enrich("direct:ha-hierarchy-mapping-upcc-pcps", new HaMappingAggregationStrategy()) .process(new PcdUpccPCPSApiResponseProcessor()) + + // Clean up the headers returned to the caller .removeHeaders("*") .setHeader(Exchange.CONTENT_TYPE, constant("text/json;charset=utf-8")) .end(); + + from("direct:ha-hierarchy-mapping-upcc-pcps") + // to the http uri + .process(new PcdHAMappingApiProcessor()) + .toD("${header.RequestUri}") + .log("This is the status code from the response: ${header.CamelHttpResponseCode}") + .log("Trying to convert the received body OK").convertBodyTo(String.class) + .end(); + } } \ No newline at end of file