ca.uhn.hl7v2.HL7Exception Java Examples

The following examples show how to use ca.uhn.hl7v2.HL7Exception. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HL7ReaderV24.java    From elexis-3-core with Eclipse Public License 1.0 7 votes vote down vote up
@Override
public String getSender() throws ElexisException{
	String sender;
	try {
		MSH msh = (MSH) message.get("MSH");
		sender = msh.getMsh4_SendingFacility().getNamespaceID().getValue();
		if (sender == null) {
			sender = "";
		}
	} catch (HL7Exception e) {
		throw new ElexisException(e.getMessage(), e);
	}
	return sender;
}
 
Example #2
Source File: ExtractHL7Attributes.java    From localization_nifi with Apache License 2.0 7 votes vote down vote up
private static Map<String, Type> getAllFields(final String segmentKey, final Segment segment, final boolean useNames) throws HL7Exception {
    final Map<String, Type> fields = new TreeMap<>();
    final String[] segmentNames = segment.getNames();
    for (int i = 1; i <= segment.numFields(); i++) {
        final Type field = segment.getField(i, 0);
        if (!isEmpty(field)) {
            final String fieldName;
            if (useNames) {
                fieldName = WordUtils.capitalize(segmentNames[i-1]).replaceAll("\\W+", "");
            } else {
                fieldName = String.valueOf(i);
            }

            final String fieldKey = new StringBuilder()
                .append(segmentKey)
                .append(".")
                .append(fieldName)
                .toString();

            fields.put(fieldKey, field);
        }
    }
    return fields;
}
 
Example #3
Source File: HL7_ORU_R01.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Reads an ORU_R01 HL7 file
 * 
 * @param text
 *            ISO-8559-1 String
 * @param readWithValidation
 *            True for parsing with validation, False for parsing without validation
 * @return The ORU_R01 message
 * @throws HL7Exception
 */
public ORU_R01 read(String text, boolean readWithValidation) throws HL7Exception{
	Parser p = new PipeParser();
	if (readWithValidation) {
		p.setValidationContext(new ElexisValidation());
	} else {
		p.setValidationContext(new NoValidation());
	}
	Message hl7Msg = p.parse(text);
	if (hl7Msg instanceof ORU_R01) {
		return (ORU_R01) hl7Msg;
	} else {
		addError(
			MessageFormat.format(Messages.HL7_ORU_R01_Error_WrongMsgType, hl7Msg.getName()));
	}
	return null;
}
 
Example #4
Source File: TestHL7Query.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings({"unchecked", "rawtypes"})
public void testSelectField() throws HL7Exception, IOException {
    final HL7Query query = HL7Query.compile("SELECT PID.5");
    final HL7Message msg = createMessage(new File("src/test/resources/hypoglycemia"));
    final QueryResult result = query.evaluate(msg);
    assertTrue(result.isMatch());
    final List<String> labels = result.getLabels();
    assertEquals(1, labels.size());
    assertEquals(1, result.getHitCount());

    final Object names = result.nextHit().getValue("PID.5");
    assertTrue(names instanceof List);
    final List<Object> nameList = (List) names;
    assertEquals(1, nameList.size());
    final HL7Field nameField = (HL7Field) nameList.get(0);
    assertEquals("SMITH^JOHN", nameField.getValue());
}
 
Example #5
Source File: HL7ReaderV251.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private OrcMessage extractOrc(ORC orc) throws HL7Exception{
	if (orc != null) {
		OrcMessage orcMessage = new OrcMessage();
		XCN[] ops = orc.getOrderingProvider();
		for (XCN op : ops) {
			FN fn = op.getFamilyName();
			ST familyName = null;
			if (fn != null) {
				familyName = fn.getSurname();
				if (familyName == null) {
					familyName = fn.getOwnSurname();
				}
			}
			addNameValuesToOrcMessage(op.getGivenName(), familyName, orcMessage);
		}
		return orcMessage;
	}
	return null;
}
 
