<commit_before>package org.ecemgroup.sharevitalsigns.library;

import android.content.Intent;
import android.app.Activity;
import android.os.Bundle;

/** ShareVitalSigns Class
 * Library class which provides functions for sending vital signs and other medical data between android applications.
 * The library can be used by a vital sign provider (e.g. that records this from a sensor) or a vital sign receiver (that displays or process this vital sign further).
 * Check  {@link ShareVitalSignsDemoReceiver} for an example of a receiver 
 * Check  {@link ShareVitalSignsDemoSender} for an example of a provider
 * Check {@link RRate} for an example of a provider that records respiratory rate with tapping on the screen.
 * 
 * the library essentially uses {@link Intents}. More on intents check the Android developer website:
 * http://developer.android.com/guide/components/intents-filters.html
 * 
 * VitalSigns currently supported:
 * HR: 		Heart Rate					beats/min
 * RR: 		Respiratory Rate			breaths/min	
 * TEMP: 	Temperature					deg Celcius
 * SPO2:	Oxygen saturation			%
 * BP_SYS:	Blood pressure (Sys )		mmHg
 * BP_DIA:  Blood pressure (Sys )		mmHg
 * 
 * Combinations:
 * BP:		Blood pressure (Sys & Dia) 	mmHg & mmHg
 * PO:		Pulse oximetry (HR & SPO2)	beats/min & % 
 * 
 *
 * @author <NAME> (<EMAIL>)
 * @version 0.1.0
 * 
 */
public class ShareVitalSigns  {

	private static final String libraryclassname = "ShareVitalSigns";
	public static final String libraryaddress = "org.ecemgroup.sharevitalsigns";
	
	// Definitions for vital signs. can be used for requests 
	public static final int MEASURE_HR = 1;
	public static final int MEASURE_RR = 2;
	public static final int MEASURE_SPO2 = 4;
	public static final int MEASURE_TEMP = 8;
	public static final int MEASURE_BPSYS = 16;
	public static final int MEASURE_BPDIA = 32;
	public static final int MEASURE_BP = MEASURE_BPSYS | MEASURE_BPDIA;
	public static final int MEASURE_PO = MEASURE_HR | MEASURE_SPO2;

	//Definitions for vital sign  names
	public static final String N_HR = "HR";
	public static final String N_RR = "RR";
	public static final String N_SPO2= "SPO2";
	public static final String N_TEMP = "TEMP";
	public static final String N_BP = "BP";
	public static final String N_PO = "PO";
	public static final String N_BPSYS = "BPSYS";
	public static final String N_BPDIA= "BPDIA";
	
	//Definitions for vital sign extras field names
	public static final String V_HR = libraryclassname+"Value_HR";
	public static final String V_RR = libraryclassname+"Value_RR";
	public static final String V_SPO2= libraryclassname+"Value_SPO2";
	public static final String V_TEMP = libraryclassname+"Value_TEMP";
	public static final String V_BP = libraryclassname+"Value_BP";
	public static final String V_PO = libraryclassname+"Value_PO";
	public static final String V_BPSYS = libraryclassname+"Value_BPSYS";
	public static final String V_BPDIA= libraryclassname+"Value_BPDIA";
	public static final String C_HR = libraryclassname+"Confidence_HR";
	public static final String C_RR = libraryclassname+"Confidence_RR";
	public static final String C_SPO2= libraryclassname+"Confidence_SPO2";
	public static final String C_TEMP = libraryclassname+"Confidence_TEMP";
	public static final String C_BP = libraryclassname+"Confidence_BP";
	public static final String C_BPSYS = libraryclassname+"Confidence_BPSYS";
	public static final String C_BPDIA= libraryclassname+"Confidence_BPDIA";
	public static final String C_PO= libraryclassname+"Confidence_PO";

	public static final String[] V_NAMELIST={V_HR,V_RR,V_SPO2,V_TEMP,V_BPSYS,V_BPDIA};
	public static final String[] C_NAMELIST={C_HR,C_RR,C_SPO2,C_TEMP,C_BPSYS,C_BPDIA};
	public static final String[] N_NAMELIST={N_HR,N_RR,N_SPO2,N_TEMP,N_BPSYS,N_BPDIA};


	//Vital Signs are stored here for Receivers and Providers
	public  ShareVitalSignsData svsData=new ShareVitalSignsData();
	
	//Saveguard Intent here  
	public Intent ShareVitalSignsIntent;
	
	
	// 
	private int VitalSignsProvided;
	

