Skip to content

Commit

Permalink
[CNDIT-1758] CDA mapper changes for ECR (#225)
Browse files Browse the repository at this point in the history
* CDA mapper changes

* Removing debug code

* Fixing sonar code smell and adding new tests for ecr poll
service

* Fixing sonar code smell

* Removed logback config file
  • Loading branch information
rshanmugam-enquizit authored Sep 27, 2024
1 parent 623a532 commit 1d1d6ea
Show file tree
Hide file tree
Showing 16 changed files with 273 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private CdaContainerComp mapParentContainer(POCDMT000040ClinicalDocument1 clinic
clinicalDocument.getCode().setDisplayName("Public Health Case Report - PHRI");
clinicalDocument.setTitle(ST.Factory.newInstance());

clinicalDocument.getTitle().set(cdaMapHelper.mapToStringData("Public Health Case Report - Data from Legacy System to CDA"));
clinicalDocument.getTitle().set(cdaMapHelper.mapToPCData("Public Health Case Report - Data from Legacy System to CDA"));

clinicalDocument.setEffectiveTime(TS.Factory.newInstance());
clinicalDocument.getEffectiveTime().setValue(this.cdaMapHelper.getCurrentUtcDateTimeInCdaFormat());
Expand Down Expand Up @@ -237,28 +237,28 @@ private void mapCustodian(POCDMT000040ClinicalDocument1 clinicalDocument) throws

custodianValue = mapToTranslatedValue("CUS103");
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().addNewStreetAddressLine();
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().getStreetAddressLineArray(k).set(cdaMapHelper.mapToCData(custodianValue));
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().getStreetAddressLineArray(k).set(cdaMapHelper.mapToPCData(custodianValue));
k = k+1;
custodianValue = mapToTranslatedValue("CUS104");
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().addNewStreetAddressLine();
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().getStreetAddressLineArray(k).set(cdaMapHelper.mapToCData(custodianValue));
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().getStreetAddressLineArray(k).set(cdaMapHelper.mapToPCData(custodianValue));

k = 0;
custodianValue = mapToTranslatedValue("CUS105");
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().addNewCity();
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().getCityArray(k).set(cdaMapHelper.mapToCData(custodianValue));
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().getCityArray(k).set(cdaMapHelper.mapToPCData(custodianValue));

custodianValue = mapToTranslatedValue("CUS106");
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().addNewState();
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().getStateArray(k).set(cdaMapHelper.mapToCData(custodianValue));
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().getStateArray(k).set(cdaMapHelper.mapToPCData(custodianValue));

custodianValue = mapToTranslatedValue("CUS107");
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().addNewPostalCode();
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().getPostalCodeArray(k).set(cdaMapHelper.mapToCData(custodianValue));
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().getPostalCodeArray(k).set(cdaMapHelper.mapToPCData(custodianValue));

custodianValue = mapToTranslatedValue("CUS108");
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().addNewCountry();
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().getCountryArray(k).set(cdaMapHelper.mapToCData(custodianValue));
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getAddr().getCountryArray(k).set(cdaMapHelper.mapToPCData(custodianValue));

custodianValue = mapToTranslatedValue("CUS109");
clinicalDocument.getCustodian().getAssignedCustodian().getRepresentedCustodianOrganization().getTelecom().setValue(custodianValue);
Expand All @@ -277,7 +277,7 @@ private void mapAuthor(POCDMT000040ClinicalDocument1 clinicalDocument) throws Ec
clinicalDocument.getAuthorArray(0).getAssignedAuthor().addNewAssignedPerson().addNewName();
clinicalDocument.getAuthorArray(0).getAssignedAuthor().getAssignedPerson().getNameArray(0).addNewFamily();
value = mapToTranslatedValue("AUT102");
clinicalDocument.getAuthorArray(0).getAssignedAuthor().getAssignedPerson().getNameArray(0).getFamilyArray(0).set(cdaMapHelper.mapToCData(value));
clinicalDocument.getAuthorArray(0).getAssignedAuthor().getAssignedPerson().getNameArray(0).getFamilyArray(0).set(cdaMapHelper.mapToPCData(value));

OffsetDateTime now = OffsetDateTime.now();
String formattedDateTime = formatDateTime(now);
Expand All @@ -292,31 +292,34 @@ private static String formatDateTime(OffsetDateTime dateTime) {

private String convertXmlToString(ClinicalDocumentDocument1 clinicalDocument) {
XmlOptions options = new XmlOptions();
options.setSavePrettyPrint();
options.setSavePrettyPrintIndent(4); // Set indentation
// Use a default namespace instead of a prefixed one (like urn:)
options.setUseDefaultNamespace();
// Set to always use full tags instead of self-closing tags
options.setSaveNoXmlDecl();
options.setSaveOuter();


String xmlOutput = clinicalDocument.xmlText(options);

xmlOutput = xmlOutput.replaceAll("<STRING[^>]*>([^<]+)</STRING>", "$1");// NOSONAR // remove string tag
xmlOutput = xmlOutput.replaceAll("<CDATA[^>]*>(.*?)</CDATA>", "$1");// NOSONAR // replace CDATA with real CDATA
xmlOutput = xmlOutput.replaceAll("\\[CDATA\\](.*?)\\[CDATA\\]", "<![CDATA[$1]]>");// NOSONAR // replace CDATA with real CDATA
xmlOutput = xmlOutput.replaceAll("<CDATA[^>]*>(.*?)</CDATA>", "<![CDATA[$1]]>");// NOSONAR // replace CDATA with real CDATA
xmlOutput = xmlOutput.replaceAll("<(\\w+)></\\1>", "");// NOSONAR // remove empty <tag></tag>
xmlOutput = xmlOutput.replaceAll("<(\\w+)/>", "");// NOSONAR // remove empty <tag/>
xmlOutput = xmlOutput.replaceAll("<STUD xmlns=\"\">STUD</STUD>", "");// NOSONAR // remove STUD tag
xmlOutput = xmlOutput.replaceAll("<stud xmlns=\"\">stud</stud>", "");// NOSONAR // remove STUD tag
xmlOutput = xmlOutput.replaceAll("(?m)^\\s*$[\n\r]{1,}", "");// NOSONAR // remove new line

xmlOutput = xmlOutput.replaceAll("sdtcxmlnamespaceholder=\""+ XML_NAME_SPACE_HOLDER +"\"", "xmlns:sdtcxmlnamespaceholder=\""+XML_NAME_SPACE_HOLDER+"\"");// NOSONAR
xmlOutput = xmlOutput.replaceAll("sdt=\"urn:hl7-org:sdtc\"", "xmlns:sdt=\"urn:hl7-org:sdtc\"");// NOSONAR
xmlOutput = xmlOutput.replaceAll("xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");// NOSONAR
xmlOutput = xmlOutput.replaceAll("xmlns:xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");// NOSONAR
xmlOutput = xmlOutput.replaceAll("xmlns:xmlns", "xmlns");// NOSONAR
xmlOutput = xmlOutput.replaceAll("xmlns:urn=\"urn:hl7-org:v3\"", "");// NOSONAR

xmlOutput = xmlOutput.replaceAll("schemaLocation=\""+ XML_NAME_SPACE_HOLDER +" CDA_SDTC.xsd\"", "xsi:schemaLocation=\""+XML_NAME_SPACE_HOLDER +" CDA_SDTC.xsd\"");// NOSONAR
xmlOutput = xmlOutput.replaceAll("<section xmlns=\"\">", "<section>");// NOSONAR

xmlOutput = xmlOutput.replaceAll("<xmlns=\"\">", "");// NOSONAR
xmlOutput = xmlOutput.replaceAll("xmlns=\"\"", "");// NOSONAR
xmlOutput = xmlOutput.replaceAll("xsi:type=\"urn:CE\"", "xsi:type=\"CE\"");// NOSONAR
xmlOutput = xmlOutput.replaceAll("xsi:type=\"urn:ST\"", "xsi:type=\"ST\"");// NOSONAR
xmlOutput = xmlOutput.replaceAll("xsi:type=\"urn:II\"", "xsi:type=\"II\"");// NOSONAR
xmlOutput = xmlOutput.replaceAll("xsi:type=\"urn:TS\"", "xsi:type=\"TS\"");// NOSONAR

xmlOutput = xmlOutput.replaceAll("\\^NOT_MAPPED", "");// NOSONAR
xmlOutput = xmlOutput.replaceAll("NOT_MAPPED","");// NOSONAR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import gov.cdc.dataingestion.nbs.repository.model.dto.EcrMsgCaseParticipantDto;
import gov.cdc.dataingestion.nbs.repository.model.dto.lookup.PhdcQuestionLookUpDto;
import gov.cdc.nedss.phdc.cda.*;
import org.apache.xmlbeans.XmlCursor;

import javax.xml.namespace.QName;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -55,7 +53,7 @@ public CdaCaseMapper mapToCaseTop(EcrSelectedRecord input, POCDMT000040ClinicalD
clinicalDocument.getComponent().getStructuredBody().getComponentArray(c).getSection().getCode().setCodeSystem(CODE_SYSTEM);
clinicalDocument.getComponent().getStructuredBody().getComponentArray(c).getSection().getCode().setCodeSystemName(CODE_SYSTEM_NAME);
clinicalDocument.getComponent().getStructuredBody().getComponentArray(c).getSection().getCode().setDisplayName("Clinical Information");
clinicalDocument.getComponent().getStructuredBody().getComponentArray(c).getSection().getTitle().set(cdaMapHelper.mapToStringData("CLINICAL INFORMATION"));
clinicalDocument.getComponent().getStructuredBody().getComponentArray(c).getSection().getTitle().set(cdaMapHelper.mapToPCData("CLINICAL INFORMATION"));

componentCounter = c;

Expand Down Expand Up @@ -528,12 +526,11 @@ private void setMessageAnswerDate(String name, EcrMsgCaseAnswerDto in, POCDMT000

var element = out.getSection().getEntryArray(counter).getObservation().getValueArray(0);

XmlCursor cursor = element.newCursor();
cursor.toFirstAttribute();
cursor.insertAttributeWithValue(new QName(NAME_SPACE_URL, "type"), "TS");
TS ts = TS.Factory.newInstance();

var ot = cdaMapHelper.mapToTsType(in.getAnswerTxt()).toString();
cursor.insertAttributeWithValue("value", ot);
cursor.dispose();
ts.setValue(ot);
element.set(ts);
}

}
Expand Down Expand Up @@ -618,7 +615,7 @@ private MultiSelect mapToMultiSelect(EcrMsgCaseAnswerDto in,
out.getCode().setCodeSystem(CLINICAL_CODE_SYSTEM);
out.getCode().setCodeSystemName(CLINICAL_CODE_SYSTEM_NAME);
out.getCode().setDisplayName("Generic Repeating Questions Section");
out.getTitle().set(cdaMapHelper.mapToStringData("REPEATING QUESTIONS"));
out.getTitle().set(cdaMapHelper.mapToPCData("REPEATING QUESTIONS"));
int componentCounter = 0;
String dataType="DATE";
int questionGroupSeqNbr = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CdaInterviewMapper mapToInterviewTop(EcrSelectedRecord input, POCDMT00004
if (clinicalDocument.getComponent().getStructuredBody().getComponentArray(c).getSection().getTitle() == null) {
clinicalDocument.getComponent().getStructuredBody().getComponentArray(c).getSection().addNewTitle();
}
clinicalDocument.getComponent().getStructuredBody().getComponentArray(c).getSection().getTitle().set(cdaMapHelper.mapToStringData("INTERVIEW SECTION"));
clinicalDocument.getComponent().getStructuredBody().getComponentArray(c).getSection().getTitle().set(cdaMapHelper.mapToPCData("INTERVIEW SECTION"));
}

POCDMT000040Component3 ot = clinicalDocument.getComponent().getStructuredBody().getComponentArray(c);
Expand Down Expand Up @@ -818,7 +818,7 @@ private void mapToInterviewObservationFieldP2Date(String name,
if(name.equals(COL_ANS_TXT) && !in.getAnswerTxt().isEmpty()){
var element = out.getEntryRelationshipArray(counter).getObservation().getValueArray(0);
XmlCursor cursor = element.newCursor();
cursor.setAttributeText(new QName(NAME_SPACE_URL, "type"), "TS");
cursor.setAttributeText(new QName(NAME_SPACE_URL, "xsi:type"), "TS");
cursor.setAttributeText(new QName("name"), value); // This is an assumption based on the original code

if(!in.getAnswerTxt().isEmpty()){
Expand Down
Loading

0 comments on commit 1d1d6ea

Please sign in to comment.