Example #6
Source File: HapiMessage.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public HapiMessage(final Message message) throws HL7Exception {
    this.message = message;

    allSegments = new ArrayList<>();
    populateSegments(message, allSegments);

    segmentMap = new HashMap<>();
    for (final HL7Segment segment : allSegments) {
        final String segmentName = segment.getName();
        List<HL7Segment> segmentList = segmentMap.get(segmentName);
        if (segmentList == null) {
            segmentList = new ArrayList<>();
            segmentMap.put(segmentName, segmentList);
        }

        segmentList.add(segment);
    }
}
 
Example #7
Source File: HL7_OML_O21.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates an OMG_O19 message
 * 
 * @param patient
 * @param kostentraeger
 * @param rechnungsempfaenger
 * @param auftragsNummer
 * @param plan
 *            Abrechnungssystem (MV, UVG, VVG, KVG, usw)
 * @param beginDate
 * @param vnr
 *            Versicherungs-, Fall- oder Unfallnr
 * @return
 */
public String createText(final HL7Patient patient, final HL7Kostentraeger rechnungsempfaenger,
	final HL7Kostentraeger kostentraeger, final String plan, final Date beginDate,
	final String fallNr, final long auftragsNummer) throws DataTypeException, HL7Exception{
	
	OML_O21 omg = new OML_O21();
	fillMSH(omg.getMSH(), "OML", "O21", mandant, this.uniqueMessageControlID, //$NON-NLS-1$ //$NON-NLS-2$
		this.uniqueProcessingID, patient); //$NON-NLS-1$ //$NON-NLS-2$
	fillPID(omg.getPATIENT().getPID(), patient);
	fillNK1(omg.getPATIENT().getNK1(), rechnungsempfaenger);
	fillPV1(omg.getPATIENT().getPATIENT_VISIT().getPV1(), patient, beginDate);
	fillIN1(omg.getPATIENT().getINSURANCE().getIN1(), patient, kostentraeger, plan, fallNr);
	fillORC(omg.getORDER().getORC(), "1", auftragsNummer); //$NON-NLS-1$
	
	// Now, let's encode the message and look at the output
	Parser parser = new PipeParser();
	return parser.encode(omg);
}
 
Example #8
Source File: TestHL7Query.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testNotNull() throws HL7Exception, IOException {
    HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.999 NOT NULL");
    QueryResult result = hl7Query.evaluate(hypoglycemia);
    assertFalse(result.isMatch());

    hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.1 NOT NULL");
    result = hl7Query.evaluate(hypoglycemia);
    assertTrue(result.isMatch());

    hl7Query = HL7Query.compile("SELECT MESSAGE WHERE ZZZ NOT NULL");
    result = hl7Query.evaluate(hypoglycemia);
    assertFalse(result.isMatch());

    hl7Query = HL7Query.compile("SELECT MESSAGE WHERE OBX NOT NULL");
    result = hl7Query.evaluate(hypoglycemia);
    assertTrue(result.isMatch());
}
 
Example #9
Source File: HL7MessageUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public static MessageContext createErrorMessageContext(String rawMessage, Exception errorMsg,
                                                       InboundProcessorParams params)
        throws AxisFault, HL7Exception {
    MessageContext synCtx = createSynapseMessageContext(
            params.getProperties().getProperty(MLLPConstants.HL7_INBOUND_TENANT_DOMAIN));

    if (params.getProperties().getProperty(Axis2HL7Constants.HL7_VALIDATION_PASSED) != null) {
        synCtx.setProperty(Axis2HL7Constants.HL7_VALIDATION_PASSED,
                           params.getProperties().getProperty(Axis2HL7Constants.HL7_VALIDATION_PASSED));
    }

    try {
        synCtx.setProperty(SynapseConstants.ERROR_CODE, SynapseConstants.RCV_IO_ERROR_RECEIVING);
        synCtx.setProperty(SynapseConstants.ERROR_MESSAGE, errorMsg.getMessage());
        synCtx.setProperty(SynapseConstants.ERROR_DETAIL,
                           (errorMsg.getCause() == null ? "null" : errorMsg.getCause().getMessage()));
        synCtx.setProperty(SynapseConstants.ERROR_EXCEPTION, errorMsg);
        synCtx.setEnvelope(createErrorEnvelope(synCtx, rawMessage, errorMsg.getMessage(), params));
    } catch (Exception e) {
        throw new HL7Exception(e);
    }

    return synCtx;
}
 
