Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIMTP-2909 Parse PER Administrative Communications Contact #156

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ public class N1PartyIdentification {
*/
private List<REFReferenceInformation> refList;

/*
* PER
*/
private List<PERAdministrativeCommunication> perList;

/**
* helper method to add REF
*
Expand All @@ -66,6 +71,18 @@ public void addReferenceInformation(REFReferenceInformation ref) {
refList.add(ref);
}

/**
* helper method to add PER
*
* @param per
*/
public void addAdministrativeCommunication(PERAdministrativeCommunication per) {
if (CollectionUtils.isEmpty(perList)) {
perList = new ArrayList<>();
}
perList.add(per);
}

/**
* helper method to add N3
*
Expand Down Expand Up @@ -134,4 +151,11 @@ public void setRefList(List<REFReferenceInformation> refList) {
this.refList = refList;
}

public List<PERAdministrativeCommunication> getPerList() {
return perList;
}

public void setPerList(List<PERAdministrativeCommunication> perList) {
this.perList = perList;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.walmartlabs.x12.common.segment;

/**
* Purpose: To identify a person or office to whom administrative communications should be directed
*/
public class PERAdministrativeCommunication {

public static final String IDENTIFIER = "PER";

// PER01, Code identifying the major duty or responsibility of the person or group named
private String contactFunctionCode;

// PER02, Free-form name
private String freeFormName;

// PER03/05/07, Code identifying the type of communication number
private String communicationNumberQualifier;

// PER04/06/08, Complete communications number including country or area code when applicable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be telephone number or email, can we change these to communicationDetailQualifier and communicationDetail or communicationInfoQualifier and communicationInfo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got this name communicationNumberQualifier/communicationNumber from 856 Ship Notice/Manifest pdf..

private String communicationNumber;


public String getContactFunctionCode() {
return contactFunctionCode;
}

public void setContactFunctionCode(String contactFunctionCode) {
this.contactFunctionCode = contactFunctionCode;
}

public String getFreeFormName() {
return freeFormName;
}

public void setFreeFormName(String freeFormName) {
this.freeFormName = freeFormName;
}

public String getCommunicationNumberQualifier() {
return communicationNumberQualifier;
}

public void setCommunicationNumberQualifier(String communicationNumberQualifier) {
this.communicationNumberQualifier = communicationNumberQualifier;
}

public String getCommunicationNumber() {
return communicationNumber;
}

public void setCommunicationNumber(String communicationNumber) {
this.communicationNumber = communicationNumber;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.walmartlabs.x12.common.segment.N1PartyIdentification;
import com.walmartlabs.x12.common.segment.N3PartyLocation;
import com.walmartlabs.x12.common.segment.N4GeographicLocation;
import com.walmartlabs.x12.common.segment.PERAdministrativeCommunication;
import com.walmartlabs.x12.common.segment.REFReferenceInformation;

public final class N1PartyIdentificationParser {
Expand Down Expand Up @@ -68,6 +69,9 @@ public static N1PartyIdentification handleN1Loop(X12Segment segment, SegmentIter
case REFReferenceInformation.IDENTIFIER:
n1.addReferenceInformation(REFReferenceInformationParser.parse(nextSegment));
break;
case PERAdministrativeCommunication.IDENTIFIER:
n1.setPerList(PERAdministrativeCommunicationsParser.parse(nextSegment));
break;
default:
// assume any other identifier is a break out of the N1 loop
// and let the other parser deal with it
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.walmartlabs.x12.common.segment.parser;

import com.walmartlabs.x12.X12Segment;
import com.walmartlabs.x12.common.segment.PERAdministrativeCommunication;

import java.util.ArrayList;
import java.util.List;

public final class PERAdministrativeCommunicationsParser {

/**
* parse the segment
*
* @param segment
* @return
*/
public static List<PERAdministrativeCommunication> parse(X12Segment segment) {
List<PERAdministrativeCommunication> perList = new ArrayList<>();

if (segment != null) {
String segmentIdentifier = segment.getIdentifier();
if (PERAdministrativeCommunication.IDENTIFIER.equals(segmentIdentifier)) {
int size = segment.segmentSize();
if (size > 2) {
String functionCode = segment.getElement(1);
String freeFormName = segment.getElement(2);
for (int i = 4; i < size; i += 2) {
PERAdministrativeCommunication per = new PERAdministrativeCommunication();
per.setContactFunctionCode(functionCode);
per.setFreeFormName(freeFormName);
per.setCommunicationNumberQualifier(segment.getElement(i - 1));
per.setCommunicationNumber(segment.getElement(i));

perList.add(per);
}
}
}
}
return perList;
}

private PERAdministrativeCommunicationsParser() {
// you can't make me
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,10 @@ private void doItemSegments(X12Segment segment, SegmentIterator segmentIterator,
DTMDateTimeReference dtm = DTMDateTimeReferenceParser.parse(segment);
item.addDTMDateTimeReference(dtm);
break;
case N1PartyIdentification.IDENTIFIER:
N1PartyIdentification n1 = N1PartyIdentificationParser.handleN1Loop(segment, segmentIterator);
item.addN1PartyIdentification(n1);
break;
default:
item.addUnparsedSegment(segment);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.walmartlabs.x12.common.segment.DTMDateTimeReference;
import com.walmartlabs.x12.common.segment.LINItemIdentification;
import com.walmartlabs.x12.common.segment.N1PartyIdentification;
import com.walmartlabs.x12.common.segment.PIDProductIdentification;
import com.walmartlabs.x12.common.segment.REFReferenceInformation;
import com.walmartlabs.x12.standard.X12Loop;
Expand Down Expand Up @@ -56,6 +57,10 @@ public class Item extends X12ParsedLoop {
* DTM: Date/Time Reference
*/
private List<DTMDateTimeReference> dtmReferences;
/*
* N1: Party Identifiers
*/
private List<N1PartyIdentification> n1PartyIdentifications;

/**
* returns true if the loop passed in is a Item loop
Expand Down Expand Up @@ -150,4 +155,24 @@ public List<REFReferenceInformation> getRefList() {
public void setRefList(List<REFReferenceInformation> refList) {
this.refList = refList;
}

/**
* helper method to add N1 to list
* @param n1
*/
public void addN1PartyIdentification(N1PartyIdentification n1) {
if (CollectionUtils.isEmpty(n1PartyIdentifications)) {
n1PartyIdentifications = new ArrayList<>();
}
n1PartyIdentifications.add(n1);
}


public List<N1PartyIdentification> getN1PartyIdentifications() {
return n1PartyIdentifications;
}

public void setN1PartyIdentifications(List<N1PartyIdentification> n1PartyIdentifications) {
this.n1PartyIdentifications = n1PartyIdentifications;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.walmartlabs.x12.common.segment.N1PartyIdentification;
import com.walmartlabs.x12.common.segment.N3PartyLocation;
import com.walmartlabs.x12.common.segment.N4GeographicLocation;
import com.walmartlabs.x12.common.segment.PERAdministrativeCommunication;
import org.junit.Test;

import java.util.ArrayList;
Expand Down Expand Up @@ -104,6 +105,22 @@ public void test_parse_handleN1Loop_one_loop_ends() {
assertEquals("85193", n4.getPostalCode());
assertEquals(null, n4.getCountryCode());

List<PERAdministrativeCommunication> perList = n1.getPerList();
assertNotNull(perList);
assertEquals(2, perList.size());

PERAdministrativeCommunication perAdministrativeCommunication = perList.get(0);
assertEquals("PY", perAdministrativeCommunication.getContactFunctionCode());
assertEquals("FSMA CONTACT", perAdministrativeCommunication.getFreeFormName());
assertEquals("TE", perAdministrativeCommunication.getCommunicationNumberQualifier());
assertEquals("+18884636332", perAdministrativeCommunication.getCommunicationNumber());

perAdministrativeCommunication = perList.get(1);
assertEquals("PY", perAdministrativeCommunication.getContactFunctionCode());
assertEquals("FSMA CONTACT", perAdministrativeCommunication.getFreeFormName());
assertEquals("EA", perAdministrativeCommunication.getCommunicationNumberQualifier());
assertEquals("FoodSafetyPlanBuilder@fda.hhs.gov", perAdministrativeCommunication.getCommunicationNumber());

assertFalse(iterator.hasNext());
}

Expand Down Expand Up @@ -233,6 +250,8 @@ private List<X12Segment> getN1LoopOne() {
segments.add(segment);
segment = new X12Segment("N4*CASA GRANDE*AZ*85193");
segments.add(segment);
segment = new X12Segment("PER*PY*FSMA CONTACT*TE*+18884636332*EA*FoodSafetyPlanBuilder@fda.hhs.gov");
segments.add(segment);

return segments;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.walmartlabs.x12.common.segment.parser;

import com.walmartlabs.x12.X12Segment;
import com.walmartlabs.x12.common.segment.PERAdministrativeCommunication;
import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;


public class PERAdministrativeCommunicationsParserTest {

@Test
public void test_parse_null_segment() {
X12Segment segment = null;
List<PERAdministrativeCommunication> perList = PERAdministrativeCommunicationsParser.parse(segment);
assertNotNull(perList);
assertEquals(0, perList.size());
}

@Test
public void test_parse_empty_segment() {
X12Segment segment = new X12Segment("");
List<PERAdministrativeCommunication> perList = PERAdministrativeCommunicationsParser.parse(segment);
assertNotNull(perList);
assertEquals(0, perList.size());
}

@Test
public void test_parse_segment() {
X12Segment segment = new X12Segment("PER*PY*FSMA CONTACT*TE*+18884636332*EA*FoodSafetyPlanBuilder@fda.hhs.gov");
List<PERAdministrativeCommunication> perList = PERAdministrativeCommunicationsParser.parse(segment);
assertNotNull(perList);
assertEquals(2, perList.size());

PERAdministrativeCommunication perAdministrativeCommunication = perList.get(0);
assertEquals("PY", perAdministrativeCommunication.getContactFunctionCode());
assertEquals("FSMA CONTACT", perAdministrativeCommunication.getFreeFormName());
assertEquals("TE", perAdministrativeCommunication.getCommunicationNumberQualifier());
assertEquals("+18884636332", perAdministrativeCommunication.getCommunicationNumber());

perAdministrativeCommunication = perList.get(1);
assertEquals("PY", perAdministrativeCommunication.getContactFunctionCode());
assertEquals("FSMA CONTACT", perAdministrativeCommunication.getFreeFormName());
assertEquals("EA", perAdministrativeCommunication.getCommunicationNumberQualifier());
assertEquals("FoodSafetyPlanBuilder@fda.hhs.gov", perAdministrativeCommunication.getCommunicationNumber());
}

@Test
public void test_parse_segment_ur() {
X12Segment segment = new X12Segment("PER*PY*FSMA CONTACT*UR*localhost:8080");
List<PERAdministrativeCommunication> perList = PERAdministrativeCommunicationsParser.parse(segment);
assertNotNull(perList);
assertEquals(1, perList.size());

PERAdministrativeCommunication perAdministrativeCommunication = perList.get(0);
assertEquals("PY", perAdministrativeCommunication.getContactFunctionCode());
assertEquals("FSMA CONTACT", perAdministrativeCommunication.getFreeFormName());
assertEquals("UR", perAdministrativeCommunication.getCommunicationNumberQualifier());
assertEquals("localhost:8080", perAdministrativeCommunication.getCommunicationNumber());
}

@Test
public void test_parse_segment_not_balanced() {
X12Segment segment = new X12Segment("PER*PY*FSMA CONTACT*TE*+18884636332*EA");
List<PERAdministrativeCommunication> perList = PERAdministrativeCommunicationsParser.parse(segment);
assertNotNull(perList);
assertEquals(1, perList.size());

PERAdministrativeCommunication perAdministrativeCommunication = perList.get(0);
assertEquals("PY", perAdministrativeCommunication.getContactFunctionCode());
assertEquals("FSMA CONTACT", perAdministrativeCommunication.getFreeFormName());
assertEquals("TE", perAdministrativeCommunication.getCommunicationNumberQualifier());
assertEquals("+18884636332", perAdministrativeCommunication.getCommunicationNumber());
}

}
Loading
Loading