• Tidak ada hasil yang ditemukan

C. Administrator View

VI. Discussions 48

Telehealth Automatically Generated Recommendations (TAGR) is a module for au- tomatically classifying SMS and e-mail messages with their appropriate tags as re- quired by the National Telehealth Center for their National Telehealth Service Pro- gram (NTSP). For demonstration purposes, a minimal web-based interface was built around the TAGR module which simulates the real-world processes of the NTSP. The web-based component allows telehealth nurses to manage the messages in the system.

It also allows the TAGR module to be configured by administrators.

The inclusion of a rudimentary spam blocker frees the telehealth nurses of the burden of having to deal with unsolicited messages. This allows them to focus their time and effort on the verification of messages.

The TAGR module’s classifier trained on the base dataset yields an average pre- diction accuracy of 73% upon validation. The accuracy may be considered decent enough to allow messages to be sent by rural physicians without keywords. The ab- sence of keywords would not pose a problem for the telehealth nurses, as the TAGR module automatically assigns the appropriate tag. As a fallback measure, telehealth nurses are able to correct the assigned tag.

The TAGR module can also train on both new data and old but corrected data.

This opens the possibility of improving the accuracy of the classifier even if the module is deployed in a production environment.

The dataset used was provided by the National Telehealth Center and contains actual messages processed by the NTSP. They were given in two batches totaling 1733 messages. However, only a total of 1464 messages were used.

As seen in Table8, the dataset is imbalanced. The Internal Medicine class contains 481 messages while the Psychology class only has 8 messages. It is also noted that three classes: Internal Medicine, Pediatrics, and Family Medicine, have very similar occurring features in them, which can easily confuse the classifier.

Tag Batch 1 Batch 2 Total Used

Internal Medicine 312 169 481 312

Pediatrics 244 83 327 244

Obgyn 157 67 224 224

General Question 111 44 155 155

Surgery 48 40 88 88

Radiology 49 127 176 176

Dermatology 29 1 106 135 32

Medico Legal 24 8 32 32

Ophthalmology 19 22 41 41

Otorhinolaryngology 18 23 41 41

Neurology 14 2 16 16

Psychology 0 8 8 0

Family Medicine 9 0 9 0

Total 1034 699 1733 1464

Table 8: Data from National Telehealth Center

To reduce the imbalance, messages under Internal Medicine and Pediatrics from the second batch of data were not included in the dataset used by the classifier.

Messages under the Psychology and Family Medicine classes were also removed, as they had too few instances. However, the final dataset was still fairly imbalanced.

The nature of the dataset also lead to the scrapping of the planned use of Condi- tional Random Fields (CRF) as the machine learning method for the classifier in favor of Support Vector Machines. CRF would possibly be better for sequential data such as natural language text because of how it takes into account context and patterns.

For example, a word is likely to be of a certain class if it is preceded by words from another class.

The dataset however, did not reveal any distinct patterns for each individual class.

Rather, classes relied more on occurrences of words specific to that class than with the order in which they appear in. Here, the classifier may benefit on a dictionary of medical terms and their associated class. The CRF would have been more useful in separating the data into relevant and irrelevant chunks. A different classifier can then make a prediction using only the relevant chunks.

The classifier was built using the scikit-learn library. Specifically, the classifier is an instance of the LinearSVC object. The LinearSVC is an implementation of a support vector machine with a linear kernel. While TAGR lets the user specify n-grams and feature percentiles, the classifier itself has preset parameters.

These preset parameters were chosen after running a grid search on the classifier, and returned the best performance. The parameters of the LinearSVC are:

C = 1

l o s s = ’ s q u a r e d h i n g e ’ p e n a l t y = ’ l 2 ’

c l a s s w e i g h t = ’ b a l a n c e d ’

There was difficulty in integrating the classifier component with the web-based component. The classifier component was not designed to run as a live web service.

This posed a problem as TAGR configuration required a persistent instance of the classifier that can be accessed across multiple pages. This was solved by caching an instance in the server with no expiry.

VII. Conclusions

Telehealth Automatically Generated Recommendations (TAGR) is a module for auto- matically classifying SMS and e-mail messages with their appropriate tags as required by the National Telehealth Center for their National Telehealth Service Program (NTSP). To accomplish this, it utilizes natural language processing techniques such as tokenization,n-gram representation, and term frequency-inverse document frequency weighting, coupled with support vector machines, a machine learning method.

The module was developed with the ultimate goal of providing an automated tagging component running in real-time for the existing National Telehealth Service Program system. With its decent base accuracy, it can be considered for deployment into a production environment.

The author considers this a positive study in that it was able to achieve the ob- jectives. It also demonstrates the potential of utilizing natural language processing techniques and machine learning methods in more real-world applications, particu- larly in telehealth and other related fields.

VIII. Recommendations

The Telehealth Automatically Generated Recommendations (TAGR) module as it stands now, is tightly connected to the web-based interface that was built around it for demonstration purposes. This bars it from being called a true stand-alone module that can easily be plugged into systems. It is recommended to modify TAGR into an executable that accepts parameters so that it can be called anytime through scripts.

Another improvement is to configure TAGR as such that it can be run as a web service. Currently, an instance of TAGR is always created on demand. This can be costly performance-wise in the case that multiple TAGR instances are created at the same time.

While the TAGR classifier’s accuracy may be considered decent enough, there is still room for improvement. The following are some recommendations on improving accuracy:

1. Build a balanced dataset to train on.

2. Explore other machine learning methods such as Conditional Random Fields, which takes into account the context of sequential data.

3. Combine machine learning methods with rule-based methods to maximize ac- curacy.

4. Build a tagged corpora of medical terminologies that can add weight to certain classes.

5. Build a dedicated module for identifying textspeak and equating them with regular terms.

6. Set the module to always run a grid search to find the parameters that will yield the highest accuracy everytime it is trained.

IX. Bibliography

[1] “Doh profile.” http://www.doh.gov.ph/profile, Sep 2015.

[2] “Mission and vision.” http://www.doh.gov.ph/mission-vision, Sep 2015.

[3] W. H. Organizationet al.,The Philippines health system review. Manila, Philip- pines: World Health Organization, Western Pacific Region, 2011.

[4] D. o. H. P. World Health Organization, “Philippines health service delivery pro- file.” Web, 2012.

[5] J. Leonardia, H. Prytherch, K. Ronquillo, R. G. Nodora, and A. Ruppel, “Assess- ment of factors influencing retention in the philippine national rural physician deployment program,” BMC Health Services Research, vol. 12, no. 1, p. 411, 2012.

[6] C. A. T. Antonio, “Addressing the maldistribution of physicians: Policy options for the up college of medicine,” Master’s thesis, University of the Philippines College of Medicine, 2008.

[7] “About - national telehealth center.” https://telehealth.ph/about/, Sep 2015.

[8] “Program areas - national telehealth center.” https://telehealth.ph/about/

onehealth/, Sep 2015.

[9] “Infographic: How does telemedicine work in nthc?.”https://telehealth.ph/

2015/02/18/infographic-how-does-telemedicine-work-in-nthc, Feb 2015.

[10] Z. R. A. Lorraine Carlos Salazar, Shelah Lardizabal-Vallarino, Digital review of Asia Pacific 2007-2008. SAGE Publications, 2008.

[11] A. B. B. P. F. A. M. Alex Gavino, Pia Athena Tolentino, “Philippines: A telemedicine program utilizing short message service (sms) for remote village doctors,” Question 14-2/2: Mobile eHealth solutions for Developing Countries, pp. 94–98, 2010.

[12] R. V. G. Randy Joseph Fernandez, “Design of a ticketing system for health care using web2py.” Presentation, 2011.

[13] C. W. Nadkarni PM, Ohno-Machado L, “Natural language processing: an in- troduction,” Journal of the American Medical Informatics Association, vol. 18, no. 5, pp. 544–551, 2011.

[14] N. D. Tatyana Shcherbakova, Maria Vergelis, “Spam and phishing in the first quarter of 2015.” https://

securelist.com/analysis/quarterly-spam-reports/69932/

spam-and-phishing-in-the-first-quarter-of-2015/, May 2015.

[15] H. Shirani-Mehr, “Sms spam detection using machine learning approach,” tech.

rep., Stanford University, 2013.

[16] R. Wootton,Telehealth in the developing world. International Development Re- search Centre Royal Society of Medicine Press, 2009.

[17] J. Dzenowagis, “Bridging the digital divide: linking health and ict policy,” Tele- health in the developing world, 2009.

[18] F. Ngabo, J. Nguimfack, F. Nwaigwe, C. Mugeni, D. Muhoza, D. R. Wilson, J. Kalach, R. Gakuba, C. Karema, and A. Binagwaho, “Designing and imple- menting an innovative sms-based alert system (rapidsms-mch) to monitor preg- nancy and reduce maternal and child deaths in rwanda,” The Pan African Med- ical Journal, vol. 13, 2012.