Example #10
Source File: HL7_ORU_R01.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Adds a ORU_R01 observation result
 * 
 * @param oru
 * @param patient
 * @param labItem
 * @param labwert
 * @param initial
 * @return
 */
private String addResultInternal(final ORU_R01 oru, final HL7Patient patient,
	final HL7LaborItem labItem, final HL7LaborWert labwert, int orderObservationIndex)
	throws DataTypeException, HL7Exception{
	
	// Observation
	ORU_R01_ORDER_OBSERVATION orderObservation =
		(ORU_R01_ORDER_OBSERVATION) oru.getPATIENT_RESULT().getORDER_OBSERVATION(
			orderObservationIndex);
	fillOBR(orderObservation.getOBR(), orderObservationIndex, labItem);
	fillOBX(orderObservation.getOBSERVATION().getOBX(), patient, labItem, labwert);
	if (labwert.getKommentar() != null && labwert.getKommentar().length() > 0) {
		fillNTE(orderObservation.getNTE(), labwert);
	}
	// Now, let's encode the message and look at the output
	Parser parser = new PipeParser();
	return parser.encode(oru);
}
 
Example #11
Source File: HL7ReaderV24.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private OrcMessage extractOrc(ORC orc) throws HL7Exception{
	if (orc != null) {
		OrcMessage orcMessage = new OrcMessage();
		XCN[] ops = orc.getOrderingProvider();
		for (XCN op : ops) {
			FN fn = op.getFamilyName();
			ST familyName = null;
			if (fn != null) {
				familyName = fn.getSurname();
				if (familyName == null) {
					familyName = fn.getOwnSurname();
				}
			}
			addNameValuesToOrcMessage(op.getGivenName(), familyName, orcMessage);
		}
		return orcMessage;
	}
	return null;
}
 
Example #12
Source File: HL7_ADT_A08.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates an ORU_R01 message
 * 
 * @param patient
 * @param consultation
 * @param labItem
 * @param labwert
 * 
 * @return
 */
public String createText(final HL7Patient patient, HL7Konsultation consultation)
	throws DataTypeException, HL7Exception{
	
	ADT_A08 adt = new ADT_A08();
	// Message
	fillMSH(adt.getMSH(), "ADT", "A08", mandant, this.uniqueMessageControlID, //$NON-NLS-1$ //$NON-NLS-2$
		"8859/1", patient); //$NON-NLS-1$ //$NON-NLS-2$
	
	fillEVN(adt.getEVN());
	
	// Patient
	fillPID(adt.getPID(), patient);
	
	// Patient Visit
	fillPV1(adt.getPV1(), consultation);
	
	// Now, let's encode the message and look at the output
	HapiContext context = new DefaultHapiContext();
	Parser parser = context.getPipeParser();
	return parser.encode(adt);
}
 
Example #13
Source File: HL7ReaderV231.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private OrcMessage extractOrc(ORC orc) throws HL7Exception{
	if (orc != null) {
		OrcMessage orcMessage = new OrcMessage();
		XCN[] ops = orc.getOrderingProvider();
		for (XCN op : ops) {
			FN fn = op.getFamilyLastName();
			ST familyName = null;
			if (fn != null) {
				familyName = fn.getFamilyName();
			}
			addNameValuesToOrcMessage(op.getGivenName(), familyName, orcMessage);
		}
		return orcMessage;
	}
	return null;
}
 
Example #14
Source File: TestHL7Query.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testNotNull() throws HL7Exception, IOException {
    HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.999 NOT NULL");
    QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia")));
    assertFalse(result.isMatch());

    hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.1 NOT NULL");
    result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia")));
    assertTrue(result.isMatch());

    hl7Query = HL7Query.compile("SELECT MESSAGE WHERE ZZZ NOT NULL");
    result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia")));
    assertFalse(result.isMatch());

    hl7Query = HL7Query.compile("SELECT MESSAGE WHERE OBX NOT NULL");
    result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia")));
    assertTrue(result.isMatch());
}
 
