Java Code Examples for net.sf.json.JSONObject#accumulate()

The following examples show how to use net.sf.json.JSONObject#accumulate() . 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: JSONUtil.java    From Criteria2Query with Apache License 2.0 6 votes vote down vote up
public static JSONObject anyConditionforInitialEvent(){
	JSONObject anycondition=new JSONObject();
	JSONArray criteriaList=new JSONArray();
	JSONObject conditionOccurrence=new JSONObject();
	JSONObject jnull=new JSONObject();
	conditionOccurrence.accumulate("ConditionOccurrence", jnull);
	criteriaList.add(conditionOccurrence);
	anycondition.accumulate("CriteriaList", criteriaList);
	JSONObject observationWindow=new JSONObject();
	observationWindow.accumulate("PriorDays", 0);
	observationWindow.accumulate("PostDays", 0);
	anycondition.accumulate("ObservationWindow", observationWindow);
	JSONObject primaryCriteriaLimit=new JSONObject();
	primaryCriteriaLimit.accumulate("Type", "First");
	anycondition.accumulate("PrimaryCriteriaLimit", primaryCriteriaLimit);
	return anycondition;
}
 
Example 2
Source File: ATLASUtil.java    From Criteria2Query with Apache License 2.0 6 votes vote down vote up
public static List<Concept> searchConceptByNameAndDomain(String entity, String domainid)
			throws UnsupportedEncodingException, IOException, ClientProtocolException {
		JSONObject queryjson = new JSONObject();
		queryjson.accumulate("QUERY", entity);
		queryjson.accumulate("DOMAIN_ID", "['" + domainid + "']");
		queryjson.accumulate("STANDARD_CONCEPT","S");//only standard concept
//		queryjson.accumulate("VOCABULARY_ID", "['SNOMED']");
		System.out.println("queryjson:" + queryjson);
		String vocabularyresult = getConcept(queryjson);
		System.out.println("vocabularyresult  length=" + vocabularyresult.length());
		Gson gson = new Gson();
		JsonArray ja = new JsonParser().parse(vocabularyresult).getAsJsonArray();
		if (ja.size() == 0) {
			System.out.println("size=" + ja.size());
			return null;
		}
		List<Concept> list = gson.fromJson(ja, new TypeToken<List<Concept>>() {
		}.getType());
		return list;
	}
 
Example 3
Source File: ConceptMapping.java    From Criteria2Query with Apache License 2.0 6 votes vote down vote up
public String extendByUMLS(String term){
	Integer conceptId=0;
	JSONObject jo=new JSONObject();
	jo.accumulate("term", term);
	String result=HttpUtil.doPost(umlsurl, jo.toString());
	JSONObject rejo=JSONObject.fromObject(result);
	if(rejo!=null){
		String aftermap=rejo.getString("term");
	if(aftermap.equals("unmapped")==false){
		return aftermap;
	}else{
		return term;
	}
	}else{
		return term;
	}
	
}
 
Example 4
Source File: ConceptMapping.java    From Criteria2Query with Apache License 2.0 6 votes vote down vote up
public String[] getCloestConceptByUsagi(String term,String domain){
	String[] res=new String[3];
	JSONObject jo=new JSONObject();
	jo.accumulate("term", StringUtil.cleanASCII(term));
	jo.accumulate("domain", domain);
	String result=HttpUtil.doPost(usagi, jo.toString());
	System.out.println(jo.toString());
	System.out.println("result="+result);
	JSONObject bestconcept=JSONObject.fromObject(result);
	System.out.println("matchScore="+bestconcept.getDouble("matchScore"));
	String matchs=String.format("%.2f", bestconcept.getDouble("matchScore")*100);
	
	JSONObject concept_jo=bestconcept.getJSONObject("concept");
	Integer cId=concept_jo.getInt("conceptId");
	String conceptname=concept_jo.getString("conceptName");
	
	res[0]=String.valueOf(cId);
	res[1]=conceptname;
	res[2]=matchs;
	return res;
}
 