[19] A. B. Marcelo, “Telemedicine in developing countries: Perspectives from the philippines,” Telehealth in the developing world, p. 27, 2009.

[20] S. A. Nisperos and Y. Urano, “Sms text messaging: A ubiquitous tool for cheaper medicine in the philippines,” inAdvanced Communication Technology (ICACT), 2011 13th International Conference on, pp. 1415–1419, IEEE, 2011.

[21] C. Tamban, I. T. Isip-Tan, and C. Jimeno, “Use of short message services (SMS) for the management of type 2 diabetes mellitus: A randomized controlled trial,”

Journal of the ASEAN Federation of Endocrine Societies, vol. 28, no. 2, pp. 143–

149, 2013.

[22] C. D´eglise, L. S. Suggs, and P. Odermatt, “Sms for disease control in devel- oping countries: a systematic review of mobile health applications,” Journal of Telemedicine and Telecare, vol. 18, no. 5, pp. 273–281, 2012.

[23] P. Melville, V. Chenthamarakshan, R. D. Lawrence, J. Powell, M. Mugisha, S. Sapra, R. Anandan, and S. Assefa, “Amplifying the voice of youth in africa via text analytics,” in Proceedings of the 19th ACM SIGKDD international con- ference on Knowledge discovery and data mining, pp. 1204–1212, ACM, 2013.

[24] M. S. Sorower, “A literature survey on algorithms for multi-label learning,” tech.

rep., Oregon State University, 2010.

[25] S. P. Stenner, K. B. Johnson, and J. C. Denny, “Paste: patient-centered sms text tagging in a medication management system,” Journal of the American Medical Informatics Association, vol. 19, no. 3, pp. 368–374, 2012.

[26] G. Tsoumakas, A. Dimou, E. Spyromitros, V. Mezaris, I. Kompatsiaris, and I. Vlahavas, “Correlation-based pruning of stacked binary relevance models for multi-label learning,” inProceedings of the 1st International Workshop on Learn- ing from Multi-Label Data, pp. 101–116, 2009.

[27] W. Bi and J. Kwok, “Efficient multi-label classification with many labels,” in Proceedings of the 30th International Conference on Machine Learning (ICML- 13), pp. 405–413, 2013.

[28] A. Alessandro, G. Corani, D. Mau´a, and S. Gabaglio, “An ensemble of bayesian networks for multilabel classification,” inProceedings of the Twenty-Third inter- national joint conference on Artificial Intelligence, pp. 1220–1225, AAAI Press, 2013.

[29] C. Clark, J. Aberdeen, M. Coarr, D. Tresner-Kirsch, B. Wellner, A. Yeh, and L. Hirschman, “Mitre system for clinical assertion status classification,” Journal of the American Medical Informatics Association, vol. 18, no. 5, pp. 563–567, 2011.

[30] S. N. Kim, D. Martinez, L. Cavedon, and L. Yencken, “Automatic classification of sentences to support evidence based medicine,” BMC bioinformatics, vol. 12, no. Suppl 2, p. S5, 2011.

[31] S. Gella and D. T. Long, “Automatic sentence classifier using sentence ordering features for event based medicine: Shared task system description,” in In Pro- ceedings of Australasian Language Technology Association Workshop, pp. 130–

133, 2012.

[32] S. Spat, B. Cadonna, I. Rakovac, C. Gutl, H. Leitner, G. Stark, P. Beck, et al.,

“Multi-label text classification of german language medical documents,” 2007.

[33] M. K. Dalal and M. A. Zaveri, “Automatic text classification: a technical re- view,”International Journal of Computer Applications, vol. 28, no. 2, pp. 37–40, 2011.

[34] A. K. Uysal and S. Gunal, “The impact of preprocessing on text classification,”

Information Processing and Management, 2014.

[35] Y.-T. Chen and M. C. Chen, “Using chi-square statistics to measure similarities for text categorization,” Expert Systems with Applications, 2011.

[36] P. Meesad, P. Boonrawd, and V. Nuipian, “A chi-square-test for word importance differentiation in text classification,” in Proceedings of International Conference on Information and Electronics Engineering, pp. 110–114, 2011.

[37] T. Ahmad, H. Akhtar, A. Chopra, and M. W. Akhtar, “Satire detection from web documents using machine learning methods,” in Soft Computing and Machine Intelligence (ISCMI), 2014 International Conference on, pp. 102–105, 2014.

[38] K. Lee, D. Palsetia, R. Narayanan, M. M. A. Patwary, A. Agrawal, and A. Choudhary, “Twitter trending topic classification,” in Data Mining Work- shops (ICDMW), 2011 IEEE 11th International Conference on, pp. 251–258, 2011.

[39] J. Huh, M. Yetisgen-Yildiz, and W. Pratt, “Text classification for assisting mod- erators in online health communities,” Journal of biomedical informatics, 2013.

[40] A. A. Argaw, A. Hulth, and B. B. Megyesi, “General-purpose text categoriza- tion applied to the medical domain,” tech. rep., Department of Computer and Systems Sciences, Stockholm University, 2007.

[41] S. Hassan, M. Rafi, and M. S. Shaikh, “Comparing svm and naive bayes classifiers for text categorization with wikitology as knowledge enrichment,” in Multitopic Conference (INMIC), 2011 IEEE 14th International, pp. 31–34, 2011.

[42] Z. Ju, J. Wang, and F. Zhu, “Named entity recognition from biomedical text using svm,” in Bioinformatics and Biomedical Engineering, (iCBBE) 2011 5th International Conference on, pp. 1–4, 2011.

[43] Z. Ju, M. Zhou, and F. Zhu, “Identifying biological terms from text by support vector machine,” in 2011 6th IEEE Conference on Industrial Electronics and Applications, pp. 455–458, 2011.

[44] R. L. Figueroa, D. A. Soto, and E. J. Pino, “Identifying and extracting patient smoking status information from clinical narrative texts in spanish,” in 2014 36th Annual International Conference of the IEEE Engineering in Medicine and Biology Society, pp. 2710–2713, 2014.

[45] A. B. Abacha and P. Zweigenbaum, “Identifying biological terms from text by support vector machine,” in Proceedings of BioNLP 2011 Workshop, pp. 56–64, 2011.

[46] “National telehealth center - history.” https://telehealth.ph/history, De- cember 2015.

[47] “National telehealth center - projects.” https://telehealth.ph/projects/, December 2015.

[48] A. T. Association, “What is telemedicine.”http://www.americantelemed.org/

about-telemedicine/what-is-telemedicine, December 2015.

[49] M. Mars, “Telemedicine and advances in urban and rural healthcare delivery in africa,” Progress in cardiovascular diseases, vol. 56, no. 3, pp. 326–335, 2013.

[50] “What are the available areas for deployment? what are the categories of these areas?.” http://www.doh.gov.ph/node/1098, Dec 2015.

[51] “Information: doctors to the barrios under study.” http://www.mb.com.ph/

information-doctors-to-the-barrios-under-study/, May 2014.

[52] T. M. Mitchell,Machine Learning. McGraw-Hill, Inc, 1997.

[53] S. Russell and P. Norvig, Artificial intelligence: a modern approach. Pearson, 1995.

[54] W. B. Cavnar, J. M. Trenkle, et al., “N-gram-based text categorization,” Ann Arbor MI, 1994.

[55] A. Rajaraman, Mining of Massive Datasets. Cambridge University Press, 2011.

[56] C. D. Manning, P. Raghavan, and H. Schutze, Introduction to Information Re- trieval. Cambridge University Press, 2008.

[57] V. Vryniotis, “Using feature selection methods

in text classification.” http://blog.datumbox.com/

using-feature-selection-methods-in-text-classification/, January 2014.

[58] S. R. Gunn et al., “Support vector machines for classification and regression,”

ISIS technical report, 1998.

[59] C.-W. Hsu, C.-C. Chang, C.-J. Lin, et al., “A practical guide to support vector classification,” 2003.

[60] M. D. Pierro, “web2py for scientific applications,” Computing in Science and Engineering, vol. 13, no. 2, pp. 64–69, 2011.

[61] F. Pedregosa, G. Varoquaux, A. Gramfort, V. Michel, B. Thirion, O. Grisel, M. Blondel, P. Prettenhofer, R. Weiss, V. Dubourg, J. Vanderplas, A. Pas- sos, D. Cournapeau, M. Brucher, M. Perrot, and E. Duchesnay, “Scikit-learn:

Machine learning in Python,” Journal of Machine Learning Research, vol. 12, pp. 2825–2830, 2011.

X. Appendix

A. Source Code

source–code/models/db.py

#−∗− c o d i n g : u t f−8−∗−

#########################################################################

## T h i s s c a f f o l d i n g model makes y o u r app work on G o o g l e App E n g i n e t o o

## F i l e i s r e l e a s e d u n d e r p u b l i c domain and you c a n u s e w i t h o u t l i m i t a t i o n s

#########################################################################