Example #15
Source File: HL7Codec.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public int encode(ByteBuffer outBuf, MLLPContext context) throws HL7Exception, IOException {

        if (this.state < READ_COMPLETE) {
            return 0;
        }

        if (this.state == READ_COMPLETE) {

            if ((context.isAutoAck() || context.isApplicationAck()) && !context.isNackMode()) {
                responseBytes = context.getHl7Message().generateACK().encode().getBytes(charsetDecoder.charset());
                context.setApplicationAck(false);
            } else {
                responseBytes = context.getHl7Message().encode().getBytes(charsetDecoder.charset());
            }

            this.state = WRITE_HEADER;
        }

        if (this.state >= WRITE_HEADER) {
            return fillBuffer(outBuf, responseBytes);
        }

        return 0;
    }
 
Example #16
Source File: HL7Writer.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Fills PID segment
 * 
 * @param pid
 * @param patient
 * @throws DataTypeException
 * @throws HL7Exception
 */
protected void fillPID(final ca.uhn.hl7v2.model.v231.segment.PID pid, final HL7Patient patient)
	throws DataTypeException, HL7Exception{
	String sex = ""; //$NON-NLS-1$
	if (patient.isMale() != null) {
		sex = "M"; //$NON-NLS-1$
		if (!patient.isMale().booleanValue()) {
			sex = "F"; //$NON-NLS-1$
		}
	}
	pid.getPid1_SetIDPID().setValue("1"); //$NON-NLS-1$
	pid.getPid2_PatientID().getID().setValue(patient.getPatCode());
	pid.getPid3_PatientIdentifierList(0).getID().setValue(patient.getPatCode());
	pid.getPid4_AlternatePatientIDPID(0).getID().setValue(patient.getPatCode());
	addKontaktToXPN(pid.getPid5_PatientName(0), patient);
	pid.getPid16_MaritalStatus().getCe1_Identifier().setValue(""); //$NON-NLS-1$
	pid.getPid7_DateTimeOfBirth().getTs1_TimeOfAnEvent()
		.setValue(HL7Helper.dateToString(patient.getBirthdate()));
	
	pid.getPid8_Sex().setValue(sex);
	pid.getPid9_PatientAlias(0).getXpn1_FamilyLastName().getFn1_FamilyName().setValue(""); //$NON-NLS-1$
	pid.getPid10_Race(0).getCe1_Identifier().setValue(""); //$NON-NLS-1$
	addAddressToXAD(pid.getPid11_PatientAddress(0), patient);
	pid.getPid12_CountyCode().setValue(""); //$NON-NLS-1$
	addPhone1ToXTN(pid.getPid13_PhoneNumberHome(0), patient);
}
 
Example #17
Source File: SampleApp.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Message processMessage(Message theIn) throws ApplicationException, HL7Exception {

    String encodedMessage = new PipeParser().encode(theIn);
    System.out.println("Received message:\n" + encodedMessage + "\n\n");

    // Now we need to generate a message to return. This will generally be an ACK message.
    Segment msh = (Segment) theIn.get("MSH");
    Message retVal;
    try {
        // This method takes in the MSH segment of an incoming message, and generates an
        // appropriate ACK
        retVal = DefaultApplication.makeACK(msh);
    } catch (IOException e) {
        throw new HL7Exception(e);
    }

    return retVal;
}
 
Example #18
Source File: HL7ReaderV26.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public String getSender() throws ElexisException{
	String sender;
	try {
		MSH msh = (MSH) message.get("MSH");
		sender = msh.getMsh4_SendingFacility().getNamespaceID().getValue();
		if (sender == null) {
			sender = msh.getMsh3_SendingApplication().getNamespaceID().getValue();
			if (sender == null) {
				sender = "";
			}
		}
	} catch (HL7Exception e) {
		throw new ElexisException(e.getMessage(), e);
	}
	return sender;
}
 