Example 5
Source File: ConceptMapping.java    From Criteria2Query with Apache License 2.0 6 votes vote down vote up
public Integer createConceptByConceptName(String word,String domain) throws UnsupportedEncodingException, ClientProtocolException, IOException{
	Integer conceptId=0;
	//the most related one
	System.out.println("word=" + word);
	System.out.println("domain=" + domain);
	
	List<Concept> econceptlist = ATLASUtil.searchConceptByNameAndDomain(word, domain);
	String expression=generateConceptSetByConcepts(econceptlist);
	long t1=System.currentTimeMillis();  
	JSONObject jo=new JSONObject();
	jo.accumulate("name", word+"_created_by_"+GlobalSetting.c2qversion);
	jo.accumulate("id", 23333);
	String result=HttpUtil.doPost(conceptseturl, jo.toString());
	JSONObject rejo=JSONObject.fromObject(result);
	HttpUtil.doPut(conceptseturl+rejo.getString("id")+"/items",expression);		
	return Integer.valueOf(rejo.getString("id"));
}
 
Example 6
Source File: JSONUtil.java    From Criteria2Query with Apache License 2.0 6 votes vote down vote up
/**
 * inclusion :flag = true ; exclusion : flag=false;
 * neg
 * temporal 1 has history of 
 * 
 * */

public static JSONObject setCriteriaUnit(int index,boolean neg,boolean flag,String type,int temporal){
	JSONObject criteriaunit = new JSONObject();
	JSONObject occurrence = new JSONObject();
	JSONObject startwindow = new JSONObject();
	JSONObject criteria = new JSONObject();
	criteria = setCriteria(type, index);
	if (neg^flag == true) {
		occurrence = setOccurrence(2, 1);	
	}else {
		occurrence = setOccurrence(0, 0);
	}
	startwindow = setTemporalWindow(temporal);
	criteriaunit.accumulate("Criteria", criteria);
	criteriaunit.accumulate("StartWindow", startwindow);
	criteriaunit.accumulate("Occurrence", occurrence);
	return criteriaunit;
}
 
Example 7
Source File: OHDSIApis.java    From Criteria2Query with Apache License 2.0 6 votes vote down vote up
public static List<Concept> searchConceptByNameAndDomain(String entity, String domainid)
		throws UnsupportedEncodingException, IOException, ClientProtocolException {
	JSONObject queryjson = new JSONObject();
	queryjson.accumulate("QUERY", entity);
	queryjson.accumulate("DOMAIN_ID", "['" + domainid + "']");
	queryjson.accumulate("STANDARD_CONCEPT", "S");// only standard concept
	System.out.println("queryjson:" + queryjson);
	String vocabularyresult = getConcept(queryjson);
	System.out.println("vocabularyresult  length=" + vocabularyresult.length());
	Gson gson = new Gson();
	JsonArray ja = new JsonParser().parse(vocabularyresult).getAsJsonArray();
	if (ja.size() == 0) {
		return null;
	}
	List<Concept> list = gson.fromJson(ja, new TypeToken<List<Concept>>() {
	}.getType());
	return list;
}
 
Example 8
Source File: JSONUtil.java    From Criteria2Query with Apache License 2.0 6 votes vote down vote up
/**
 * index 1: has history of 
 * index 2: has 
 * */
public static JSONObject setTemporalWindow(int index) {
	JSONObject window = new JSONObject();
	JSONObject start = new JSONObject();
	JSONObject end = new JSONObject();
	if(index ==1){
		start.accumulate("Coeff", -1);
		// start.accumulate("Count", 0);
		end.accumulate("Coeff", "1");
		// end.accumulate("Count", 0);
		//end.accumulate("Days", "0");	
	}
	window.accumulate("Start", start);
	window.accumulate("End", end);
	return window;
}
 
Example 9
Source File: ATLASUtil.java    From Criteria2Query with Apache License 2.0 6 votes vote down vote up
public static List<Concept> searchConceptByName(String entity)
		throws UnsupportedEncodingException, IOException, ClientProtocolException {
	JSONObject queryjson = new JSONObject();
	queryjson.accumulate("QUERY", entity);
	System.out.println("queryjson:" + queryjson);
	String vocabularyresult = getConcept(queryjson);
	System.out.println("vocabularyresult  length=" + vocabularyresult.length());
	Gson gson = new Gson();
	JsonArray ja = new JsonParser().parse(vocabularyresult).getAsJsonArray();
	if (ja.size() == 0) {
		System.out.println("size=" + ja.size());
		return null;
	}
	List<Concept> list = gson.fromJson(ja, new TypeToken<List<Concept>>() {
	}.getType());
	return list;
}
 
