<commit_before>
package org.raxa.alertmessage;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.log4j.Logger;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

/**
 * 
 * This class does the following:
 * Input:raw message String or Template message String.
 * <p>1)Parse the Alert Message.
 * <p>2)Then it templatize the message and store the string as JSON Format with the Json schema mapped from ContentForamat.Class
 * <p>4)mode-1 will play using TTS and mode-2 will play using Audio Files provided the location of  audio file is in preferLanguage.properties and 
 * is stored as tagName. eg in hindi.properties we have header1=/home/atul/Documents/voice/greetings/hindi/header1.mp3
 * <p>5)if mode not found default is 1
 * <p>6)Assuming mode of dose and medicine name to be 1.Can be changed.
 * 
 * <p>CAUTION:
 * 		1)Any type of punctuation like ',' '.' is highly discouraged as it will make the tts to stop executig that line
 * 		2)Medicine name should be send as lowercase otherwise the TTS will pronounce each Letter of the word.
 *  </pp>    
 *<p>
 *Though it is used by the server every midnight to update alert,it needs to be changed if there is any change in message format
 *<p>
 *Method:parseMessage(String message) takes the message and templatise it.Any changes in message format should be reflected there.
 *<p>
 *Assuming only tablet and volume exist.More data needs to be provided to know what kind og medicine it is.Should be updated.
 *Right now considering all medicine to be tablet.If a medicine is volume isTablet should be set to false
 *
 *
 * @author atul
 *
 */
public class MessageTemplate implements MessageInterface {
		
		Properties prop = new Properties();
		private Logger logger = Logger.getLogger(this.getClass());
		private List<String> Tmessage;
		private String medicineDose;
		private String medicine;			//should be in lowerCase
		private String tabletOrVolume;  // either "tablet" or volume;
		private String name;
		public final String PatientNameFieldRepresentation="name";
		public final String MedicineFieldRepresentation="medicine";
		public final String MedicineTypeFieldRepresentation="type";
		public final String ModeFieldRepresentation="mode";
		public final String Header1Representation="header1";
		public final String Header2TypeFieldRepresentation="header2";
		public final String Footer1FieldRepresentation="footer1";
		public final String EndingFieldRepresentation="ending";
		public final String DoseFieldRepresentation="dose";
		
		private boolean isTablet;
		
		
		/**
		 *<p> Right now the text for both sms and voice are same but if we want to change it this function also gets alertType
		 * informationSo it can be changed accordingly.
		 * 
		 * 
		 * <p>
		 * 	 * For now Assuming Template of Raw Message is "Take x of y" as the template of Raxa Alert is not Ready
		 * Even Assuming that y is always a doze as the template as of now does not provide that information.
		 * <h2>Tags:</h2>
		 *<p><h3>"header1"</h3>:Greetings(eg.Welcome to Raxa.Good Morning)
		 * <p><h3>"name"</h3>:Name of the Patient
		 * <p><h3>"header2"</h3>:Introductory Line (eg.Today You have to take)
		 * <p><h3>"dose"</h3>:doze of Medicine(Solid)
		 * <p><h3>"footer1"</h3>:Language Specific (eg:(in Hindi) lena hai)
		 * <p><h3>"ending"</h3>:Good-Bye Message (eg.We hope you will get well soon.GoodBye)
		 * 
		 * <p>Depending on the alertType the message can be varied.Right now its same for both.
		 * @param message
		 * @param preferLanguage
		 * @param name
		 * @param pid
		 * @return
		 */
		
