public Map handleRequest()

in src/com/amazonaws/lab/HL7DataHandler.java [55:131]


	public Map<String, String> handleRequest(Map<String, String> map, Context context) {
		// Get S3 object as string, then process it
		HL7input = getS3ObjectContentAsString(map.get("S3Bucket"), map.get("InputFile"));
		log.debug("HL7input: " + 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();
			//send in a format which can be used in the template
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
			sdf.setTimeZone(TimeZone.getTimeZone(timeZoneId));
			String activityDateTime = (mdmMsg.getTXA().getActivityDateTime() != null
					? sdf.format(mdmMsg.getTXA().getActivityDateTime().getTimeOfAnEvent().getValueAsDate())
					: 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());

			// NotesData notesData = new NotesData();
			// notesData.setKey("Notes");
			// notesData.setNotes(notes);
			patInfo.setNotes(notes);
			json = new Gson().toJson(patInfo);
			// log.debug("The data "+data.length);

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

		// Save the output in a "processing" folder in the S3 bucket
		log.debug("Output S3 path: " + map.get("S3Bucket") + "processing/unstructuredtext/" + map.get("FileName"));
		putS3ObjectContentAsString(map.get("S3Bucket"), "processing/unstructuredtext/" + map.get("FileName"),
				json.toString());

		// Create our output response back to the state machine
		Map<String, String> output = new HashMap<>();
		output.put("S3Bucket", map.get("S3Bucket"));
		output.put("FileName", map.get("FileName"));
		output.put("InputFile", map.get("InputFile"));
		output.put("DataType", map.get("DataType"));
		output.put("UnstructuredText", "processing/unstructuredtext/" + map.get("FileName"));

		return output;
	}