i f r e q u e s t . g l o b a l s e t t i n g s . w e b 2 p y v e r s i o n < ” 2 . 1 4 . 1 ” : r a i s e HTTP( 5 0 0 , ” R e q u i r e s web2py 2 . 1 3 . 3 o r n e w e r ” )

## i f SSL/HTTPS i s p r o p e r l y c o n f i g u r e d and you want a l l HTTP r e q u e s t s t o

## be r e d i r e c t e d t o HTTPS, uncomment t h e l i n e b e l o w :

# r e q u e s t . r e q u i r e s h t t p s ( )

## app c o n f i g u r a t i o n made e a s y . Look i n s i d e p r i v a t e / a p p c o n f i g . i n i f r o m g l u o n . c o n t r i b . a p p c o n f i g i m p o r t AppConfig

## o n c e i n p r o d u c t i o n , remove r e l o a d=True t o g a i n f u l l s p e e d myconf = AppConfig ( r e l o a d=True )

i f n o t r e q u e s t . env . w e b 2 p y r u n t i m e g a e :

## i f NOT r u n n i n g on G o o g l e App E n g i n e u s e S Q L i t e o r o t h e r DB db = DAL( myconf . g e t ( ’ db . u r i ’ ) ,

p o o l s i z e = myconf . g e t ( ’ db . p o o l s i z e ’ ) , m i g r a t e e n a b l e d = myconf . g e t ( ’ db . m i g r a t e ’ ) , c h e c k r e s e r v e d = [ ’ a l l ’ ] ,

d b c o d e c = ’UTF−8 ’) e l s e :

## c o n n e c t t o G o o g l e B i g T a b l e ( o p t i o n a l ’ g o o g l e : d a t a s t o r e : / / namespace ’ ) db = DAL( ’ g o o g l e : d a t a s t o r e+ndb ’ )

## s t o r e s e s s i o n s and t i c k e t s t h e r e s e s s i o n . c o n n e c t ( r e q u e s t , r e s p o n s e , db=db )

## o r s t o r e s e s s i o n i n Memcache , R e d i s , e t c .

## f r o m g l u o n . c o n t r i b . memdb i m p o r t MEMDB

## f r o m g o o g l e . a p p e n g i n e . a p i . memcache i m p o r t C l i e n t

## s e s s i o n . c o n n e c t ( r e q u e s t , r e s p o n s e , db = MEMDB( C l i e n t ( ) ) )

## by d e f a u l t g i v e a v i e w / g e n e r i c . e x t e n s i o n t o a l l a c t i o n s f r o m l o c a l h o s t

## none o t h e r w i s e . a p a t t e r n c a n be ’ c o n t r o l l e r / f u n c t i o n . e x t e n s i o n ’ r e s p o n s e . g e n e r i c p a t t e r n s = [ ’’ ] i f r e q u e s t . i s l o c a l e l s e [ ]

## c h o o s e a s t y l e f o r f o r m s

r e s p o n s e . f o r m s t y l e = myconf . g e t ( ’ f o r m s . f o r m s t y l e ’ ) # o r ’ b o o t s t r a p 3 s t a c k e d ’ o r ’ b o o t s t r a p 2 ’ o r o t h e r

r e s p o n s e . f o r m l a b e l s e p a r a t o r = myconf . g e t ( ’ f o r m s . s e p a r a t o r ’ ) o r ’ ’

## ( o p t i o n a l ) o p t i m i z e h a n d l i n g o f s t a t i c f i l e s

# r e s p o n s e . o p t i m i z e c s s = ’ c o n c a t , m i n i f y , i n l i n e ’

# r e s p o n s e . o p t i m i z e j s = ’ c o n c a t , m i n i f y , i n l i n e ’

## ( o p t i o n a l ) s t a t i c a s s e t s f o l d e r v e r s i o n i n g

# r e s p o n s e . s t a t i c v e r s i o n = ’ 0 . 0 . 0 ’

#########################################################################

## H e r e i s s a m p l e c o d e i f you n e e d f o r

## e m a i l c a p a b i l i t i e s

## a u t h e n t i c a t i o n ( r e g i s t r a t i o n , l o g i n , l o g o u t , . . . )

## a u t h o r i z a t i o n ( r o l e b a s e d a u t h o r i z a t i o n )

## s e r v i c e s ( xml , c s v , j s o n , xmlrpc , j s o n r p c , amf , r s s )

## o l d s t y l e c r u d a c t i o n s

## ( more o p t i o n s d i s c u s s e d i n g l u o n / t o o l s . py )

#########################################################################

f r o m g l u o n . t o o l s i m p o r t Auth , S e r v i c e , P l u g i n M a n a g e r

# h o s t names must be a l i s t o f a l l o w e d h o s t names ( g l o b s y n t a x a l l o w e d ) a u t h = Auth ( db , h o s t n a m e s=myconf . g e t ( ’ h o s t . names ’ ) )

s e r v i c e = S e r v i c e ( ) p l u g i n s = P l u g i n M a n a g e r ( )

## c r e a t e a l l t a b l e s n e e d e d by a u t h i f n o t custom t a b l e s a u t h . d e f i n e t a b l e s ( u s e r n a m e=True , s i g n a t u r e=F a l s e )

db . a u t h u s e r . e m a i l . r e a d a b l e = db . a u t h u s e r . e m a i l . w r i t a b l e = F a l s e

db . a u t h u s e r . p a s s w o r d . r e q u i r e s = [ IS LENGTH ( m i n s i z e =8 , e r r o r m e s s a g e = ’ P a s s w o r d must be a t l e a s t 8 c h a r a c t e r s i n l e n g t h ’ ) , CRYPT( a u t h . s e t t i n g s . hmac key ) ]

a u t h . m e s s a g e s . i n v a l i d l o g i n = ’ I n v a l i d u s e r n a m e / p a s s w o r d c o m b i n a t i o n ’

a u t h . s e t t i n g s . c h a n g e p a s s w o r d n e x t = URL( ’ d e f a u l t ’ , ’ u s e r ’ , a r g s = ’ c h a n g e p a s s w o r d ’ ) a u t h . s e t t i n g s . p r o f i l e n e x t = URL( ’ d e f a u l t ’ , ’ u s e r ’ , a r g s = ’ p r o f i l e ’ )

## c o n f i g u r e a u t h p o l i c y

a u t h . s e t t i n g s . c r e a t e u s e r g r o u p s = None

a u t h . s e t t i n g s . r e g i s t r a t i o n r e q u i r e s v e r i f i c a t i o n = F a l s e a u t h . s e t t i n g s . r e g i s t r a t i o n r e q u i r e s a p p r o v a l = F a l s e a u t h . s e t t i n g s . r e s e t p a s s w o r d r e q u i r e s v e r i f i c a t i o n = True a u t h . s e t t i n g s . r e m e m b e r m e f o r m = F a l s e

#########################################################################

## D e f i n e y o u r t a b l e s b e l o w ( o r b e t t e r i n a n o t h e r model f i l e ) f o r e x a m p l e

##

##>>> db . d e f i n e t a b l e ( ’ m y t a b l e ’ , F i e l d ( ’ m y f i e l d ’ , ’ s t r i n g ’ ) )

##

## F i e l d s c a n be ’ s t r i n g ’ , ’ t e x t ’ , ’ p a s s w o r d ’ , ’ i n t e g e r ’ , ’ d o u b l e ’ , ’ b o o l e a n ’

## ’ d a t e ’ , ’ t i m e ’ , ’ d a t e t i m e ’ , ’ b l o b ’ , ’ u p l o a d ’ , ’ r e f e r e n c e TABLENAME’

## T h e r e i s an i m p l i c i t ’ i d i n t e g e r a u t o i n c r e m e n t ’ f i e l d

## C o n s u l t manual f o r more o p t i o n s , v a l i d a t o r s , e t c .

##

## More API e x a m p l e s f o r c o n t r o l l e r s :

##

##>>> db . m y t a b l e . i n s e r t ( m y f i e l d = ’ v a l u e ’ )

##>>> r o w s=db ( db . m y t a b l e . m y f i e l d ==’ v a l u e ’ ) . s e l e c t ( db . m y t a b l e . ALL)

##>>> f o r row i n r o w s : p r i n t row . i d , row . m y f i e l d

#########################################################################

## a f t e r d e f i n i n g t a b l e s , uncomment b e l o w t o e n a b l e a u d i t i n g

# a u t h . e n a b l e r e c o r d v e r s i o n i n g ( db ) MESSAGE TAGS = ( ’ U n a s s i g n e d ’ ,

’ D e r m a t o l o g y ’ ,

’ G e n e r a l Q u e s t i o n ’ ,

’ I n t e r n a l M e d i c i n e ’ ,

’ Medico L e g a l ’ ,

’ N e u r o l o g y ’ ,

’ Obgyn ’ ,

’ Ophthalmology ’ ,

’ O t o r h i n o l a r y n g o l o g y ’ ,

’ P e d i a t r i c s ’ ,

’ R a d i o l o g y ’ ,

’ S u r g e r y ’ , )