		public List<String> templatize(String message,String preferLanguage,String name,String pid,int alertType){
			this.name=name;
			Properties prop = new Properties();
			parseMessage(message);
			String propertyFile="english.properties";
			Tmessage=new ArrayList<String>();
			String header1,header2,footer1,ending;
			int header1mode,header2mode,footer1mode,endingmode,tabletOrVolumemode;
			try{
				logger.info("Trying to get mode in which the words should be spoken from "+propertyFile);
				prop.load(this.getClass().getClassLoader().getResourceAsStream(propertyFile));
				header1mode=Integer.parseInt(prop.getProperty("header1mode",String.valueOf(TTS_MODE)));  //If headerMode not provided it will use TTS
				header2mode=Integer.parseInt(prop.getProperty("header2mode",String.valueOf(TTS_MODE)));
				footer1mode=Integer.parseInt(prop.getProperty("footer1mode",String.valueOf(TTS_MODE)));
				endingmode=Integer.parseInt(prop.getProperty("endingmode",String.valueOf(TTS_MODE)));
				tabletOrVolumemode=Integer.parseInt(prop.getProperty("tabletOrVolume",String.valueOf(TTS_MODE)));
			}
			catch(Exception ex3){
				logger.error("Unable to set mode,making all mode to 1 for patient ID  "+pid);
				header1mode=header2mode=footer1mode=endingmode=tabletOrVolumemode=TTS_MODE;<commit_msg>Update MessageTemplate.java<commit_after>package org.raxa.alertmessage;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import org.apache.log4j.Logger;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

/**
 * 
 * This class does the following:
 * Input:raw message String or Template message String.
 * <p>1)Parse the Alert Message.
 * <p>2)Then it templatize the message and store the string as JSON Format with the Json schema mapped from ContentForamat.Class
 * <p>4)mode-1 will play using TTS and mode-2 will play using Audio Files provided the location of  audio file is in preferLanguage.properties and 
 * is stored as tagName. eg in hindi.properties we have header1=/home/atul/Documents/voice/greetings/hindi/header1.mp3
 * <p>5)if mode not found default is 1
 * <p>6)Assuming mode of dose and medicine name to be 1.Can be changed.
 * 
 * <p>CAUTION:
 * 		1)Any type of punctuation like ',' '.' is highly discouraged as it will make the tts to stop executig that line
 * 		2)Medicine name should be send as lowercase otherwise the TTS will pronounce each Letter of the word.
 *  </pp>    
 *<p>
 *Though it is used by the server every midnight to update alert,it needs to be changed if there is any change in message format
 *<p>
 *Method:parseMessage(String message) takes the message and templatise it.Any changes in message format should be reflected there.
 *<p>
 *Assuming only tablet and volume exist.More data needs to be provided to know what kind og medicine it is.Should be updated.
 *Right now considering all medicine to be tablet.If a medicine is volume isTablet should be set to false
 *
 *
 * @author atul
 *
 */
public class MessageTemplate implements MessageInterface {
		
		Properties prop = new Properties();
		private Logger logger = Logger.getLogger(this.getClass());
		private List<String> Tmessage;
		private String medicineDose;
		private String medicine;			//should be in lowerCase
		private String tabletOrVolume;  // either "tablet" or volume;
		private String name;
		public final String PatientNameFieldRepresentation="name";
		public final String MedicineFieldRepresentation="medicine";
		public final String MedicineTypeFieldRepresentation="type";
		public final String ModeFieldRepresentation="mode";
		public final String Header1Representation="header1";
		public final String Header2TypeFieldRepresentation="header2";
		public final String Footer1FieldRepresentation="footer1";
		public final String EndingFieldRepresentation="ending";
		public final String DoseFieldRepresentation="dose";
		
		private boolean isTablet;
		
		
		/**
		 *<p> Right now the text for both sms and voice are same but if we want to change it this function also gets alertType
		 * informationSo it can be changed accordingly.
		 * 
		 * 
		 * <p>
		 * 	 * For now Assuming Template of Raw Message is "Take x of y" as the template of Raxa Alert is not Ready
		 * Even Assuming that y is always a doze as the template as of now does not provide that information.
		 * <h2>Tags:</h2>
		 *<p><h3>"header1"</h3>:Greetings(eg.Welcome to Raxa.Good Morning)
		 * <p><h3>"name"</h3>:Name of the Patient
		 * <p><h3>"header2"</h3>:Introductory Line (eg.Today You have to take)
		 * <p><h3>"dose"</h3>:doze of Medicine(Solid)
		 * <p><h3>"footer1"</h3>:Language Specific (eg:(in Hindi) lena hai)
		 * <p><h3>"ending"</h3>:Good-Bye Message (eg.We hope you will get well soon.GoodBye)
		 * 
		 * <p>Depending on the alertType the message can be varied.Right now its same for both.
		 * @param message
		 * @param preferLanguage
		 * @param name
		 * @param pid
		 * @return
		 */
		
		public List<String> templatize(String message,String preferLanguage,String name,String pid,int alertType){
			this.name=name;
			Properties prop = new Properties();
			parseMessage(message);
			String propertyFile="english.properties";
			Tmessage=new ArrayList<String>();
			String header1,header2,footer1,ending;
			int header1mode,header2mode,footer1mode,endingmode,tabletOrVolumemode;
			try{
				logger.info("Trying to get mode in which the words should be spoken from "+propertyFile);
				prop.load(this.getClass().getClassLoader().getResourceAsStream(propertyFile));
				header1mode=Integer.parseInt(prop.getProperty("header1mode",String.valueOf(TTS_MODE)));  //If headerMode not provided it will use TTS
				header2mode=Integer.parseInt(prop.getProperty("header2mode",String.valueOf(TTS_MODE)));
				footer1mode=Integer.parseInt(prop.getProperty("footer1mode",String.valueOf(TTS_MODE)));
				endingmode=Integer.parseInt(prop.getProperty("endingmode",String.valueOf(TTS_MODE)));
				tabletOrVolumemode=Integer.parseInt(prop.getProperty("type",String.valueOf(TTS_MODE)));
			}
			catch(Exception ex3){
				logger.error("Unable to set mode,making all mode to 1 for patient ID  "+pid);
				header1mode=header2mode=footer1mode=endingmode=tabletOrVolumemode=TTS_MODE;
{'fraction_non_alphanumeric': 0.09530983227879883, 'fraction_numerical': 0.011047504268353922, 'mean_word_length': 4.657954545454546, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4262088', 'n_tokens_mistral': 3159, 'n_tokens_neox': 2837, 'n_words': 985}