Example #19
Source File: HL7ReaderV26.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private OrcMessage extractOrc(ORC orc) throws HL7Exception{
	if (orc != null) {
		OrcMessage orcMessage = new OrcMessage();
		XCN[] ops = orc.getOrderingProvider();
		for (XCN op : ops) {
			FN fn = op.getFamilyName();
			ST familyName = null;
			if (fn != null) {
				familyName = fn.getSurname();
				if (familyName == null) {
					familyName = fn.getOwnSurname();
				}
			}
			addNameValuesToOrcMessage(op.getGivenName(), familyName, orcMessage);
		}
		return orcMessage;
	}
	return null;
}
 
Example #20
Source File: HL7ReaderV251.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ObservationMessage readObservation(HL7PatientResolver patientResolver,
	boolean createIfNotFound) throws ElexisException{
	observation = null;
	
	try {
		this.patientResolver = patientResolver;
		if (message.getName().contains("OUL_R22")) {
			readObservationOulR22(createIfNotFound);
		} else {
			readObservationOruR01(createIfNotFound);
		}
	} catch (HL7Exception | ParseException e) {
		throw new ElexisException(e.getMessage(), e);
	}
	
	return observation;
}
 
Example #21
Source File: HapiSegment.java    From nifi with Apache License 2.0 6 votes vote down vote up
public HapiSegment(final Segment segment) throws HL7Exception {
    this.segment = segment;

    final List<HL7Field> fieldList = new ArrayList<>();
    for (int i = 1; i <= segment.numFields(); i++) {
        final Type[] types = segment.getField(i);

        if (types == null || types.length == 0) {
            fieldList.add(new EmptyField());
            continue;
        }

        for (final Type type : types) {
            fieldList.add(new HapiField(type));
        }
    }

    this.fields = Collections.unmodifiableList(fieldList);
}
 
Example #22
Source File: TestHL7Query.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings({"unchecked", "rawtypes"})
public void testSelectField() throws HL7Exception, IOException {
    final HL7Query query = HL7Query.compile("SELECT PID.5");
    final HL7Message msg = hypoglycemia;
    final QueryResult result = query.evaluate(msg);
    assertTrue(result.isMatch());
    final List<String> labels = result.getLabels();
    assertEquals(1, labels.size());
    assertEquals(1, result.getHitCount());

    final Object names = result.nextHit().getValue("PID.5");
    assertTrue(names instanceof List);
    final List<Object> nameList = (List) names;
    assertEquals(1, nameList.size());
    final HL7Field nameField = (HL7Field) nameList.get(0);
    assertEquals("SMITH^JOHN", nameField.getValue());
}
 
Example #23
Source File: TestHL7Query.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testIsNull() throws HL7Exception, IOException {
    HL7Query hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.999 IS NULL");
    QueryResult result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia")));
    assertTrue(result.isMatch());

    hl7Query = HL7Query.compile("DECLARE result AS REQUIRED OBX SELECT MESSAGE WHERE result.1 IS NULL");
    result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia")));
    assertFalse(result.isMatch());

    hl7Query = HL7Query.compile("SELECT MESSAGE WHERE ZZZ IS NULL");
    result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia")));
    assertTrue(result.isMatch());

    hl7Query = HL7Query.compile("SELECT MESSAGE WHERE OBX IS NULL");
    result = hl7Query.evaluate(createMessage(new File("src/test/resources/hypoglycemia")));
    assertFalse(result.isMatch());
}
 
Example #24
Source File: PixFeedHandler.java    From openxds with Apache License 2.0 5 votes vote down vote up
/**
 * Validates the incoming Message in this order:
 * 
 * <ul>
 * <li> Validate Receiving Facility and Receiving Application</li>
 * <li> Validate Domain </li>
 * <li> Validate patient Id <li>		 
 * <li> Validate merge patient Id if applicable<li> 
 * </ul>
 * 
    * @param reply the reply message to be populated if any validation is failed
 * @param hl7Header the message header of the incoming message
 * @param patientId the id of the patient to be validated
 * @param mrgPatientId the id of the patient to be merged
 * @param isPixCreate Whether this validation is for PIX patient creation
 * @return <code>true</code> if the message is correct; <code>false</code>otherwise.
 * @throws HL7Exception if something is wrong with HL7 message 
 * @throws ApplicationException if something is wrong with the application
 */