	//init method for a provider
	public ShareVitalSigns (int provider) {
		VitalSignsProvided=provider;
	}

	//init method for receiver (no provider is known)
	public ShareVitalSigns () {

	}

	//%%%%%%%%%%%%%%%%RECEIVER StUFF%%%%%%%%%%%%%%%%%%%%%%%%

	public ShareVitalSignsResultReceiver VitalSignReceiver;
	private int ShareVitalSignsRequested; //value that is being send



	/**
	 * Interface for SVS results
	 * 
	 * 
	 */
	public interface ShareVitalSignsResultReceiver {


		public void onResult(float[] vital, int[] confidence);



	}


	/**
	 * This receiver method opens VitalSign Intent and requests a vital sign measurement externally using the Intent.
	 * 
	 * 
	 * @param resultReceiver
	 * @param measureCode int of Vital Sign Code
	 * 
	 * @return Intent   intent to be launched within activity
	 */
	public  Intent measureVitalSigns(ShareVitalSignsResultReceiver resultreceiver,int measureCode) {

		VitalSignReceiver = resultreceiver; //
		ShareVitalSignsRequested = measureCode; //
		
		//TODO open more specific intent targeted to vital sign requested with measure code
		Intent launchMeasure = new Intent(libraryaddress+".MEASURE");
		launchMeasure.putExtra(libraryclassname+"Measure", measureCode);
	
		return launchMeasure;

	}


