public String processRequest()

in clns-eTarget/src/main/java/org/digitalecmt/etarget/GetMeetingOutcome.java [80:186]


	public String processRequest() {
		if (!super.isUserPermittedEndpoint(userID, "GetMeetingOutcome")) {
			// Stop the request if user doesn't have permission for this API or web
			// component
			Map<String,String> response = new HashMap<>();
	    	response.put("success", "false");
	    	response.put("error", "User not permitted to access: GetMeetingOutcome");
	    	return new Gson().toJson(response);
		} else {
			boolean isAdmin=super.isAdmin(userID); 
			List<Integer> needPrinting=null;
			
			MeetingOutcomeDAO mo = this.getContext().getBean(MeetingOutcomeDAO.class);
			mo.setAdditionalSources(addSources);
			try {
				List<MeetingOutcome> lmos = mo.getMeetingOutcomesByPersonID(personIDint);
				if(isAdmin) {
					needPrinting=mo.getMeetingOutcomesForPrinting(personIDint);
				}
				List<Map<String, Object>> meetings = new ArrayList<>();
				for (MeetingOutcome meetingoutcome : lmos) {
					Map<String, Object> meeting = new HashMap<>();
					// Reformat the date
					DateFormat dfmeetingDate = new SimpleDateFormat("dd/MM/yyyy");
					Date meetingDate = meetingoutcome.getMeeting_date();
					if(meetingDate!=null) {
						meetingDateFormatted = dfmeetingDate.format(meetingDate);
					} else {
						meetingDateFormatted = "";
					}

					DateFormat timestamp = new SimpleDateFormat("dd/MM/yyyy HH:mm");
					timestamp.setTimeZone(TimeZone.getTimeZone("Europe/London"));
					if (meetingoutcome.getLast_updated() != null) {
						lastUpdatedFormated = timestamp.format(meetingoutcome.getLast_updated());
					}

					meeting.put("meeting_id", meetingoutcome.getMo_id());
					meeting.put("meetingDate", meetingDateFormatted);
					meeting.put("updatedBy", meetingoutcome.getUpdated_by());
					meeting.put("lastUpdated", lastUpdatedFormated);
					if(meetingoutcome.getLast_printed()!=null) {
						meeting.put("lastPrinted", timestamp.format(meetingoutcome.getLast_printed()));
					} else {
						meeting.put("lastPrinted", "");
					}
					meeting.put("outcome", meetingoutcome.getOutcome());
					meeting.put("notes", meetingoutcome.getNotes());
					meeting.put("ctDNA", meetingoutcome.getCtDNA());
					meeting.put("tumourNGS", meetingoutcome.getTumourNGS());
					meeting.put("fmBlood", meetingoutcome.getFMBlood());
					meeting.put("fmTumour", meetingoutcome.getFMTumour());
					meeting.put("genericGenomic", meetingoutcome.getGenericGenomic());
					meeting.put("summary", meetingoutcome.getSummary());
					if(needPrinting!=null) {
						meeting.put("needPrinting", needPrinting.contains(meetingoutcome.getMo_id()));
					}
					if(meetingoutcome.getCtDNA().size()>0) {
						Map<String,Object> firstblood=meetingoutcome.getCtDNA().get(0);
						if(firstblood.get("specimenDate")!=null) {
							meeting.put("ctDNASampleDate",firstblood.get("specimenDate")); 
						} else {
							meeting.put("ctDNASampleDate",firstblood.get("")); 
						}
					} else {
						Calendar sampleDate=mo.getSampleDateBlood(meetingoutcome.getMeeting_date(), meetingoutcome.getPerson_id());
						if(sampleDate!=null) {
							meeting.put("ctDNASampleDate", dfmeetingDate.format(sampleDate.getTime()));
						} else {
							meeting.put("ctDNASampleDate","");
						}
							
					}
					if(meetingoutcome.getTumourNGS().size()>0) {
						Map<String,Object> firsttumour=meetingoutcome.getTumourNGS().get(0);
						if(firsttumour.get("specimenDate")!=null) {
							meeting.put("tumourSampleDate",firsttumour.get("specimenDate"));
						} else if(firsttumour.get("SpecimentDate")!=null){ 
							//old spelling mistake lives on in the database :-(
							meeting.put("tumourSampleDate",firsttumour.get("SpecimentDate"));
						} else {
							meeting.put("tumourSampeleDate","");
						}
					} else {
						Calendar sampleDate=mo.getSampleDateTumour(meetingoutcome.getMeeting_date(), meetingoutcome.getPerson_id());
						if(sampleDate!=null) {
							meeting.put("tumourSampleDate",dfmeetingDate.format(sampleDate.getTime()));
						} else {
							meeting.put("tumourSampleDate","");
						}
					}
					meetings.add(meeting);
				}
				String json = new Gson().toJson(meetings);
				return json;

			} catch (Exception e) {
				log.log(Level.SEVERE, e.getMessage(), e);
				e.printStackTrace();
				Map<String,String> response = new HashMap<>();
		    	response.put("success", "false");
		    	response.put("error", "Failed to get meeting outcome.");
		    	return new Gson().toJson(response);
			}
		}

	}