<commit_before>/**
 * A suite of methods to help process patient records from other matchmakers
 */
package org.broadinstitute.macarthurlab.beamr.matchmakers;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.broadinstitute.macarthurlab.beamr.entities.GenomicFeature;
import org.broadinstitute.macarthurlab.beamr.entities.Patient;
import org.broadinstitute.macarthurlab.beamr.entities.PhenotypeFeature;
import org.broadinstitute.macarthurlab.beamr.entities.Variant;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

/**
 * @author harindra
 *
 */
public class PatientRecordUtility {
	
	/**
	 * Default constructor does nothing
	 */
	public PatientRecordUtility(){}
	
	
	public boolean areAllRequiredFieldsPresent(String patientJsonString){
		boolean verdict=true;
		JSONParser parser = new JSONParser();
		try{
			JSONObject jsonObject = (JSONObject) parser.parse(patientJsonString);
			JSONObject patient = (JSONObject)jsonObject.get("patient");
		 
		String id = (String)patient.get("id");
		if (id == null){
			verdict=false;
		}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		
		return verdict;<commit_msg>Added in validation of input patient structure. Checking if id and contact details are entered. If they are not, a 400 Bad Request is sent back as defined in MME Spec<commit_after>/**
 * A suite of methods to help process patient records from other matchmakers
 */
package org.broadinstitute.macarthurlab.beamr.matchmakers;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.broadinstitute.macarthurlab.beamr.entities.GenomicFeature;
import org.broadinstitute.macarthurlab.beamr.entities.Patient;
import org.broadinstitute.macarthurlab.beamr.entities.PhenotypeFeature;
import org.broadinstitute.macarthurlab.beamr.entities.Variant;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

/**
 * @author harindra
 *
 */
public class PatientRecordUtility {
	
	/**
	 * Default constructor does nothing
	 */
	public PatientRecordUtility(){}
	
	
	public boolean areAllRequiredFieldsPresent(String patientJsonString){
		boolean verdict=true;
		JSONParser parser = new JSONParser();
		try{
			JSONObject jsonObject = (JSONObject) parser.parse(patientJsonString);
			JSONObject patient = (JSONObject)jsonObject.get("patient");
		 
			
		//Id
		if (patient.containsKey("id")){
			String id = (String)patient.get("id");
		}
		else{
			verdict=false;
		}
		
		//Contact
		if (patient.containsKey("contact")){
			Map<String,String> contactDets = new HashMap<String,String>();
			JSONObject  contact = (JSONObject)patient.get("contact");
			contactDets.put("name", (String)contact.get("name"));
			contactDets.put("institution", (String)contact.get("institution"));
			contactDets.put("href", (String)contact.get("href"));
			}
		else{
			verdict=false;
		}
		
		}
		catch(Exception e){
			System.out.println("ERROR:parsing input query patient data: " + e.toString());
			verdict=false;
		}

		return verdict;
{'fraction_non_alphanumeric': 0.11601866251944012, 'fraction_numerical': 0.0009331259720062209, 'mean_word_length': 4.826086956521739, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7254393', 'n_tokens_mistral': 1077, 'n_tokens_neox': 971, 'n_words': 214}