public String parseHL7Payload()

in src/com/amazonaws/lab/HL7DataHandler.java [133:190]


	public String parseHL7Payload(String HL7input) {
		String json = null;
		try {
			/*
			 * A Parser is used to convert between string representations of messages and
			 * instances of HAPI's "Message" object. In this case, we are using a
			 * "GenericParser", which is able to handle both XML and ER7 (pipe & hat)
			 * encodings.
			 */
			Parser p = hapiContext.getGenericParser();
			Message hapiMsg;
			// The parse method performs the actual parsing
			hapiMsg = p.parse(HL7input);

			MDM_T02 mdmMsg = (MDM_T02) hapiMsg;
			// MSH msh = mdmMsg.getMSH();
			PID patId = mdmMsg.getPID();
			String activityDateTime = (mdmMsg.getTXA().getActivityDateTime() != null
					? mdmMsg.getTXA().getActivityDateTime().getTimeOfAnEvent().getValueAsDate().toString()
					: null);
			mdmMsg.getTXA().getActivityDateTime().getTimeOfAnEvent().getValueAsDate();
			ArrayList<String> notes = new ArrayList<>();

			List<OBX> obxList = mdmMsg.getOBXAll();
			for (OBX obx : obxList) {
				Varies[] dataList = obx.getObservationValue();
				// log.debug("The observation value :"+obx.getObservationValue() + "-- "+data);
				for (Varies data : dataList) {
					log.debug("The observation value :" + data.getData());
					notes.add(data.getData().toString());
				}
			}

			PatientInfo patInfo = new PatientInfo();
			patInfo.setLastName(patId.getPatientName()[0].getFamilyName().getValue());
			patInfo.setFirstName(patId.getPatientName()[0].getGivenName().getValue());
			patInfo.setMiddleInitial(patId.getPatientName()[0].getMiddleInitialOrName().getValue());
			patInfo.setDateOfBirth(patId.getDateOfBirth().getTs1_TimeOfAnEvent().getValue());
			patInfo.setActivityDateTime(activityDateTime);
			patInfo.setAddressCity(patId.getPatientAddress(0).getCity().getValue());
			patInfo.setGender(patId.getSex().getValue());
			patInfo.setMRN(patId.getPid3_PatientIDInternalID(0).getID().getValue());

			log.debug("The patient city : " + patId.getPatientAddress(0).getCity().getValue());
			log.debug("The patient gender : " + patId.getSex().getValue());
			log.debug("The MRN is : "+patId.getPid3_PatientIDInternalID(0).getID().getValue());

			// NotesData notesData = new NotesData();
			// notesData.setKey("Notes");
			// notesData.setNotes(notes);
			patInfo.setNotes(notes);
			json = new Gson().toJson(patInfo);

		} catch (HL7Exception exp) {
			log.error("Unable to parse message " + exp.getMessage());
		}
		return json;
	}