db . d e f i n e t a b l e ( ’ t m e s s a g e ’ ,

F i e l d ( ’ m s g t i m e ’ , ’ d a t e t i m e ’ , r e p r e s e n t=lambda x , row : x . s t r f t i m e (”%b %d , %Y %I :%M

%p ” ) , l a b e l = ’ R e c e i v e d ’ ) ,

F i e l d ( ’ m s g s e n d e r ’ , ’ s t r i n g ’ , n o t n u l l=True , l a b e l = ’From ’ ) , F i e l d ( ’ m s g c o n t e n t ’ , ’ t e x t ’ , n o t n u l l=True , l a b e l = ’ Message ’ ) ,

F i e l d ( ’ m s g t a g ’ , ’ s t r i n g ’ , r e q u i r e s=I S I N S E T (MESSAGE TAGS, e r r o r m e s s a g e = ’ S e l e c t a v a l u e ’ ) , l a b e l = ’Tag ’ ) ,

F i e l d ( ’ i s v e r i f i e d ’ , ’ b o o l e a n ’ ) , F i e l d ( ’ i s s p a m ’ , ’ b o o l e a n ’ ) )

db . d e f i n e t a b l e ( ’ t f i l t e r ’ , F i e l d ( ’ m s g s e n d e r ’ , ’ s t r i n g ’ , r e q u i r e d=True , u n i q u e=True , l a b e l = ’ S e n d e r Name ’ ) )

db . d e f i n e t a b l e ( ’ t m o d e l ’ ,

F i e l d ( ’ m d l t i m e ’ , ’ d a t e t i m e ’ , r e p r e s e n t=lambda x , row : x . s t r f t i m e (”%b %d , %Y %I :%M

%p ” ) , l a b e l = ’ Date C r e a t e d ’ ) ,

F i e l d ( ’ mdl name ’ , ’ s t r i n g ’ , r e q u i r e d=True , u n i q u e=True , l a b e l = ’ Model Name ’ ) , F i e l d ( ’ m d l p e r c e n t ’ , ’ i n t e g e r ’ , r e q u i r e s = IS INT IN RANGE ( 1 , 1 0 0 , e r r o r m e s s a g e = ’

Out o f r a n g e ! 1−100 o n l y ’ ) , l a b e l = ’ S e l e c t P e r c e n t i l e ’ ) ,

F i e l d ( ’ mdl ngrams ’ , ’ i n t e g e r ’ , r e q u i r e s = IS INT IN RANGE ( 1 , 1 0 , e r r o r m e s s a g e = ’Out o f r a n g e ! 1−10 o n l y ’ ) , l a b e l = ’ S e l e c t n−grams ’ ) ,

F i e l d ( ’ i s d e p l o y e d ’ , ’ b o o l e a n ’ , d e f a u l t=F a l s e ) ) f r o m t a g r i m p o r t TAGR

t a g r = c a c h e . ram ( ’ c t a g r ’ , lambda : TAGR( ) , t i m e e x p i r e=None )

source–code/models/menu.py

#−∗− c o d i n g : u t f−8−∗−

# t h i s f i l e i s r e l e a s e d u n d e r p u b l i c domain and you c a n u s e w i t h o u t l i m i t a t i o n s

#########################################################################

## C u s t o m i z e y o u r APP t i t l e , s u b t i t l e and menus h e r e

#########################################################################

r e s p o n s e . l o g o = A(B ( ’ web ’ , SPAN( 2 ) , ’ py ’ ) ,XML( ’& t r a d e ;& nbsp ; ’ ) ,

c l a s s =”navbar−b r a n d ” , h r e f =” h t t p : / /www. web2py . com / ” , i d =”web2py−l o g o ” )

r e s p o n s e . t i t l e = r e q u e s t . a p p l i c a t i o n . r e p l a c e ( ’ ’ , ’ ’ ) . t i t l e ( ) r e s p o n s e . s u b t i t l e = ’ ’

## r e a d more a t h t t p : / / dev . w3 . o r g / h t m l 5 / markup / meta . name . html r e s p o n s e . meta . a u t h o r = myconf . g e t ( ’ app . a u t h o r ’ )

r e s p o n s e . meta . d e s c r i p t i o n = myconf . g e t ( ’ app . d e s c r i p t i o n ’ ) r e s p o n s e . meta . k e y w o r d s = myconf . g e t ( ’ app . k e y w o r d s ’ ) r e s p o n s e . meta . g e n e r a t o r = myconf . g e t ( ’ app . g e n e r a t o r ’ )

#########################################################################

## t h i s i s t h e main a p p l i c a t i o n menu add / remove i t e m s a s r e q u i r e d

#########################################################################

i f a u t h . i s l o g g e d i n ( ) : r e s p o n s e . menu += [

(CAT( I ( c l a s s = ’ g l y p h i c o n g l y p h i c o n−u s e r ’ ) , ’+ a u t h . u s e r . f i r s t n a m e + ’ ’+

a u t h . u s e r . l a s t n a m e ) , F a l s e , URL( ’ d e f a u l t ’ , ’ i n d e x ’ , a r g s = [ ’ l o g i n ’ ] ) , [ ] ) ,

(CAT( I ( c l a s s = ’ g l y p h i c o n g l y p h i c o n−e n v e l o p e ’ ) , M e s s a g e s ’ ) , F a l s e , URL( ’ m e s s a g e s ’ , ’ i n d e x ’ ) , [ ] ) ,

(CAT( I ( c l a s s = ’ g l y p h i c o n g l y p h i c o n−t r a s h ’ ) , F i l t e r e d ’ ) , F a l s e , URL( ’ f i l t e r e d ’ , ’ i n d e x ’ ) , [ ] )

]

i f a u t h . h a s m e m b e r s h i p ( ’ A d m i n i s t r a t o r ’ ) : r e s p o n s e . menu += [

(CAT( I ( c l a s s = ’ g l y p h i c o n g l y p h i c o n−f i l t e r ’ ) , F i l t e r L i s t ’ ) , F a l s e , URL( ’ f i l t e r s e t t i n g s ’ , ’ i n d e x ’ ) , [ ] ) ,

(CAT( I ( c l a s s = ’ g l y p h i c o n g l y p h i c o n−cog ’ ) , ’ TAGR S e t t i n g s ’ ) , F a l s e , URL( ’ t a g r s e t t i n g s ’ , ’ i n d e x ’ ) , [ ] ) ,

]

r e s p o n s e . menu += [ ( CAT( I ( c l a s s = ’ g l y p h i c o n g l y p h i c o n−l o g−out ’ ) , Log Out ’ ) , F a l s e , URL( ’ d e f a u l t ’ , ’ i n d e x ’ , a r g s = [ ’ l o g o u t ’ ] ) , [ ] ) , ]

i f ” a u t h ” i n l o c a l s ( ) : a u t h . wikimenu ( )

source–code/controllers/default.py

#−∗− c o d i n g : u t f−8−∗−

# t h i s f i l e i s r e l e a s e d u n d e r p u b l i c domain and you c a n u s e w i t h o u t l i m i t a t i o n s

#########################################################################

## T h i s i s a s a m p l e c o n t r o l l e r

## i n d e x i s t h e d e f a u l t a c t i o n o f any a p p l i c a t i o n

## u s e r i s r e q u i r e d f o r a u t h e n t i c a t i o n and a u t h o r i z a t i o n

## download i s f o r d o w n l o a d i n g f i l e s u p l o a d e d i n t h e db ( d o e s s t r e a m i n g )

#########################################################################

r e s p o n s e . t i t l e = ’ N a t i o n a l T e l e h e a l t h System ’ d e f i n d e x ( ) :

i f a u t h . h a s m e m b e r s h i p ( ’ T e l e h e a l t h Nurse ’ ) : r e s p o n s e . c u r r e n t r o l e = ’ Nurse ’

e l i f a u t h . h a s m e m b e r s h i p ( ’ A d m i n i s t r a t o r ’ ) : r e s p o n s e . c u r r e n t r o l e = ’ Admin ’

e l s e :

r e s p o n s e . c u r r e n t r o l e = ’ User ’ p a s s

r e t u r n d i c t ( f o r m=a u t h ( ) ) d e f u s e r ( ) :

” ” ” e x p o s e s :

h t t p : / / . . . . / [ app ] / d e f a u l t / u s e r / l o g i n h t t p : / / . . . . / [ app ] / d e f a u l t / u s e r / l o g o u t h t t p : / / . . . . / [ app ] / d e f a u l t / u s e r / r e g i s t e r h t t p : / / . . . . / [ app ] / d e f a u l t / u s e r / p r o f i l e

h t t p : / / . . . . / [ app ] / d e f a u l t / u s e r / r e t r i e v e p a s s w o r d h t t p : / / . . . . / [ app ] / d e f a u l t / u s e r / c h a n g e p a s s w o r d h t t p : / / . . . . / [ app ] / d e f a u l t / u s e r / b u l k r e g i s t e r u s e @auth . r e q u i r e s l o g i n ( )