Example 10
Source File: ReconTool.java    From Criteria2Query with Apache License 2.0 5 votes vote down vote up
public List<String> resolve(String text){
	JSONObject jo=new JSONObject();
	jo.accumulate("entity", text);
	String result=HttpUtil.doPost(reconurl, jo.toString());
	JSONArray array = JSONArray.fromObject(result);
	List<String> list=new ArrayList<String>();
	for(Object obj :array){
		list.add((String) obj);
	}
	return list;
}
 
Example 11
Source File: QueryFormulateServiceImpl.java    From Criteria2Query with Apache License 2.0 5 votes vote down vote up
public JSONArray defaultInitialEvent() {
	JSONArray jacriterialist = new JSONArray();
	JSONObject jo = new JSONObject();
	// JSONObject jnull=new JSONObject();
	JSONObject jvo = new JSONObject();
	jvo.accumulate("VisitSourceConcept", null);
	jvo.accumulate("First", null);
	jo.accumulate("VisitOccurrence", jvo);

	jacriterialist.add(jo);
	return jacriterialist;
}
 
Example 12
Source File: QueryFormulateServiceImpl.java    From Criteria2Query with Apache License 2.0 5 votes vote down vote up
public JSONObject formualteCohortQuery(Document doc) {
	List<Integer> conceptsetIds=extractConceptsetByDoc(doc);
	CdmCohort omopcohort=translateByDoc(doc);
	JSONObject cohort = new JSONObject();
	//Merge All criteria to one criteria 
	CdmCriteria initial_criteria=new CdmCriteria();
	List<CdmCriterion> clist=new ArrayList<CdmCriterion>();
	for(CdmCriteria c:omopcohort.getInitial_event()){
		if(c!=null){
			clist.addAll(c.getClist());
		}
	}
	StringBuffer initialeventtext=new StringBuffer();
	for(CdmCriteria cdmc:omopcohort.getInitial_event()){
		initialeventtext.append(cdmc.getText());
	}
	initial_criteria.setText(initialeventtext.toString());
	initial_criteria.setInitialevent(true);
	initial_criteria.setIncluded(true);
	initial_criteria.setClist(clist);
	initial_criteria.setPriorDays(omopcohort.getDaysBefore());
	initial_criteria.setPostDays(omopcohort.getDaysAfter());
	initial_criteria.setLimitTo(omopcohort.getLimitTo());
	initial_criteria.setOccurenceStart(omopcohort.getOccurrenceStart());
	cohort.accumulate("ConceptSets", formulateConceptSet(conceptsetIds));
	// initial events
	cohort.accumulate("PrimaryCriteria", formulatePrimaryCriteria(initial_criteria));
	if(initial_criteria.getText()!=null &&initial_criteria.getText().length() >0){
		System.out.println("=>additional criteria");
		cohort.accumulate("AdditionalCriteria", formulateOneCdmCriteria(initial_criteria));
	}
	cohort.accumulate("QualifiedLimit", formulateQualifiedLimit());
	cohort.accumulate("ExpressionLimit", formulateExpressionLimit());
	// other criteria
	cohort.accumulate("InclusionRules", formulateInclusionRules(omopcohort.getAdditional_criteria()));
	// set null for CensoringCriteria and CollapseSettings
	cohort.accumulate("CensoringCriteria", formulateCensoringCriteria());
	cohort.accumulate("CollapseSettings", formulateCollapseSettings());
	return cohort;
}
 
