Skip to content

Commit

Permalink
Added CHC/UPCC.
Browse files Browse the repository at this point in the history
Added ASCII conversion.
  • Loading branch information
weskubo-cgi authored and weskubo-cgi committed Feb 12, 2025
1 parent 31003bf commit 904a73a
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -33,7 +36,9 @@ public void process(Exchange exchange) throws Exception {
ObjectMapper mapper = new ObjectMapper();
List<Root> pcpsChcModels = mapper.readValue(payload, new TypeReference<List<Root>>() {
});
List<PCPSChcSubmission> parsedChcPCPS = parsePCPSRequest(pcpsChcModels);

List<HaMapping> haMappings = (List<HaMapping>)exchange.getProperties().get(Constants.PROPERTY_HA_MAPPING);
List<PCPSChcSubmission> parsedChcPCPS = parsePCPSRequest(pcpsChcModels, haMappings);

validateRecordCount(pcpsChcModels, parsedChcPCPS);

Expand Down Expand Up @@ -66,7 +71,7 @@ && getPeriodicField(o, "deliveredVirtually", index) == null
&& getPeriodicField(o, "outsideBusinessHours", index) == null;
}

private List<PCPSChcSubmission> parsePCPSRequest(List<Root> pcpsModels)
private List<PCPSChcSubmission> parsePCPSRequest(List<Root> pcpsModels, List<HaMapping> haMappings)
throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException,
SecurityException {
List<PCPSChcSubmission> parsedChcPCPS = new ArrayList<>();
Expand All @@ -83,7 +88,8 @@ private List<PCPSChcSubmission> parsePCPSRequest(List<Root> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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<Root> haMapping = new ArrayList<Root>();
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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;
import java.util.List;
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;
Expand All @@ -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;
Expand All @@ -33,7 +36,9 @@ public void process(Exchange exchange) throws Exception {

ObjectMapper mapper = new ObjectMapper();
List<Root> pcpsModels = mapper.readValue(payload, new TypeReference<List<Root>>() {});
List<PCPSUpccSubmission> parsedUpccPCPS = parsePCPSRequest(pcpsModels);

List<HaMapping> haMappings = (List<HaMapping>)exchange.getProperties().get(Constants.PROPERTY_HA_MAPPING);
List<PCPSUpccSubmission> parsedUpccPCPS = parsePCPSRequest(pcpsModels, haMappings);

validateRecordCount(pcpsModels, parsedUpccPCPS);

Expand Down Expand Up @@ -66,7 +71,7 @@ && getPeriodicField(o, "deliveredVirtually", index) == null
&& getPeriodicField(o, "outsideBusinessHours", index) == null;
}

private List<PCPSUpccSubmission> parsePCPSRequest(List<Root> pcpsModels)
private List<PCPSUpccSubmission> parsePCPSRequest(List<Root> pcpsModels, List<HaMapping> haMappings)
throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException,
SecurityException {
List<PCPSUpccSubmission> parsedUpccPCPS = new ArrayList<>();
Expand All @@ -83,7 +88,8 @@ private List<PCPSUpccSubmission> parsePCPSRequest(List<Root> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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();

}
}

0 comments on commit 904a73a

Please sign in to comment.