@auth . r e q u i r e s m e m b e r s h i p ( ’ g r o u p name ’ )

@auth . r e q u i r e s p e r m i s s i o n ( ’ r e a d ’ , ’ t a b l e name ’ , r e c o r d i d ) t o d e c o r a t e f u n c t i o n s t h a t n e e d a c c e s s c o n t r o l

a l s o n o t i c e t h e r e i s h t t p : / / . . . . / [ app ] / appadmin / manage / a u t h t o a l l o w a d m i n i s t r a t o r t o manage u s e r s

” ” ”

” ” ”

e x a m p l e a c t i o n u s i n g t h e i n t e r n a t i o n a l i z a t i o n o p e r a t o r T and f l a s h r e n d e r e d by v i e w s / d e f a u l t / i n d e x . html o r v i e w s / g e n e r i c . html

i f you n e e d a s i m p l e w i k i s i m p l y r e p l a c e t h e two l i n e s b e l o w w i t h : r e t u r n a u t h . w i k i ( )

” ” ”

i f r e q u e s t . a r g s ( 0 ) == ’ n o t a u t h o r i z e d ’ :

r e d i r e c t (URL( ’ d e f a u l t ’ , ’ n o t a u t h o r i z e d . html ’ ) ) e l i f r e q u e s t . a r g s ( 0 ) == ’ l o g i n ’ :

r e d i r e c t (URL( ’ d e f a u l t ’ , ’ i n d e x ’ , a r g s = ’ l o g i n ’ ) ) e l s e :

r e t u r n d i c t ( f o r m=a u t h ( ) ) d e f n o t a u t h o r i z e d ( ) :

r e t u r n d i c t ( )

@cache . a c t i o n ( ) d e f download ( ) :

” ” ”

a l l o w s d o w n l o a d i n g o f u p l o a d e d f i l e s

h t t p : / / . . . . / [ app ] / d e f a u l t / download / [ f i l e n a m e ]

” ” ”

r e t u r n r e s p o n s e . download ( r e q u e s t , db ) d e f c a l l ( ) :

” ” ”

e x p o s e s s e r v i c e s . f o r e x a m p l e :

h t t p : / / . . . . / [ app ] / d e f a u l t / c a l l / j s o n r p c

d e c o r a t e w i t h @ s e r v i c e s . j s o n r p c t h e f u n c t i o n s t o e x p o s e s u p p o r t s xml , j s o n , xmlrpc , j s o n r p c , amfrpc , r s s , c s v

” ” ”

r e t u r n s e r v i c e ( )

source–code/controllers/messages.py

r e s p o n s e . t i t l e = ’ N a t i o n a l T e l e h e a l t h System ’

@auth . r e q u i r e s l o g i n ( ) d e f i n d e x ( ) :

r e s p o n s e . t i t l e += ’ | M e s s a g e s ’ p o s t s p e r p a g e = 20

d i s p l a y l i n k s = 5

t o t a l p o s t s = db ( db . t m e s s a g e . i s s p a m == F a l s e ) . c o u n t ( ) t o t a l p a g e s = t o t a l p o s t s / p o s t s p e r p a g e

i f ( t o t a l p o s t s % p o s t s p e r p a g e != 0 ) : t o t a l p a g e s += 1 i f n o t r e q u e s t . v a r s . p a g e o r i n t ( r e q u e s t . v a r s . p a g e ) < 1 :

r e d i r e c t (URL( v a r s ={’ page ’ : 1}) ) e l i f i n t ( r e q u e s t . v a r s . p a g e ) > t o t a l p a g e s :

r e d i r e c t (URL( v a r s ={’ page ’ : t o t a l p a g e s}) ) e l s e :

c u r r e n t p a g e = i n t ( r e q u e s t . v a r s . p a g e ) s t a r t r o w = ( c u r r e n t p a g e−1)∗p o s t s p e r p a g e e n d r o w = c u r r e n t p a g ep o s t s p e r p a g e

m e s s a g e s = db ( db . t m e s s a g e . i s s p a m == F a l s e ) . s e l e c t ( o r d e r b y =˜db . t m e s s a g e . m s g t i m e , l i m i t b y =(

s t a r t r o w , e n d r o w ) ) i f t o t a l p a g e s == 1 :

p a g i n a t i o n = None e l s e :

i f c u r r e n t p a g e d i s p l a y l i n k s > 0 :

s t a r t l i n k = c u r r e n t p a g e d i s p l a y l i n k s e l s e :

s t a r t l i n k = 1

i f c u r r e n t p a g e + d i s p l a y l i n k s < t o t a l p a g e s : e n d l i n k = c u r r e n t p a g e + d i s p l a y l i n k s e l s e :

e n d l i n k = t o t a l p a g e s p a g i n a t i o n = [ ]

i f s t a r t l i n k > 1 :

p a g i n a t i o n . append ( L I (A( ” 1 ” , h r e f =URL( i n d e x , v a r s=d i c t ( p a g e = ’ 1 ’ ) ) ) ) ) p a g i n a t i o n . append ( L I (SPAN ( ” . . . ” ) , c l a s s =” d i s a b l e d ” ) )

f o r i i n r a n g e ( s t a r t l i n k , e n d l i n k + 1 ) : i f c u r r e n t p a g e == i :

p a g i n a t i o n . append ( L I (A( s t r ( i ) , h r e f =URL( i n d e x , v a r s=d i c t ( p a g e=s t r ( i ) ) ) ) , c l a s s =”

a c t i v e ” ) ) e l s e :

p a g i n a t i o n . append ( L I (A( s t r ( i ) , h r e f =URL( i n d e x , v a r s=d i c t ( p a g e=s t r ( i ) ) ) ) ) ) i f e n d l i n k < t o t a l p a g e s :

p a g i n a t i o n . append ( L I (SPAN ( ” . . . ” ) , c l a s s =” d i s a b l e d ” ) )

p a g i n a t i o n . append ( L I (A( s t r ( t o t a l p a g e s ) , h r e f =URL( i n d e x , v a r s=d i c t ( p a g e=s t r ( t o t a l p a g e s ) ) ) ) ) )

r e t u r n d i c t ( m e s s a g e s=m e s s a g e s , p a g i n a t i o n=p a g i n a t i o n )

@auth . r e q u i r e s s i g n a t u r e ( )

@auth . r e q u i r e s l o g i n ( ) d e f mark ( ) :

m e s s a g e s = db ( db . t m e s s a g e . i d == r e q u e s t . v a r s . m a r k i d ) . s e l e c t ( ) f o r m = FORM(INPUT( t y p e = ’ s u b m i t ’ , v a l u e = ’ Yes ’ ) ,

INPUT( t y p e = ’ b u t t o n ’ , v a l u e = ’No ’ , o n c l i c k = ’ window . l o c a t i o n . h r e f =” ’ + URL( ’ i n d e x . html ’ , v a r s ={’ page ’ : r e q u e s t . v a r s . p a g e}) + ’ ” ; r e t u r n f a l s e ; ’ )

)

i f f o r m . p r o c e s s ( ) . a c c e p t e d :

db ( db . t m e s s a g e . i d == r e q u e s t . v a r s . m a r k i d ) . u p d a t e ( i s s p a m=True ) r e s p o n s e . f l a s h = None

r e d i r e c t (URL( ’ i n d e x . html ’ , v a r s ={’ page ’ : r e q u e s t . v a r s . p a g e}) , c l i e n t s i d e =True ) r e t u r n d i c t ( f o r m=form , m e s s a g e s=m e s s a g e s )

@auth . r e q u i r e s s i g n a t u r e ( )

@auth . r e q u i r e s l o g i n ( ) d e f remove ( ) :

m e s s a g e s = db ( db . t m e s s a g e . i d == r e q u e s t . v a r s . r e m o v e i d ) . s e l e c t ( ) f o r m = FORM(INPUT( t y p e = ’ s u b m i t ’ , v a l u e = ’ Yes ’ ) ,

INPUT( t y p e = ’ b u t t o n ’ , v a l u e = ’No ’ , o n c l i c k = ’ window . l o c a t i o n . h r e f =” ’ + URL( ’ i n d e x . html ’ , v a r s ={’ page ’ : r e q u e s t . v a r s . p a g e}) + ’ ” ; r e t u r n f a l s e ; ’ )

)

i f f o r m . p r o c e s s ( ) . a c c e p t e d :

db ( db . t m e s s a g e . i d == r e q u e s t . v a r s . r e m o v e i d ) . u p d a t e ( i s v e r i f i e d =F a l s e ) r e s p o n s e . f l a s h = None

r e d i r e c t (URL( ’ i n d e x . html ’ , v a r s ={’ page ’ : r e q u e s t . v a r s . p a g e}) , c l i e n t s i d e =True ) r e t u r n d i c t ( f o r m=form , m e s s a g e s=m e s s a g e s )

d e f v e r i f y p r o c e s s i n g ( f o r m ) :