private boolean validateMessage(ACK reply, HL7Header hl7Header, PatientIdentifier patientId, PatientIdentifier mrgPatientId, boolean isPixCreate) 
throws HL7Exception, ApplicationException {
	Identifier serverApplication = getServerApplication();
	Identifier serverFacility = getServerFacility();
	Identifier receivingApplication = hl7Header.getReceivingApplication();
	Identifier receivingFacility = hl7Header.getReceivingFacility();
	String incomingMessageId = hl7Header.getMessageControlId();
	//1. validate receiving facility and receiving application
	boolean isValidFacilityApplication = validateReceivingFacilityApplication(reply, 
			receivingApplication, receivingFacility, 
			serverApplication, serverFacility, incomingMessageId);
	if (!isValidFacilityApplication) return false;		
	
	//2.validate the domain
	boolean isValidDomain = validateDomain(reply, patientId, incomingMessageId);
	if (!isValidDomain) return false;
	
	//3. validate ID itself 
	if (!isPixCreate) { 
		//Do not valid patient id for PIX patient creation
		boolean isValidPid = validatePatientId(reply, patientId, hl7Header.toMessageHeader(), false, incomingMessageId);
		if (!isValidPid) return false;
	}
	
	//4. validate mrgPatientId
	if (mrgPatientId != null) {
		boolean isValidMrgPid = validatePatientId(reply, mrgPatientId, hl7Header.toMessageHeader(), true, incomingMessageId);
		if (!isValidMrgPid) return false;
	}
	
	//Finally, it must be true when it reaches here
	return true;
}
 
Example #25
Source File: PixFeedHandler.java    From openxds with Apache License 2.0 5 votes vote down vote up
/**
 * Validates a patient identifier domain, namely, assigning authority.
 * 
 * @param reply the reply message to be populated if the validation fails
 * @param patientId the patient id
 * @param incomingMessageId the incoming message id
 * @return <code>true</code> if the patient domain is validated successfully;
 *         otherwise <code>false</code>.
 * @throws HL7Exception if something is wrong with HL7 message 
 */
private boolean validateDomain(ACK reply, PatientIdentifier patientId, String incomingMessageId) 
throws HL7Exception {
	Identifier domain = patientId.getAssigningAuthority();
	boolean domainOk = AssigningAuthorityUtil.validateDomain(
			domain, connection);
	if (!domainOk) {
		HL7v231.populateMSA(reply.getMSA(), "AE", incomingMessageId);
		//segmentId=PID, sequence=1, fieldPosition=3, fieldRepetition=1,componentNubmer=4
		HL7v231.populateERR(reply.getERR(), "PID", "1", "3", "1", "4",
				"204", "Unknown Key Identifier");
		return false;
	}
	return true;
}
 
Example #26
Source File: PixFeedHandler.java    From openxds with Apache License 2.0 5 votes vote down vote up
/**
    * Validates the receiving facility and receiving application of an incoming message.
 * 
    * @param reply the reply message to be populated if any validation is failed
 * @param receivingApplication the receiving application of the incoming message
 * @param receivingFacility the receiving facility of the incoming message
 * @param expectedApplication the expected receiving application
 * @param expectedFacility the expected receiving facility
 * @param incomingMessageId the incoming message
 * @return <code>true</code> if validation is passed;
 *         otherwise <code>false</code>.
 * @throws HL7Exception if something is wrong with HL7 message 
 * @throws ApplicationException if something is wrong with the application
 */