Example 13
Source File: QueryFormulateServiceImpl.java    From Criteria2Query with Apache License 2.0 5 votes vote down vote up
public JSONObject translateTemporal(TemporalConstraint temporal) {
	JSONObject temporalwindow = new JSONObject();
	JSONObject start = new JSONObject();
	JSONObject end = new JSONObject();
	if (temporal == null) {
		start.accumulate("Coeff", -1);
		end.accumulate("Coeff", 1);
		temporalwindow.accumulate("Start", start);
		temporalwindow.accumulate("End", end);
	} else {
		if (temporal.getStart_days() != null && temporal.getEnd_days() != null) {
			start.accumulate("Days", temporal.getStart_days());
			start.accumulate("Coeff", temporal.getStart_offset());
			temporalwindow.accumulate("Start", start);
			end.accumulate("Days", temporal.getEnd_days());
			end.accumulate("Coeff", temporal.getEnd_offset());
			temporalwindow.accumulate("End", end);
		} else if (temporal.getStart_days() == null && temporal.getEnd_days() != null) {
			start.accumulate("Coeff", -1);
			temporalwindow.accumulate("Start", start);
			end.accumulate("Days", temporal.getEnd_days());
			end.accumulate("Coeff", temporal.getEnd_offset());
			temporalwindow.accumulate("End", end);
		} else if (temporal.getStart_days() != null && temporal.getEnd_days() == null) {
			start.accumulate("Days", temporal.getStart_days());
			start.accumulate("Coeff", temporal.getStart_offset());
			end.accumulate("Coeff", 1);
			temporalwindow.accumulate("Start", start);
			temporalwindow.accumulate("End", end);
		}
	}
	return temporalwindow;
}
 
Example 14
Source File: OHDSIApis.java    From Criteria2Query with Apache License 2.0 5 votes vote down vote up
public static Integer createConceptSetByConceptName(String conceptsetname,String word,String domain) throws UnsupportedEncodingException, ClientProtocolException, IOException{			
	//the most related one		
	List<Concept> econceptlist = searchConceptByNameAndDomain(word, domain);				
	String expression=generateConceptSetByConcepts(econceptlist);
	JSONObject jo=new JSONObject();
	jo.accumulate("name", conceptsetname);
	jo.accumulate("id", 1);
	String result=HttpUtil.doPost(conceptseturl, jo.toString());
	JSONObject rejo=JSONObject.fromObject(result);
	HttpUtil.doPut(conceptseturl+rejo.getString("id")+"/items",expression);		
	return Integer.valueOf(rejo.getString("id"));
}
 
Example 15
Source File: JSONUtil.java    From Criteria2Query with Apache License 2.0 5 votes vote down vote up
public static JSONObject setCriteria(String type, int conceptsetid) {
	JSONObject criteriatype = new JSONObject();
	JSONObject codesetId = new JSONObject();
	codesetId.accumulate("CodesetId", conceptsetid);
	if (type.equals("Condition")) {
		criteriatype.accumulate("ConditionOccurrence", codesetId);
	} else if (type.equals("Drug")) {
		criteriatype.accumulate("DrugExposure", codesetId);
	} else if (type.equals("Observation")) {
		criteriatype.accumulate("Observation", codesetId);
	} else if (type.equals("Procedure_Device")) {
		criteriatype.accumulate("DeviceExposure", codesetId);
	}
	return criteriatype;
}
 
Example 16
Source File: ATLASUtil.java    From Criteria2Query with Apache License 2.0 5 votes vote down vote up
public static JSONObject querybyconceptSetid(int conceptid){
	JSONObject jot=new JSONObject();
   	String re2=HttpUtil.doGet("http://api.ohdsi.org/WebAPI/conceptset/"+conceptid);
   	JSONObject jore2=JSONObject.fromObject(re2);
   	jot.accumulateAll(jore2);
   	String re3=HttpUtil.doGet("http://api.ohdsi.org/WebAPI/conceptset/"+conceptid+"/expression");
   	
   	JSONObject expression=JSONObject.fromObject(re3);
   	jot.accumulate("expression",expression);
   	
   	return jot;
}
 
Example 17
Source File: QueryFormulateServiceImpl.java    From Criteria2Query with Apache License 2.0 4 votes vote down vote up
public JSONObject formulateQualifiedLimit() {
	JSONObject qualifiedlimit = new JSONObject();
	qualifiedlimit.accumulate("Type", "First");
	return qualifiedlimit;
}
 
Example 18
Source File: QueryFormulateServiceImpl.java    From Criteria2Query with Apache License 2.0 4 votes vote down vote up
public JSONObject formulateExpressionLimit() {
	JSONObject expressionlimit = new JSONObject();
	expressionlimit.accumulate("Type", "First");
	return expressionlimit;
}
 
