use of ca.uhn.hl7v2.model.Structure in project tdi-studio-se by Talend.
the class HL7MessageTreeLabelProvider method getColumnText.
public String getColumnText(Object element, int columnIndex) {
if (element instanceof Type) {
Type datatype = (Type) element;
return datatype.getName();
}
if (element instanceof IModel) {
if (element instanceof TypeModel) {
TypeModel tm = (TypeModel) element;
allPrimitives.addAll(Arrays.asList(tm.getPrimitives()));
}
return ((IModel) element).getDisplayName();
}
// }
if (element instanceof Group) {
Group group = (Group) element;
String groupName = group.getName();
groupName = groupName.substring(groupName.lastIndexOf('.') + 1, groupName.length());
return groupName;
}
if (element instanceof Structure) {
Structure structure = (Structure) element;
return structure.getName();
}
return null;
}
use of ca.uhn.hl7v2.model.Structure in project tdi-studio-se by Talend.
the class HL7PublicUtil method getFirstLevelChild.
public List getFirstLevelChild(Object parentElement) {
List values = new ArrayList();
if (parentElement instanceof Message) {
Message messParent = (Message) parentElement;
String[] childNames = messParent.getNames();
if (!values.isEmpty()) {
values.clear();
}
for (int i = 0; i < childNames.length; i++) {
try {
Structure[] childReps = messParent.getAll(childNames[i]);
for (int j = 0; j < childReps.length; j++) {
if (childReps[j] instanceof Message) {
values.add(childReps[j]);
}
if (childReps[j] instanceof Group) {
values.add(childReps[j]);
allSegmentFromGroup.clear();
getAllSegmentsFromGroup((Group) childReps[j]);
}
if (childReps[j] instanceof Segment) {
SegmentModel sModel = new SegmentModel((Segment) childReps[j], messParent, i, j);
if (sModel.getTypes() != null && sModel.getTypes().length > 0) {
values.add(sModel);
if (!allSegmentsForMessage.contains(sModel)) {
allSegmentsForMessage.add(sModel);
}
}
}
}
} catch (HL7Exception e) {
e.printStackTrace();
}
}
}
return values;
}
use of ca.uhn.hl7v2.model.Structure in project tdi-studio-se by Talend.
the class HL7PublicUtil method getChildren.
public Set getChildren(Object parentElement) {
// List values = new ArrayList();
Set values = new HashSet();
if (parentElement instanceof Message) {
Message messParent = (Message) parentElement;
String[] childNames = messParent.getNames();
if (!values.isEmpty()) {
values.clear();
}
for (int i = 0; i < childNames.length; i++) {
try {
Structure[] childReps = messParent.getAll(childNames[i]);
for (int j = 0; j < childReps.length; j++) {
if (childReps[j] instanceof Message) {
values.add(childReps[j]);
if (getChildren(childReps[j]).size() > 0) {
values.addAll(getChildren(childReps[j]));
}
}
if (childReps[j] instanceof Group) {
values.add(childReps[j]);
allSegmentFromGroup.clear();
getAllSegmentsFromGroup((Group) childReps[j]);
}
if (childReps[j] instanceof Segment) {
SegmentModel sModel = new SegmentModel((Segment) childReps[j], messParent, i, j);
if (sModel.getTypes() != null && sModel.getTypes().length > 0) {
values.add(sModel);
if (getChildren(sModel).size() > 0) {
values.addAll(getChildren(sModel));
}
if (!allSegmentsForMessage.contains(sModel)) {
allSegmentsForMessage.add(sModel);
}
}
}
}
// values.addAll(Arrays.asList(childReps));
} catch (HL7Exception e) {
e.printStackTrace();
}
}
return values;
}
if (parentElement instanceof Segment) {
values.clear();
Segment segment = (Segment) parentElement;
SegmentModel sm = new SegmentModel(segment, segment, 0, 0);
TypeModel[] models = sm.getTypes();
for (TypeModel model : models) {
values.add(model);
if (getChildren(model).size() > 0) {
values.addAll(getChildren(model));
}
}
return values;
}
if (parentElement instanceof SegmentModel) {
SegmentModel sm = (SegmentModel) parentElement;
TypeModel[] models = sm.getTypes();
for (TypeModel model : models) {
values.add(model);
if (getChildren(model).size() > 0) {
values.addAll(getChildren(model));
}
}
return values;
}
if (parentElement instanceof TypeModel) {
TypeModel tm = (TypeModel) parentElement;
PrimitiveModel[] models = tm.getPrimitives();
for (PrimitiveModel model : models) {
values.add(model);
if (getChildren(model).size() > 0) {
values.addAll(getChildren(model));
}
}
return values;
// return tm.getPrimitives();
}
if (parentElement instanceof Group) {
values.clear();
Group group = (Group) parentElement;
String[] childNames = group.getNames();
for (int i = 0; i < childNames.length; i++) {
try {
Structure[] childReps = group.getAll(childNames[i]);
for (int j = 0; j < childReps.length; j++) {
if (childReps[j] instanceof Segment) {
SegmentModel sm = new SegmentModel((Segment) childReps[j], group, i, j);
if (sm.getTypes() != null && sm.getTypes().length > 0) {
values.add(sm);
if (getChildren(sm).size() > 0) {
values.addAll(getChildren(sm));
}
}
} else {
values.add(childReps[j]);
if (getChildren(childReps[j]).size() > 0) {
values.addAll(getChildren(childReps[j]));
}
}
}
// values.addAll(Arrays.asList(childReps));
} catch (HL7Exception e) {
e.printStackTrace();
}
}
return values;
}
return values;
}
use of ca.uhn.hl7v2.model.Structure in project nifi by apache.
the class HapiMessage method populateSegments.
private void populateSegments(final Group group, final List<HL7Segment> segments) throws HL7Exception {
for (final String structureName : group.getNames()) {
final Structure[] structures = group.getAll(structureName);
if (group.isGroup(structureName)) {
for (final Structure structure : structures) {
populateSegments((Group) structure, segments);
}
} else {
for (final Structure structure : structures) {
final Segment segment = (Segment) structure;
final HapiSegment hapiSegment = new HapiSegment(segment);
segments.add(hapiSegment);
}
}
}
}
use of ca.uhn.hl7v2.model.Structure in project streamsx.health by IBMStreams.
the class ObxToSplMapper method messageToModel.
@SuppressWarnings("unchecked")
public <T> Iterable<T> messageToModel(Message message) {
ArrayList<Observation> observations = new ArrayList<Observation>();
if (message instanceof ORU_R01) {
ORU_R01 oruMsg = (ORU_R01) message;
String obxTs = "";
String obxLocation = "";
String sendingApp = "";
String sendingFacility = "";
try {
MSH msh = oruMsg.getMSH();
sendingApp = msh.getSendingApplication().encode();
sendingFacility = msh.getSendingFacility().encode();
List<ORU_R01_PATIENT_RESULT> patient_RESULTAll = ((ORU_R01) message).getPATIENT_RESULTAll();
for (ORU_R01_PATIENT_RESULT result : patient_RESULTAll) {
ORU_R01_ORDER_OBSERVATION order_OBSERVATION = result.getORDER_OBSERVATION();
OBR obr = order_OBSERVATION.getOBR();
DTM ts = obr.getObservationDateTime();
obxTs = ts.getValue();
ORU_R01_PATIENT patient = result.getPATIENT();
ORU_R01_VISIT visit = patient.getVISIT();
PL location = visit.getPV1().getAssignedPatientLocation();
obxLocation = location.encode();
List<ORU_R01_OBSERVATION> observationAll = order_OBSERVATION.getOBSERVATIONAll();
for (ORU_R01_OBSERVATION oru_R01_OBSERVATION : observationAll) {
parseOBX(observations, obxTs, obxLocation, oru_R01_OBSERVATION.getOBX(), sendingApp, sendingFacility);
}
}
} catch (HL7Exception e) {
if (TRACE.isDebugEnabled())
TRACE.log(TraceLevel.WARN, e);
}
try {
OBR obr = (OBR) oruMsg.get("OBR");
DTM ts = obr.getObservationDateTime();
obxTs = ts.getValue();
Structure tmp = oruMsg.get("PV1");
if (tmp != null) {
PV1 pv1 = (PV1) tmp;
PL location = pv1.getAssignedPatientLocation();
obxLocation = location.encode();
}
Structure[] structures = oruMsg.getAll("OBX");
for (Structure structure : structures) {
parseOBX(observations, obxTs, obxLocation, (OBX) structure, sendingApp, sendingFacility);
}
} catch (HL7Exception e) {
if (TRACE.isDebugEnabled())
TRACE.log(TraceLevel.WARN, e);
}
}
return (Iterable<T>) observations;
}
Aggregations