private boolean validateReceivingFacilityApplication(ACK reply, Identifier receivingApplication,
		Identifier receivingFacility, Identifier expectedApplication, Identifier expectedFacility,
		String incomingMessageId) 
	    throws HL7Exception, ApplicationException
{
	//In case of tests, don't validate receiving application and facility,
	//It is not easy to switch to different receiving applications and facilities
	boolean  isTest = Boolean.parseBoolean(connection.getProperty("test"));
	if (isTest) return true;

	//We first need to validate ReceivingApplication and ReceivingFacility.
	//Currently we are not validating SendingApplication and SendingFacility
	if (!receivingApplication.equals(expectedApplication)) {
		HL7v231.populateMSA(reply.getMSA(), "AE", incomingMessageId);
		//segmentId=MSH, sequence=1, fieldPosition=5, fieldRepetition=1, componentNubmer=1
		HL7v231.populateERR(reply.getERR(), "MSH", "1", "5", "1", "1",
				null, "Unknown Receiving Application");
		return false;
	}
	if (!receivingFacility.equals(expectedFacility)) {
		HL7v231.populateMSA(reply.getMSA(), "AE", incomingMessageId);
		//segmentId=MSH, sequence=1, fieldPosition=6, fieldRepetition=1, componentNubmer=1
		HL7v231.populateERR(reply.getERR(), "MSH", "1", "6", "1", "1",
				null, "Unknown Receiving Facility");
		return false;
	}
	
	return true;
}
 
Example #27
Source File: HL7v231ToBaseConvertor.java    From openxds with Apache License 2.0 5 votes vote down vote up
/**
* Get the mother's PersonName from the PID segment
*
* @return the {@link PersonName} of the monther's maiden name
*/
  public PersonName getMotherMaidenName() throws HL7Exception {
  	PersonName mName=new PersonName();
mName.setLastName(pid.getMotherSMaidenName(0).getFamilyLastName().getFamilyName().getValue());
mName.setSecondName(pid.getMotherSMaidenName(0).getMiddleInitialOrName().getValue());
mName.setFirstName(pid.getMotherSMaidenName(0).getGivenName().getValue());
mName.setPrefix(pid.getMotherSMaidenName(0).getPrefixEgDR().getValue());
mName.setSuffix(pid.getMotherSMaidenName(0).getSuffixEgJRorIII().getValue());
mName.setDegree(pid.getMotherSMaidenName(0).getDegreeEgMD().getValue());
mName.setNameTypeCode(pid.getMotherSMaidenName(0).getNameTypeCode().getValue());
mName.setNameRepresentationCode(pid.getMotherSMaidenName(0).getNameRepresentationCode().getValue());
return mName;
  }
 
Example #28
Source File: HL7v231ToBaseConvertor.java    From openxds with Apache License 2.0 5 votes vote down vote up
/**
* Gets the PersonName from the PID segment
*
* @return the {@link PersonName} of the patient
*/
  public PersonName getPatientName() throws HL7Exception {
  	PersonName pName=new PersonName();

  	pName.setSuffix(pid.getPatientName(0).getSuffixEgJRorIII().getValue()); //patient name suffix
  	pName.setSecondName(pid.getPatientName(0).getMiddleInitialOrName().getValue()); //patient middle name
  	pName.setLastName(pid.getPatientName(0).getFamilyLastName().getFamilyName().getValue()); //patient last name
  	pName.setFirstName(pid.getPatientName(0).getGivenName().getValue()); //patient name first
  	pName.setPrefix(pid.getPatientName(0).getPrefixEgDR().getValue());
  	pName.setNameTypeCode(pid.getPatientName(0).getNameTypeCode().getValue());
  	pName.setNameRepresentationCode(pid.getPatientName(0).getNameRepresentationCode().getValue());
  	pName.setDegree(pid.getPatientName(0).getDegreeEgMD().getValue());

  	return pName;
  }
 
Example #29
Source File: HL7Writer.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Fills PID segment
 * 
 * @param pid
 * @param patient
 * @throws DataTypeException
 * @throws HL7Exception
 */