Example 19
Source File: JSONUtil.java    From Criteria2Query with Apache License 2.0 4 votes vote down vote up
public static JSONObject setOccurrence(int type, int count) {
	JSONObject jsonob = new JSONObject();
	jsonob.accumulate("Type", type);
	jsonob.accumulate("Count", count);
	return jsonob;
}
 
Example 20
Source File: QueryFormulateServiceImpl.java    From Criteria2Query with Apache License 2.0 4 votes vote down vote up
public JSONArray formulateDemographic(List<CdmCriterion> criteria_list){
	JSONArray demographicarr = new JSONArray();
	for (CdmCriterion cdmcriterion : criteria_list) {
		if(cdmcriterion.getDomain().equals("Demographic")){
			//age
			if(cdmcriterion.getOrginialtext().toLowerCase().contains("age")){
				JSONObject jo=new JSONObject();
				if(cdmcriterion.getAttributes()!=null){
					String agerangestr=cdmcriterion.getAttributes().get("age_range");
					System.out.println("==???age???==");
					List<Double> m=NumericConvert.recognizeNumbersAdvanced(agerangestr);
					if(m!=null){
						System.out.println("m_size="+m.size());
						System.out.println("number="+m.get(0));
						System.err.println("Age str="+agerangestr);
						agerangestr=agerangestr.toLowerCase();
						if(m.size()==1 && 
								(
										(agerangestr.indexOf(">")!=-1 &&agerangestr.indexOf("<")==-1&&agerangestr.indexOf("=")==-1)
										||
										(agerangestr.indexOf("older") !=-1&&agerangestr.indexOf("younger") ==-1)
								)
							)
						{
							System.out.println("gt-==?");
							jo.accumulate("Value",m.get(0));
							jo.accumulate("Op", "gt");
						}else if(m.size()==1 && 
									(
											(agerangestr.indexOf("<")!=-1 &&agerangestr.indexOf(">")==-1&&agerangestr.indexOf("=")==-1)
											||
											(agerangestr.indexOf("younger") !=-1&&agerangestr.indexOf("older") ==-1)
									)
								)
						{
							jo.accumulate("Value",m.get(0));
							jo.accumulate("Op", "lt");
						}else if(m.size()==2){
							jo.accumulate("Value",m.get(0));
							jo.accumulate("Extent",m.get(1));
							jo.accumulate("Op", "bt");
						}else if(m.size()==1 && ((agerangestr.indexOf("≤")!=-1 )||(agerangestr.indexOf("at most")!=-1)||((agerangestr.indexOf("<")!=-1)&&(agerangestr.indexOf("=")!=-1)))){
							jo.accumulate("Value",m.get(0));
							jo.accumulate("Op", "lte");
						}else if(m.size()==1 && ((agerangestr.indexOf("≥")!=-1 )||(agerangestr.indexOf("at least")!=-1)||((agerangestr.indexOf(">")!=-1)&&(agerangestr.indexOf("=")!=-1)))){
							jo.accumulate("Value",m.get(0));
							jo.accumulate("Op", "gte");
						}
					}
				}
				JSONObject agejson=new JSONObject();
				agejson.accumulate("Age", jo);
				demographicarr.add(agejson);
			}
			System.out.println("gender===>");
			if(Arrays.asList(GenderGroup.maletriggers).contains(cdmcriterion.getOrginialtext().trim().toLowerCase())||Arrays.asList(GenderGroup.femaletriggers).contains(cdmcriterion.getOrginialtext().trim().toLowerCase())){
				JSONArray genderarr=new JSONArray();
				JSONObject genderjson=new JSONObject();
				if(Arrays.asList(GenderGroup.maletriggers).contains(cdmcriterion.getOrginialtext().trim().toLowerCase())){
					genderarr.add(setMale());
				}
				if(Arrays.asList(GenderGroup.femaletriggers).contains(cdmcriterion.getOrginialtext().trim().toLowerCase())){
					genderarr.add(setFeMale());
				}
				genderjson.accumulate("Gender", genderarr);
				demographicarr.add(genderjson);
			}
		}
	}
	return demographicarr;
}