i f f o r m . v a r s . i s v e r i f i e d ==’on ’ and f o r m . v a r s . m s g t a g ==’ U n a s s i g n e d ’ : f o r m . e r r o r s . m s g t a g = ’ Cannot v e r i f y a m e s s a g e t a g g e d a s U n a s s i g n e d ’

@auth . r e q u i r e s s i g n a t u r e ( )

@auth . r e q u i r e s l o g i n ( ) d e f v e r i f y ( ) :

v e r i f y i d = r e q u e s t . v a r s . v e r i f y i d db . t m e s s a g e . m s g t i m e . w r i t a b l e = F a l s e db . t m e s s a g e . m s g s e n d e r . w r i t a b l e = F a l s e db . t m e s s a g e . m s g c o n t e n t . w r i t a b l e = F a l s e

db . t m e s s a g e . i s s p a m . r e a d a b l e = db . t m e s s a g e . i s s p a m . w r i t a b l e = F a l s e f o r m = SQLFORM( t a b l e = db . t m e s s a g e ,

r e c o r d = v e r i f y i d , f o r m s t y l e = ” t a b l e 3 c o l s ” , s h o w i d = F a l s e ,

l a b e l s = {’ i s v e r i f i e d ’ : ’ Check t o v e r i f y ’}) i f f o r m . p r o c e s s ( o n v a l i d a t i o n= v e r i f y p r o c e s s i n g ) . a c c e p t e d :

r e s p o n s e . f l a s h = None

r e d i r e c t (URL( ’ i n d e x . html ’ , v a r s ={’ page ’ : r e q u e s t . v a r s . p a g e}) , c l i e n t s i d e =True ) r e t u r n d i c t ( f o r m=f o r m )

source–code/controllers/filtered.py

r e s p o n s e . t i t l e = ’ N a t i o n a l T e l e h e a l t h System ’

@auth . r e q u i r e s l o g i n ( ) d e f i n d e x ( ) :

r e s p o n s e . t i t l e += ’ | F i l t e r e d M e s s a g e s ’ p o s t s p e r p a g e = 20

d i s p l a y l i n k s = 5

t o t a l p o s t s = db ( db . t m e s s a g e . i s s p a m == True ) . c o u n t ( ) t o t a l p a g e s = t o t a l p o s t s / p o s t s p e r p a g e

i f ( t o t a l p o s t s % p o s t s p e r p a g e != 0 ) : t o t a l p a g e s += 1 i f n o t r e q u e s t . v a r s . p a g e o r i n t ( r e q u e s t . v a r s . p a g e ) < 1 :

r e d i r e c t (URL( v a r s ={’ page ’ : 1}) )

e l i f i n t ( r e q u e s t . v a r s . p a g e ) > t o t a l p a g e s : r e d i r e c t (URL( v a r s ={’ page ’ : t o t a l p a g e s}) ) e l s e :

c u r r e n t p a g e = i n t ( r e q u e s t . v a r s . p a g e ) s t a r t r o w = ( c u r r e n t p a g e−1)∗p o s t s p e r p a g e e n d r o w = c u r r e n t p a g ep o s t s p e r p a g e

m e s s a g e s = db ( db . t m e s s a g e . i s s p a m == True ) . s e l e c t ( o r d e r b y =˜db . t m e s s a g e . m s g t i m e , l i m i t b y =(

s t a r t r o w , e n d r o w ) ) i f t o t a l p a g e s == 1 :

p a g i n a t i o n = None e l s e :

i f c u r r e n t p a g e d i s p l a y l i n k s > 0 :

s t a r t l i n k = c u r r e n t p a g e d i s p l a y l i n k s e l s e :

s t a r t l i n k = 1

i f c u r r e n t p a g e + d i s p l a y l i n k s < t o t a l p a g e s : e n d l i n k = c u r r e n t p a g e + d i s p l a y l i n k s e l s e :

e n d l i n k = t o t a l p a g e s p a g i n a t i o n = [ ]

i f s t a r t l i n k > 1 :

p a g i n a t i o n . append ( L I (A( ” 1 ” , h r e f =URL( i n d e x , v a r s=d i c t ( p a g e = ’ 1 ’ ) ) ) ) ) p a g i n a t i o n . append ( L I (SPAN ( ” . . . ” ) , c l a s s =” d i s a b l e d ” ) )

f o r i i n r a n g e ( s t a r t l i n k , e n d l i n k + 1 ) : i f c u r r e n t p a g e == i :

p a g i n a t i o n . append ( L I (A( s t r ( i ) , h r e f =URL( i n d e x , v a r s=d i c t ( p a g e=s t r ( i ) ) ) ) , c l a s s =”

a c t i v e ” ) ) e l s e :

p a g i n a t i o n . append ( L I (A( s t r ( i ) , h r e f =URL( i n d e x , v a r s=d i c t ( p a g e=s t r ( i ) ) ) ) ) ) i f e n d l i n k < t o t a l p a g e s :

p a g i n a t i o n . append ( L I (SPAN ( ” . . . ” ) , c l a s s =” d i s a b l e d ” ) )

p a g i n a t i o n . append ( L I (A( s t r ( t o t a l p a g e s ) , h r e f =URL( i n d e x , v a r s=d i c t ( p a g e=s t r ( t o t a l p a g e s ) ) ) ) ) )

r e t u r n d i c t ( m e s s a g e s=m e s s a g e s , p a g i n a t i o n=p a g i n a t i o n )

@auth . r e q u i r e s s i g n a t u r e ( )

@auth . r e q u i r e s l o g i n ( ) d e f unmark ( ) :

m e s s a g e s = db ( db . t m e s s a g e . i d == r e q u e s t . v a r s . u n m a r k i d ) . s e l e c t ( )

f o r m = FORM(INPUT( t y p e = ’ s u b m i t ’ , v a l u e = ’ Yes ’ ) ,

INPUT( t y p e = ’ b u t t o n ’ , v a l u e = ’No ’ , o n c l i c k = ’ l o c a t i o n . h r e f =” ’ + URL( ’ i n d e x . html ’ , v a r s ={’ page ’ : r e q u e s t . v a r s . p a g e}) + ’ ” ; r e t u r n f a l s e ; ’ )

)

i f f o r m . p r o c e s s ( ) . a c c e p t e d :

db ( db . t m e s s a g e . i d == r e q u e s t . v a r s . u n m a r k i d ) . u p d a t e ( i s s p a m=F a l s e ) r e s p o n s e . f l a s h = None

r e d i r e c t (URL( ’ i n d e x . html ’ , v a r s ={’ page ’ : r e q u e s t . v a r s . p a g e}) , c l i e n t s i d e =True ) r e t u r n d i c t ( f o r m=form , m e s s a g e s=m e s s a g e s )

source–code/controllers/filter settings.py

r e s p o n s e . t i t l e = ’ N a t i o n a l T e l e h e a l t h System ’

@auth . r e q u i r e s m e m b e r s h i p ( ’ A d m i n i s t r a t o r ’ ) d e f i n d e x ( ) :

r e s p o n s e . t i t l e += ’ | F i l t e r S e t t i n g s ’

r e t u r n d i c t ( m e s s a g e=” h e l l o f r o m f i l t e r s e t t i n g s . py ” )

@auth . r e q u i r e s m e m b e r s h i p ( ’ A d m i n i s t r a t o r ’ ) d e f b l a c k l i s t ( ) :

db . t f i l t e r . i d . r e a d a b l e = F a l s e g r i d = SQLFORM. g r i d ( db . t f i l t e r ,

f i e l d s =db . t f i l t e r , s o r t a b l e=F a l s e , d e t a i l s =F a l s e , s e a r c h a b l e=F a l s e , d e l e t a b l e=True , e d i t a b l e=F a l s e , c s v=F a l s e ,

f o r m s t y l e = ’ t a b l e 3 c o l s ’ , m a x t e x t l e n g t h =256) g r i d . e l e m e n t ( ’ . w e b 2 p y c o u n t e r ’ , r e p l a c e=None ) r e t u r n d i c t ( g r i d=g r i d )

source–code/controllers/tagr settings.py

i m p o r t o s

r e s p o n s e . t i t l e = ’ N a t i o n a l T e l e h e a l t h System ’

@auth . r e q u i r e s m e m b e r s h i p ( ’ A d m i n i s t r a t o r ’ ) d e f i n d e x ( ) :

r e s p o n s e . t i t l e += ’ | TAGR’

r e t u r n d i c t ( )

@auth . r e q u i r e s m e m b e r s h i p ( ’ A d m i n i s t r a t o r ’ ) d e f t r a i n ( ) :

r e s p o n s e . t i t l e += ’ | T r a i n a new model ’