protected void fillPID(final ca.uhn.hl7v2.model.v26.segment.PID pid, final HL7Patient patient)
	throws DataTypeException,
	HL7Exception{
	String sex = ""; //$NON-NLS-1$
	if (patient.isMale() != null) {
		sex = "M"; //$NON-NLS-1$
		if (!patient.isMale().booleanValue()) {
			sex = "F"; //$NON-NLS-1$
		}
	}
	pid.getPid1_SetIDPID().setValue("1"); //$NON-NLS-1$
	pid.getPid2_PatientID().getIDNumber().setValue(patient.getPatCode());
	pid.getPid3_PatientIdentifierList(0).getIDNumber().setValue(patient.getPatCode());
	pid.getPid4_AlternatePatientIDPID(0).getIDNumber().setValue(patient.getPatCode());
	addKontaktToXPN(pid.getPid5_PatientName(0), patient);
	pid.getPid16_MaritalStatus().getCwe1_Identifier().setValue(""); //$NON-NLS-1$
	pid.getPid7_DateTimeOfBirth().setValue(HL7Helper.dateToString(patient.getBirthdate()));
	
	pid.getPid8_AdministrativeSex().setValue(sex);
	pid.getPid9_PatientAlias(0).getXpn1_FamilyName().getFn1_Surname().setValue(""); //$NON-NLS-1$
	pid.getPid10_Race(0).getCwe1_Identifier().setValue(""); //$NON-NLS-1$
	addAddressToXAD(pid.getPid11_PatientAddress(0), patient);
	pid.getPid12_CountyCode().setValue(""); //$NON-NLS-1$
	addPhone1ToXTN(pid.getPid13_PhoneNumberHome(0), patient);
	addPhone2ToXTN(pid.getPid14_PhoneNumberBusiness(0), patient);
}
 
Example #30
Source File: PixFeedHandler.java    From openxds with Apache License 2.0 5 votes vote down vote up
/**
	 * Converts a PIX Feed Patient message to a {@link Patient} object.
	 * 
	 * @param msgIn the incoming PIX Feed message
	 * @return a {@link Patient} object
	 * @throws ApplicationException if something is wrong with the application
	 */
	private Patient getPatient(Message msgIn) throws ApplicationException,HL7Exception {
		HL7v231ToBaseConvertor convertor = null;
		if (msgIn.getVersion().equals("2.3.1")) {
			convertor = new HL7v231ToBaseConvertor(msgIn, connection);
		} else {
			throw new ApplicationException("Unexpected HL7 version");
		}
		Patient patientDesc = new Patient();
		patientDesc.setPatientIds(convertor.getPatientIds());
		patientDesc.setPatientName(convertor.getPatientName());
		patientDesc.setMonthersMaidenName(convertor.getMotherMaidenName());
		patientDesc.setBirthDateTime(convertor.getBirthDate());
		patientDesc.setAdministrativeSex(convertor.getSexType());
		patientDesc.setPatientAlias(convertor.getPatientAliasName());
		patientDesc.setRace(convertor.getRace());
		patientDesc.setPrimaryLanguage(convertor.getPrimaryLanguage());
		patientDesc.setMaritalStatus(convertor.getMartialStatus());
		patientDesc.setReligion(convertor.getReligion());
		patientDesc.setPatientAccountNumber(convertor.getpatientAccountNumber());
		patientDesc.setSsn(convertor.getSsn());
		patientDesc.setDriversLicense(convertor.getDriversLicense());
		patientDesc.setMonthersId(convertor.getMonthersId());
		patientDesc.setEthnicGroup(convertor.getEthnicGroup());
		patientDesc.setBirthPlace(convertor.getBirthPlace());
		patientDesc.setBirthOrder(convertor.getBirthOrder());
		patientDesc.setCitizenship(convertor.getCitizenShip());
		patientDesc.setDeathDate(convertor.getDeathDate());		
//TODO: patientDesc.setDeathIndicator(convertor.getDeathIndicator());
		patientDesc.setPhoneNumbers(convertor.getPhoneList());
		patientDesc.setAddresses(convertor.getAddressList());
		patientDesc.setVisits(convertor.getVisitList());
		return patientDesc;
	}