	/**
	 * This receiver method reads the values returned from Intent and compares if requested and returned codes match. 
	 * It further checks if the requested vital signs have been measured and if stores them in the object 
	 * 
	 * 
	 * @param resultReceiver
	 * @param measureCode int of Vital Sign Code
	 * 
	 * @return boolean
	 */
	//@Override
	public boolean getResults(int requestCode, int resultCode, Intent data) {

		if (requestCode == ShareVitalSignsRequested) { //requestCode matches code send
			if (resultCode == Activity.RESULT_OK) { //a measurement was performed<commit_msg>SHAREVITALSIGNS: Opens more specific intent targeted to vital sign requested with measure code<commit_after>package org.ecemgroup.sharevitalsigns.library;

import android.content.Intent;
import android.app.Activity;
import android.os.Bundle;

/** ShareVitalSigns Class
 * Library class which provides functions for sending vital signs and other medical data between android applications.
 * The library can be used by a vital sign provider (e.g. that records this from a sensor) or a vital sign receiver (that displays or process this vital sign further).
 * Check  {@link ShareVitalSignsDemoReceiver} for an example of a receiver 
 * Check  {@link ShareVitalSignsDemoSender} for an example of a provider
 * Check {@link RRate} for an example of a provider that records respiratory rate with tapping on the screen.
 * 
 * the library essentially uses {@link Intents}. More on intents check the Android developer website:
 * http://developer.android.com/guide/components/intents-filters.html
 * 
 * VitalSigns currently supported:
 * HR: 		Heart Rate					beats/min
 * RR: 		Respiratory Rate			breaths/min	
 * TEMP: 	Temperature					deg Celcius
 * SPO2:	Oxygen saturation			%
 * BP_SYS:	Blood pressure (Sys )		mmHg
 * BP_DIA:  Blood pressure (Sys )		mmHg
 * 
 * Combinations:
 * BP:		Blood pressure (Sys & Dia) 	mmHg & mmHg
 * PO:		Pulse oximetry (HR & SPO2)	beats/min & % 
 * 
 *
 * @author <NAME> (<EMAIL>)
 * @version 0.1.0
 * 
 */
public class ShareVitalSigns  {

	private static final String libraryclassname = "ShareVitalSigns";
	public static final String libraryaddress = "org.ecemgroup.sharevitalsigns";
	
	// Definitions for vital signs. can be used for requests 
	public static final int MEASURE_HR = 1;
	public static final int MEASURE_RR = 2;
	public static final int MEASURE_SPO2 = 4;
	public static final int MEASURE_TEMP = 8;
	public static final int MEASURE_BPSYS = 16;
	public static final int MEASURE_BPDIA = 32;
	public static final int MEASURE_BP = MEASURE_BPSYS | MEASURE_BPDIA;
	public static final int MEASURE_PO = MEASURE_HR | MEASURE_SPO2;

	//Definitions for vital sign  names
	public static final String N_HR = "HR";
	public static final String N_RR = "RR";
	public static final String N_SPO2= "SPO2";
	public static final String N_TEMP = "TEMP";
	public static final String N_BP = "BP";
	public static final String N_PO = "PO";
	public static final String N_BPSYS = "BPSYS";
	public static final String N_BPDIA= "BPDIA";
	
	//Definitions for vital sign extras field names
	public static final String V_HR = libraryclassname+"Value_HR";
	public static final String V_RR = libraryclassname+"Value_RR";
	public static final String V_SPO2= libraryclassname+"Value_SPO2";
	public static final String V_TEMP = libraryclassname+"Value_TEMP";
	public static final String V_BP = libraryclassname+"Value_BP";
	public static final String V_PO = libraryclassname+"Value_PO";
	public static final String V_BPSYS = libraryclassname+"Value_BPSYS";
	public static final String V_BPDIA= libraryclassname+"Value_BPDIA";
	public static final String C_HR = libraryclassname+"Confidence_HR";
	public static final String C_RR = libraryclassname+"Confidence_RR";
	public static final String C_SPO2= libraryclassname+"Confidence_SPO2";
	public static final String C_TEMP = libraryclassname+"Confidence_TEMP";
	public static final String C_BP = libraryclassname+"Confidence_BP";
	public static final String C_BPSYS = libraryclassname+"Confidence_BPSYS";
	public static final String C_BPDIA= libraryclassname+"Confidence_BPDIA";
	public static final String C_PO= libraryclassname+"Confidence_PO";

	public static final String[] V_NAMELIST={V_HR,V_RR,V_SPO2,V_TEMP,V_BPSYS,V_BPDIA};
	public static final String[] C_NAMELIST={C_HR,C_RR,C_SPO2,C_TEMP,C_BPSYS,C_BPDIA};
	public static final String[] N_NAMELIST={N_HR,N_RR,N_SPO2,N_TEMP,N_BPSYS,N_BPDIA};


	//Vital Signs are stored here for Receivers and Providers
	public  ShareVitalSignsData svsData=new ShareVitalSignsData();
	
	//Saveguard Intent here  
	public Intent ShareVitalSignsIntent;
	
	
	// 
	private int VitalSignsProvided;
	

	//init method for a provider
	public ShareVitalSigns (int provider) {
		VitalSignsProvided=provider;
	}

	//init method for receiver (no provider is known)
	public ShareVitalSigns () {

	}

	//%%%%%%%%%%%%%%%%RECEIVER StUFF%%%%%%%%%%%%%%%%%%%%%%%%

	public ShareVitalSignsResultReceiver VitalSignReceiver;
	private int ShareVitalSignsRequested; //value that is being send



	/**
	 * Interface for SVS results
	 * 
	 * 
	 */
	public interface ShareVitalSignsResultReceiver {


		public void onResult(float[] vital, int[] confidence);



	}


	/**
	 * This receiver method opens VitalSign Intent and requests a vital sign measurement externally using the Intent.
	 * 
	 * 
	 * @param resultReceiver
	 * @param measureCode int of Vital Sign Code
	 * 
	 * @return Intent   intent to be launched within activity
	 */
	public  Intent measureVitalSigns(ShareVitalSignsResultReceiver resultreceiver,int measureCode) {

		VitalSignReceiver = resultreceiver; //
		ShareVitalSignsRequested = measureCode; //

		String intentAddress = libraryaddress+".MEASURE."+N_NAMELIST[Math.getExponent((double)measureCode)];
		Intent launchMeasure = new Intent(intentAddress);
		launchMeasure.putExtra(libraryclassname+"Measure", measureCode);
	
		return launchMeasure;

	}


	/**
	 * This receiver method reads the values returned from Intent and compares if requested and returned codes match. 
	 * It further checks if the requested vital signs have been measured and if stores them in the object 
	 * 
	 * 
	 * @param resultReceiver
	 * @param measureCode int of Vital Sign Code
	 * 
	 * @return boolean
	 */
	//@Override
	public boolean getResults(int requestCode, int resultCode, Intent data) {

		if (requestCode == ShareVitalSignsRequested) { //requestCode matches code send
			if (resultCode == Activity.RESULT_OK) { //a measurement was performed
{'fraction_non_alphanumeric': 0.08198673243748937, 'fraction_numerical': 0.004082326926348018, 'mean_word_length': 4.67519305019305, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1091923', 'n_tokens_mistral': 3805, 'n_tokens_neox': 3526, 'n_words': 1199}