f o r m = FORM(TABLE(TR(TD(LABEL ( ’ E x t r a c t n−grams : ’ , f o r = ’ ngrams ’ ) , c l a s s = ’ w 2 p f l ’ ) , TD(INPUT( t y p e = ’number ’ , name = ’ ngrams ’ , m i n = ’ 1 ’ , max = ’ 1 0 ’ , r e q u i r e s=

IS NOT EMPTY ( ) ) , c l a s s = ’ w2p fw ’ ) ) ,

TR(TD(LABEL ( ’ S e l e c t p e r c e n t i l e : ’ , f o r = ’ p e r c e n t i l e ’ ) , c l a s s = ’ w 2 p f l ’ ) , TD(INPUT( t y p e = ’number ’ , name = ’ p e r c e n t i l e ’ , m i n = ’ 1 ’ , max = ’ 1 0 0 ’ , r e q u i r e s=

IS NOT EMPTY ( ) ) , c l a s s = ’ w2p fw ’ ) ) ,

TR(TD( c l a s s = ’ w 2 p f l ’ ) ,TD(INPUT( t y p e = ’ s u b m i t ’ , v a l u e = ’ T r a i n ’ ) , c l a s s = ’ w2p fw ’ ) ) ) ) . p r o c e s s ( )

r e t u r n d i c t ( f o r m=f o r m ) d e f t r a i n r e s u l t s ( ) :

d a t a= g e t d a t a ( )

d a t a m e s s a g e s = d a t a [ ’ m e s s a g e s ’ ] d a t a l a b e l s = d a t a [ ’ l a b e l s ’ ]

t a g r = c a c h e . ram . s t o r a g e [ ’ c t a g r ’ ] [ 1 ]

t a g r . i n i t i a l i z e ( i n t ( r e q u e s t . v a r s . ngrams ) , i n t ( r e q u e s t . v a r s . p e r c e n t i l e ) ) d a t a p r e p = t a g r . p r e p a r e d a t a ( d a t a m e s s a g e s , d a t a l a b e l s )

r e p o r t = t a g r . e v a l u a t e ( d a t a p r e p , d a t a l a b e l s ) d a t a p r e p = None

d a t a = None

r e t u r n d i c t ( r e p o r t=r e p o r t ) d e f t e s t ( ) :

f o r m = FORM(TABLE(

TR(TD(LABEL ( ’ P r e d i c t e d Tag : ’ ) , c l a s s = ’ w 2 p f l ’ ) ,TD( r e q u e s t . v a r s . r e s u l t , c l a s s = ’ w2p fw ’ ) ) ,

TR(TD(LABEL ( ’ M e s s a g e C o n t e n t : ’ , f o r = ’ m e s s a g e c o n t e n t ’ ) , c l a s s = ’ w 2 p f l ’ ) ,TD(

TEXTAREA( name = ’ m e s s a g e c o n t e n t ’ , r e q u i r e s=IS NOT EMPTY ( ) ) , c l a s s = ’ w2p fw ’ ) ) ,

TR(TD( c l a s s = ’ w 2 p f l ’ ) ,TD(INPUT( t y p e = ’ s u b m i t ’ , v a l u e = ’ C l a s s i f y ’ ) , c l a s s = ’ w2p fw ’ ) ) )

) d a t a= g e t d a t a ( )

d a t a m e s s a g e s = d a t a [ ’ m e s s a g e s ’ ] d a t a l a b e l s = d a t a [ ’ l a b e l s ’ ]

t a g r = c a c h e . ram . s t o r a g e [ ’ c t a g r ’ ] [ 1 ]

d a t a p r e p = t a g r . p r e p a r e d a t a ( d a t a m e s s a g e s , d a t a l a b e l s )

t a g r . t r a i n o n w h o l e ( d a t a p r e p , d a t a l a b e l s ) d a t a p r e p = None

d a t a = None

i f f o r m . p r o c e s s ( ) . a c c e p t e d :

r e s u l t = t a g r . c l a s s i f y ( r e q u e s t . v a r s . m e s s a g e c o n t e n t )

r e d i r e c t (URL( ’ t a g r s e t t i n g s ’ , ’ t e s t . l o a d ’ , v a r s ={’ r e s u l t ’ : r e s u l t}) ) r e t u r n d i c t ( f o r m=f o r m )

d e f s a v e ( ) :

f o r m = FORM(TABLE(

TR(TD(LABEL ( ’ Model name : ’ , f o r = ’ model name ’ ) , c l a s s = ’ w 2 p f l ’ ) ,TD(INPUT(

t y p e = ’ t e x t ’ , name = ’ model name ’ ,

r e q u i r e s =[IS NOT EMPTY ( e r r o r m e s s a g e = ’ Cannot be empty ’ ) ,

IS NOT IN DB ( db , ’ t m o d e l . mdl name ’ , e r r o r m e s s a g e = ’Name a l r e a d y e x i s t s ’ ) ,

IS ALPHANUMERIC( e r r o r m e s s a g e = ’Name c a n o n l y c o n t a i n a l p h a n u m e r i c c h a r a c t e r s ’ ) ] ) , c l a s s = ’ w2p fw ’ ) ) ,

TR(TD( c l a s s = ’ w 2 p f l ’ ) ,TD(INPUT( t y p e = ’ s u b m i t ’ , v a l u e = ’ Save ’ ) , c l a s s = ’ w2p fw ’ ) ) )

)

i f f o r m . p r o c e s s ( m e s s a g e o n s u c c e s s = ’ Model s u c c e s s f u l l y s a v e d ! ’ ) . a c c e p t e d : t a g r = c a c h e . ram . s t o r a g e [ ’ c t a g r ’ ] [ 1 ]

t a g r . s a v e ( o s . p a t h . j o i n ( r e q u e s t . f o l d e r , ’ p r i v a t e ’ , f o r m . v a r s . model name ) )

db . t m o d e l . i n s e r t ( m d l t i m e=r e q u e s t . now , mdl name=f o r m . v a r s . model name , m d l n g r a m s=r e q u e s t . v a r s . ngrams , m d l p e r c e n t=r e q u e s t . v a r s . p e r c e n t i l e )

r e t u r n d i c t ( f o r m=f o r m )

@auth . r e q u i r e s m e m b e r s h i p ( ’ A d m i n i s t r a t o r ’ ) d e f l o a d ( ) :

r e s p o n s e . t i t l e += ’ | Load a t r a i n e d model ’

mdl = db ( db . t m o d e l ) . s e l e c t ( o r d e r b y =˜db . t m o d e l . m d l t i m e )

f o r m = FORM(TABLE(TR(TD(LABEL ( ’ S e l e c t model : ’ , f o r = ’ model ’ ) , c l a s s = ’ w 2 p f l ’ ) ,

TD(SELECT( name = ’ m o d e l i d ’ ,[ OPTION( mdl [ i ] . mdl name , v a l u e=s t r ( mdl [ i ] . i d ) ) f o r i i n r a n g e ( l e n ( mdl ) ) ] ) , c l a s s = ’ w2p fw ’ ) ) ,

TR(TD( c l a s s = ’ w 2 p f l ’ ) ,TD(INPUT( t y p e = ’ s u b m i t ’ , v a l u e = ’ Load ’ ) , c l a s s = ’ w2p fw

’ ) ) ) ) . p r o c e s s ( ) r e t u r n d i c t ( f o r m=form , mdl=mdl ) d e f l o a d r e s u l t s ( ) :

d a t a= g e t d a t a ( )

d a t a m e s s a g e s = d a t a [ ’ m e s s a g e s ’ ] d a t a l a b e l s = d a t a [ ’ l a b e l s ’ ]

t a g r = c a c h e . ram . s t o r a g e [ ’ c t a g r ’ ] [ 1 ]

t a g r . l o a d ( o s . p a t h . j o i n ( r e q u e s t . f o l d e r , ’ p r i v a t e ’ , r e q u e s t . v a r s . mdl name ) ) d a t a p r e p = t a g r . p r e p a r e d a t a ( d a t a m e s s a g e s , d a t a l a b e l s )

r e p o r t = t a g r . e v a l u a t e ( d a t a p r e p , d a t a l a b e l s ) d a t a p r e p = None

d a t a = None

r e t u r n d i c t ( r e p o r t=r e p o r t )

@auth . r e q u i r e s m e m b e r s h i p ( ’ A d m i n i s t r a t o r ’ ) d e f c h o o s e ( ) :

r e s p o n s e . t i t l e += ’ | Choose a model t o u s e ’

mdl = db ( db . t m o d e l ) . s e l e c t ( o r d e r b y =˜db . t m o d e l . m d l t i m e )

f o r m = FORM(TABLE(TR(TD(LABEL ( ’ S e l e c t model : ’ , f o r = ’ model ’ ) , c l a s s = ’ w 2 p f l ’ ) ,

TD(SELECT( name = ’ m o d e l i d ’ ,[ OPTION( mdl [ i ] . mdl name , v a l u e=s t r ( mdl [ i ] . i d ) ) f o r i i n r a n g e ( l e n ( mdl ) ) ] ) , c l a s s = ’ w2p fw ’ ) ) ,

TR(TD( c l a s s = ’ w 2 p f l ’ ) ,TD(INPUT( t y p e = ’ s u b m i t ’ , v a l u e = ’ Choose ’ ) , c l a s s = ’ w2p fw ’ ) ) ) )

