Skip to content

Commit

Permalink
Update encoder to handle mvp and subgroup encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
saquino0827 committed Oct 4, 2023
1 parent 88e31dc commit 2ee6e30
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gov.cms.qpp.conversion.encode;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -26,6 +27,7 @@ public class ClinicalDocumentEncoder extends QppOutputEncoder {

private static final Logger DEV_LOG = LoggerFactory.getLogger(ClinicalDocumentEncoder.class);
private static final String MEASUREMENT_SETS = "measurementSets";
private static final String SUBMISSION = "submission";

public ClinicalDocumentEncoder(Context context) {
super(context);
Expand Down Expand Up @@ -55,17 +57,17 @@ public void internalEncode(JsonWrapper wrapper, Node thisNode) {
*/
private void encodeToplevel(JsonWrapper wrapper, Node thisNode) {
String entityType = thisNode.getValue(ClinicalDocumentDecoder.ENTITY_TYPE);

encodePerformanceYear(wrapper, thisNode);
wrapper.put(ClinicalDocumentDecoder.ENTITY_TYPE, entityType);
if (!ClinicalDocumentDecoder.ENTITY_APM.equals(entityType)) {
if (!ClinicalDocumentDecoder.ENTITY_APM.equals(entityType)
&& !ClinicalDocumentDecoder.ENTITY_SUBGROUP.equalsIgnoreCase(entityType)) {
wrapper.put(ClinicalDocumentDecoder.NATIONAL_PROVIDER_IDENTIFIER,
thisNode.getValue(ClinicalDocumentDecoder.NATIONAL_PROVIDER_IDENTIFIER));
wrapper.put(ClinicalDocumentDecoder.TAX_PAYER_IDENTIFICATION_NUMBER,
thisNode.getValue(ClinicalDocumentDecoder.TAX_PAYER_IDENTIFICATION_NUMBER));
}

if(Program.isPcf(thisNode)) {
if (Program.isPcf(thisNode)) {
wrapper.put(ClinicalDocumentDecoder.ENTITY_ID, thisNode.getValue(ClinicalDocumentDecoder.PCF_ENTITY_ID));
}

Expand All @@ -77,6 +79,10 @@ private void encodeToplevel(JsonWrapper wrapper, Node thisNode) {
ClinicalDocumentDecoder.ENTITY_APM.equalsIgnoreCase(entityType))) {
wrapper.put(ClinicalDocumentDecoder.ENTITY_ID, thisNode.getValue(ClinicalDocumentDecoder.ENTITY_ID));
}

if (ClinicalDocumentDecoder.ENTITY_SUBGROUP.equalsIgnoreCase(entityType)) {
wrapper.put(ClinicalDocumentDecoder.ENTITY_ID, thisNode.getValue(ClinicalDocumentDecoder.SUBGROUP_ID));
}
}

/**
Expand Down Expand Up @@ -111,7 +117,6 @@ private JsonWrapper encodeMeasurementSets(Map<TemplateId, Node> childMapByTempla
if (child == null) {
continue;
}

try {
TemplateId childType = child.getType();

Expand All @@ -120,7 +125,12 @@ private JsonWrapper encodeMeasurementSets(Map<TemplateId, Node> childMapByTempla

sectionEncoder.encode(childWrapper, child);
childWrapper.put("source", "qrda3");
String mvpId = currentNode.getValue(ClinicalDocumentDecoder.MVP_ID);
if (TemplateId.MEASURE_SECTION_V5.getRoot().equalsIgnoreCase(childType.getRoot())
&& !StringUtils.isEmpty(mvpId)) {
childWrapper.put(ClinicalDocumentDecoder.PROGRAM_NAME, mvpId);
}
else if (TemplateId.MEASURE_SECTION_V5.getRoot().equalsIgnoreCase(childType.getRoot())
&& ClinicalDocumentDecoder.MIPS_APM.equalsIgnoreCase(
currentNode.getValue(ClinicalDocumentDecoder.RAW_PROGRAM_NAME))) {
childWrapper.put(ClinicalDocumentDecoder.PROGRAM_NAME, ClinicalDocumentDecoder.MIPS.toLowerCase(Locale.getDefault()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gov.cms.qpp.conversion.encode;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -90,9 +91,16 @@ private void encodeChildren(List<Node> children, JsonWrapper measurementsWrapper
* @param parent the clinical document node
*/
private void pilferParent(JsonWrapper wrapper, Node parent) {
wrapper.put(ClinicalDocumentDecoder.PROGRAM_NAME,
String mvpId = parent.getValue(ClinicalDocumentDecoder.MVP_ID);
if (StringUtils.isEmpty(mvpId)) {
wrapper.put(ClinicalDocumentDecoder.PROGRAM_NAME,
parent.getValue(ClinicalDocumentDecoder.PROGRAM_NAME));
maintainContinuity(wrapper, parent, ClinicalDocumentDecoder.PROGRAM_NAME);
maintainContinuity(wrapper, parent, ClinicalDocumentDecoder.PROGRAM_NAME);
} else {
wrapper.put(ClinicalDocumentDecoder.PROGRAM_NAME,
parent.getValue(ClinicalDocumentDecoder.MVP_ID));
maintainContinuity(wrapper, parent, ClinicalDocumentDecoder.MVP_ID);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,39 @@ void testAppApmIncludesEntityID() throws EncodeException {
.isNotNull();
}

@Test
void testMvpIdReplacesProgramName() throws EncodeException {
JsonWrapper testJsonWrapper = new JsonWrapper();
clinicalDocumentNode.putValue(ClinicalDocumentDecoder.MVP_ID, "G0053");

ClinicalDocumentEncoder clinicalDocumentEncoder = new ClinicalDocumentEncoder(new Context());
clinicalDocumentEncoder.internalEncode(testJsonWrapper, clinicalDocumentNode);

JsonWrapper measurementSets = getMeasurementSets(testJsonWrapper);
String programName = measurementSets.get(0).getString("programName");

assertThat(programName).isEqualTo("G0053");
}

@Test
void testSubgroupIncludesSubgroupId() throws EncodeException {
JsonWrapper testJsonWrapper = new JsonWrapper();
clinicalDocumentNode.putValue(ClinicalDocumentDecoder.MVP_ID, "G0053");
clinicalDocumentNode.putValue(ClinicalDocumentDecoder.ENTITY_TYPE, "subgroup");
clinicalDocumentNode.putValue(ClinicalDocumentDecoder.SUBGROUP_ID, "SG-00000001");

ClinicalDocumentEncoder clinicalDocumentEncoder = new ClinicalDocumentEncoder(new Context());
clinicalDocumentEncoder.internalEncode(testJsonWrapper, clinicalDocumentNode);


JsonWrapper measurementSets = getMeasurementSets(testJsonWrapper);
String programName = measurementSets.get(0).getString("programName");

assertThat(programName).isEqualTo("G0053");
assertThat(testJsonWrapper.getString(ClinicalDocumentDecoder.ENTITY_TYPE)).isEqualTo("subgroup");
assertThat(testJsonWrapper.getString(ClinicalDocumentDecoder.ENTITY_ID)).isEqualTo("SG-00000001");
}


private JsonWrapper getMeasurementSets(JsonWrapper clinicalDocument) {
return clinicalDocument.get("measurementSets");
Expand Down

0 comments on commit 2ee6e30

Please sign in to comment.