i f f o r m . p r o c e s s ( ) . a c c e p t e d : f o r row i n mdl :

i f row . i d==i n t ( r e q u e s t . v a r s . m o d e l i d ) :

db ( db . t m o d e l . i d == row . i d ) . u p d a t e ( i s d e p l o y e d=True ) e l s e :

db ( db . t m o d e l . i d == row . i d ) . u p d a t e ( i s d e p l o y e d=F a l s e ) r e d i r e c t (URL( ) )

r e t u r n d i c t ( f o r m=form , mdl=mdl ) d e f g e t d a t a ( ) :

r o w s = db ( db . t m e s s a g e . i s v e r i f i e d ==True ) . s e l e c t ( db . t m e s s a g e . m s g t a g , db . t m e s s a g e . m s g c o n t e n t )

d a t a m e s s a g e s = [ ] d a t a l a b e l s = [ ] f o r row i n r o w s :

d a t a m e s s a g e s . append ( row . m s g c o n t e n t ) d a t a l a b e l s . append ( row . m s g t a g )

r e t u r n d i c t ( m e s s a g e s=d a t a m e s s a g e s , l a b e l s =d a t a l a b e l s )

source–code/controllers/input.py

f r o m t a g r i m p o r t TAGR i m p o r t o s

r e s p o n s e . t i t l e = ’ N a t i o n a l T e l e h e a l t h System ’ d e f i n d e x ( ) :

f o r m = FORM(TABLE(

TR(TD(LABEL ( ’ M e s s a g e S e n d e r : ’ , f o r = ’ m e s s a g e s e n d e r ’ ) , c l a s s = ’ w 2 p f l ’ ) ,TD(INPUT(

t y p e = ’ t e x t ’ , name = ’ m e s s a g e s e n d e r ’ , r e q u i r e s=IS NOT EMPTY ( ) ) , c l a s s = ’ w2p fw

’ ) ) ,

TR(TD(LABEL ( ’ M e s s a g e C o n t e n t : ’ , f o r = ’ m e s s a g e c o n t e n t ’ ) , c l a s s = ’ w 2 p f l ’ ) ,TD(

TEXTAREA( name = ’ m e s s a g e c o n t e n t ’ , r e q u i r e s=IS NOT EMPTY ( ) ) , c l a s s = ’ w2p fw ’ ) ) ,

TR(TD( c l a s s = ’ w 2 p f l ’ ) ,TD(INPUT( t y p e = ’ s u b m i t ’ , v a l u e = ’ Submit ’ ) , c l a s s = ’ w2p fw

’ ) ) ) )

i f f o r m . p r o c e s s ( ) . a c c e p t e d :

i f i s s p a m ( r e q u e s t . v a r s . m e s s a g e s e n d e r ) : db . t m e s s a g e . i n s e r t ( m s g t i m e=r e q u e s t . now ,

m s g s e n d e r=r e q u e s t . v a r s . m e s s a g e s e n d e r , m s g c o n t e n t=r e q u e s t . v a r s . m e s s a g e c o n t e n t , m s g t a g = ’ U n a s s i g n e d ’ ,

i s v e r i f i e d =F a l s e , i s s p a m=True )

r e s p o n s e . f l a s h = ’ S e n t t o F i l t e r e d M e s s a g e s f o l d e r ’ e l i f c l f i s o n l i n e ( ) :

db . t m e s s a g e . i n s e r t ( m s g t i m e=r e q u e s t . now ,

m s g s e n d e r=r e q u e s t . v a r s . m e s s a g e s e n d e r , m s g c o n t e n t=r e q u e s t . v a r s . m e s s a g e c o n t e n t , m s g t a g= c l a s s i f y ( r e q u e s t . v a r s . m e s s a g e c o n t e n t ) , i s v e r i f i e d =F a l s e ,

i s s p a m=F a l s e )

r e s p o n s e . f l a s h = ’ Tagged and s e n t t o M e s s a g e s f o l d e r ’ e l s e :

db . t m e s s a g e . i n s e r t ( m s g t i m e=r e q u e s t . now ,

m s g s e n d e r=r e q u e s t . v a r s . m e s s a g e s e n d e r , m s g c o n t e n t=r e q u e s t . v a r s . m e s s a g e c o n t e n t , m s g t a g = ’ U n a s s i g n e d ’ ,

i s v e r i f i e d =F a l s e , i s s p a m=F a l s e )

r e s p o n s e . f l a s h = ’ U n a s s i g n e d ; s e n t t o M e s s a g e s f o l d e r ’ r e t u r n d i c t ( f o r m=f o r m )

d e f i s s p a m ( s e n d e r ) :

r o w s = db ( db . t f i l t e r ) . s e l e c t ( db . t f i l t e r . m s g s e n d e r ) f i l t e r = [ ]

f o r row i n r o w s :

f i l t e r . append ( row . m s g s e n d e r ) r e t u r n s e n d e r i n f i l t e r

d e f c l f i s o n l i n e ( ) :

r o w s = db ( db . t m o d e l ) . s e l e c t ( db . t m o d e l . i s d e p l o y e d ) s t a t u s = [ ]

f o r row i n r o w s :

s t a t u s . append ( row . i s d e p l o y e d ) r e t u r n ( True i n s t a t u s )

d e f c l a s s i f y ( m e s s a g e ) :

f o r row i n db ( db . t m o d e l . i s d e p l o y e d == True ) . s e l e c t ( ) : model = row . mdl name

c l f = TAGR( )

c l f . l o a d ( o s . p a t h . j o i n ( r e q u e s t . f o l d e r , ’ p r i v a t e ’ , model ) ) r e t u r n c l f . c l a s s i f y ( m e s s a g e )

source–code/views/layout.html

<!DOCTYPE html>

<html c l a s s =”no−j s ” l a n g =”{{=T . a c c e p t e d l a n g u a g e o r ’ en ’}}”>

<head>

<t i t l e>{{= r e s p o n s e . t i t l e o r r e q u e s t . a p p l i c a t i o n}}</ t i t l e>

<l i n k r e l =” s t y l e s h e e t ” h r e f =”{{=URL( ’ s t a t i c ’ , ’ c s s / b o o t s t r a p . min . c s s ’ )}}”/>

<l i n k r e l =” s t y l e s h e e t ” h r e f =”{{=URL( ’ s t a t i c ’ , ’ c s s / web2py−b o o t s t r a p 3 . c s s ’ )}}”/>

<l i n k r e l =” s t y l e s h e e t ” h r e f =”{{=URL( ’ s t a t i c ’ , ’ c s s / t a g r−s t y l e . c s s ’ )}}”/>

<l i n k r e l =” s h o r t c u t i c o n ” h r e f =”{{=URL( ’ s t a t i c ’ , ’ i m a g e s / f a v i c o n . i c o ’ )}}” t y p e =”i m a g e / x−

i c o n ”>

<l i n k r e l =”a p p l e−t o u c h−i c o n ” h r e f =”{{=URL( ’ s t a t i c ’ , ’ i m a g e s / f a v i c o n . png ’ )}}”>

<!−− A l l J a v a S c r i p t a t t h e bottom , e x c e p t f o r M o d e r n i z r w h i c h e n a b l e s

HTML5 e l e m e n t s & f e a t u r e d e t e c t s −−>

<s c r i p t s r c =”{{=URL( ’ s t a t i c ’ , ’ j s / m o d e r n i z r−2 . 8 . 3 . min . j s ’ )}}”></ s c r i p t>

<!−−[ i f l t IE 9]>

<s c r i p t s r c =”{{=URL( ’ s t a t i c ’ , ’ j s / r e s p o n d−1 . 4 . 2 . min . j s ’ )}}”></ s c r i p t>

<! [ e n d i f ]−−>

{{i n c l u d e ’ w e b 2 p y a j a x . html ’} } {{b l o c k head}}{{end}}

{{

# u s i n g s i d e b a r s n e e d t o know what s i d e b a r you want t o u s e mc0 = ’ c o l−md−12 ’

mc1 = ’ c o l−md−9 ’ mc2 = ’ c o l−md−6 ’

l e f t s i d e b a r e n a b l e d = g l o b a l s ( ) . g e t ( ’ l e f t s i d e b a r e n a b l e d ’ , F a l s e ) r i g h t s i d e b a r e n a b l e d = g l o b a l s ( ) . g e t ( ’ r i g h t s i d e b a r e n a b l e d ’ , F a l s e ) m i d d l e c o l u m n = {0 : mc0 , 1 : mc1 , 2 : mc2}[

( l e f t s i d e b a r e n a b l e d and 1 o r 0 ) +( r i g h t s i d e b a r e n a b l e d and 1 o r 0 ) ] }}

</head>

<body>

<d i v c l a s s =” w 2 p f l a s h a l e r t a l e r t−d i s m i s s a b l e ”>{{= r e s p o n s e . f l a s h o r ’ ’}}</ d i v>

Dokumen terkait