From 25aea581bc59ae3413e3fb867f2f4aa916c7494c Mon Sep 17 00:00:00 2001 From: maroni Date: Mon, 7 May 2012 17:03:40 -0300 Subject: [PATCH] Nova versao do simulador e tratamento de erros das chamadas. --- build.xml | 142 +- nbproject/build-impl.xml | 2226 ++++++++++---------- nbproject/faces-config.NavData | 19 + nbproject/genfiles.properties | 16 +- nbproject/project.properties | 2 +- nbproject/project.xml | 214 +- src/conf/persistence.xml | 4 +- .../simdecs/comunicacao/BaseComunicacao.java | 14 +- .../simdecs/comunicacao/MetodoConfiancaEtapa.java | 5 +- .../comunicacao/MetodoConfiancaInicial.java | 4 +- .../simdecs/comunicacao/MetodoGravaHistorico.java | 4 +- .../ufcspa/simdecs/comunicacao/MetodoGravaLog.java | 39 +- .../simdecs/comunicacao/MetodoIniciaCaso.java | 16 +- .../simdecs/comunicacao/MetodoRegistraAcao.java | 4 +- src/java/org/ufcspa/simdecs/entities/Caso.java | 1 - .../ufcspa/simdecs/entities/DependenciaNodo.java | 1 - .../simdecs/entities/IntervaloTabelaResposta.java | 1 - .../simdecs/entities/IntervencaoPedagogica.java | 140 ++ src/java/org/ufcspa/simdecs/entities/Log.java | 6 +- src/java/org/ufcspa/simdecs/entities/Nodo.java | 4 + .../org/ufcspa/simdecs/entities/NodoPaciente.java | 1 - src/java/org/ufcspa/simdecs/entities/Paciente.java | 1 - src/java/org/ufcspa/simdecs/entities/Rede.java | 1 - .../org/ufcspa/simdecs/entities/RedeAluno.java | 1 - .../org/ufcspa/simdecs/entities/SessaoUsuario.java | 1 - .../ufcspa/simdecs/entities/SinonimoResposta.java | 1 - .../ufcspa/simdecs/entities/TabelaResposta.java | 1 - .../ufcspa/simdecs/entities/TaticaPedagogica.java | 24 +- src/java/org/ufcspa/simdecs/entities/Usuario.java | 1 - .../simdecs/exceptions/InvalidNodeState.java | 17 + .../exceptions/InvalidParameterException.java | 17 + .../simdecs/mb/editarcasos/EditarCasoBean.java | 120 +- .../ufcspa/simdecs/mb/editarcasos/LoginBean.java | 2 +- .../org/ufcspa/simdecs/mediador/LogExecucao.java | 176 +- .../simdecs/mediador/NegociacaoPedagogica.java | 491 ++++- src/java/org/ufcspa/simdecs/util/NodoBean.java | 31 +- .../org/ufcspa/simdecs/util/ProbabilisticBean.java | 36 + src/java/org/ufcspa/simdecs/util/UnBBayesUtil.java | 170 ++ src/java/org/ufcspa/simdecs/util/UnBUtil.java | 163 -- web/WEB-INF/glassfish-web.xml | 11 + web/redes/di.xml | 390 ++++ web/simulador/endereco.txt | 2 +- web/style.css | 1 - web/teste2.xhtml | 12 + 44 files changed, 2825 insertions(+), 1708 deletions(-) create mode 100644 nbproject/faces-config.NavData create mode 100644 src/java/org/ufcspa/simdecs/entities/IntervencaoPedagogica.java create mode 100644 src/java/org/ufcspa/simdecs/exceptions/InvalidNodeState.java create mode 100644 src/java/org/ufcspa/simdecs/exceptions/InvalidParameterException.java create mode 100644 src/java/org/ufcspa/simdecs/util/ProbabilisticBean.java create mode 100644 src/java/org/ufcspa/simdecs/util/UnBBayesUtil.java delete mode 100644 src/java/org/ufcspa/simdecs/util/UnBUtil.java create mode 100644 web/WEB-INF/glassfish-web.xml create mode 100644 web/redes/di.xml create mode 100644 web/teste2.xhtml diff --git a/build.xml b/build.xml index 18b539c..48e17e4 100644 --- a/build.xml +++ b/build.xml @@ -1,71 +1,71 @@ - - - - - - - - - - - Builds, tests, and runs the project SimDeCS. - - - + + + + + + + + + + + Builds, tests, and runs the project SimDeCS. + + + diff --git a/nbproject/build-impl.xml b/nbproject/build-impl.xml index 9623f28..3d76080 100644 --- a/nbproject/build-impl.xml +++ b/nbproject/build-impl.xml @@ -1,1113 +1,1113 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set build.web.dir - Must set build.generated.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.war - - - - - - - - - -The Java EE server classpath is not correctly set up - server home directory is missing. -Either open the project in the IDE and assign the server or setup the server classpath manually. -For example like this: - ant -Dj2ee.server.home=<app_server_installation_directory> - - -The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. -Either open the project in the IDE and assign the server or setup the server classpath manually. -For example like this: - ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) -or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -The libs.CopyLibs.classpath property is not set up. -This property must point to -org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part -of NetBeans IDE installation and is usually located at -<netbeans_installation>/java<version>/ant/extra folder. -Either open the project in the IDE and make sure CopyLibs library -exists or setup the property manually. For example like this: - ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.jsp.includes - - - - - - - - - - - - - - - - - - - - - - - - - - Must select a file in the IDE or set jsp.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. - - - Launching ${browse.url} - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set src.dir + Must set test.src.dir + Must set build.dir + Must set build.web.dir + Must set build.generated.dir + Must set dist.dir + Must set build.classes.dir + Must set dist.javadoc.dir + Must set build.test.classes.dir + Must set build.test.results.dir + Must set build.classes.excludes + Must set dist.war + + + + + + + + + +The Java EE server classpath is not correctly set up - server home directory is missing. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Dj2ee.server.home=<app_server_installation_directory> + + +The Java EE server classpath is not correctly set up. Your active server type is ${j2ee.server.type}. +Either open the project in the IDE and assign the server or setup the server classpath manually. +For example like this: + ant -Duser.properties.file=<path_to_property_file> (where you put the property "j2ee.platform.classpath" in a .properties file) +or ant -Dj2ee.platform.classpath=<server_classpath> (where no properties file is used) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +The libs.CopyLibs.classpath property is not set up. +This property must point to +org-netbeans-modules-java-j2seproject-copylibstask.jar file which is part +of NetBeans IDE installation and is usually located at +<netbeans_installation>/java<version>/ant/extra folder. +Either open the project in the IDE and make sure CopyLibs library +exists or setup the property manually. For example like this: + ant -Dlibs.CopyLibs.classpath=a/path/to/org-netbeans-modules-java-j2seproject-copylibstask.jar + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must set JVM to use for profiling in profiler.info.jvm + Must set profiler agent JVM arguments in profiler.info.jvmargs.agent + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + Must select a file in the IDE or set jsp.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Browser not found, cannot launch the deployed application. Try to set the BROWSER environment variable. + + + Launching ${browse.url} + + + + + + Must select one file in the IDE or set run.class + + + + Must select one file in the IDE or set run.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + + + + + + + + Must select one file in the IDE or set debug.class + + + + + Must set fix.includes + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Must select some files in the IDE or set javac.includes + + + + + + + + + + + + + + + + + + + Some tests failed; see details above. + + + + + + + + + Must select some files in the IDE or set test.includes + + + + Some tests failed; see details above. + + + + + Must select one file in the IDE or set test.class + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/faces-config.NavData b/nbproject/faces-config.NavData new file mode 100644 index 0000000..93f070e --- /dev/null +++ b/nbproject/faces-config.NavData @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/nbproject/genfiles.properties b/nbproject/genfiles.properties index 7062374..8926f6f 100644 --- a/nbproject/genfiles.properties +++ b/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=9cef979c -build.xml.script.CRC32=9f680c47 -build.xml.stylesheet.CRC32=651128d4@1.36.1.1 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=9cef979c -nbproject/build-impl.xml.script.CRC32=9fe94479 -nbproject/build-impl.xml.stylesheet.CRC32=b7883b1f@1.36.1.1 +build.xml.data.CRC32=9cef979c +build.xml.script.CRC32=9f680c47 +build.xml.stylesheet.CRC32=651128d4@1.36.1.1 +# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. +# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. +nbproject/build-impl.xml.data.CRC32=9cef979c +nbproject/build-impl.xml.script.CRC32=9fe94479 +nbproject/build-impl.xml.stylesheet.CRC32=b7883b1f@1.36.1.1 diff --git a/nbproject/project.properties b/nbproject/project.properties index 679653a..922f216 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -54,7 +54,7 @@ includes=** j2ee.compile.on.save=true j2ee.deploy.on.save=true j2ee.platform=1.6-web -j2ee.platform.classpath=${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.home}/modules/jsf-impl.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar:${j2ee.server.home}/modules/javax.resource.jar:${j2ee.server.home}/modules/endorsed/javax.annotation.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/javax.management.j2ee.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl.jar:${j2ee.server.home}/modules/javax.security.auth.message.jar:${j2ee.server.home}/modules/javax.jms.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.security.jacc.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/javax.enterprise.deploy.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/javax.ejb.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/jsf-api.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/javax.servlet.jar:${j2ee.server.home}/modules/javax.transaction.jar:${j2ee.server.home}/modules/jersey-core.jar:${j2ee.server.home}/modules/jstl-impl.jar +j2ee.platform.classpath=${j2ee.server.home}/modules/endorsed/javax.annotation.jar:${j2ee.server.home}/modules/javax.transaction.jar:${j2ee.server.home}/modules/javax.ejb.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/weld-osgi-bundle.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.middleware}/mq/lib/jaxm-api.jar:${j2ee.server.home}/modules/javax.mail.jar:${j2ee.server.home}/modules/javax.enterprise.deploy.jar:${j2ee.server.home}/modules/javax.jms.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/bean-validator.jar:${j2ee.server.home}/modules/javax.security.auth.message.jar:${j2ee.server.home}/modules/jersey-core.jar:${j2ee.server.home}/modules/javax.persistence.jar:${j2ee.server.home}/modules/javax.management.j2ee.jar:${j2ee.server.home}/modules/javax.security.jacc.jar:${j2ee.server.home}/modules/javax.el-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp-api.jar:${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/javax.resource.jar:${j2ee.server.home}/modules/javax.servlet-api.jar:${j2ee.server.home}/modules/javax.servlet.jsp.jstl-api.jar:${j2ee.server.home}/modules/javax.faces.jar j2ee.platform.embeddableejb.classpath=${j2ee.server.home}/lib/embedded/glassfish-embedded-static-shell.jar j2ee.platform.wscompile.classpath=${j2ee.server.home}/modules/webservices-osgi.jar j2ee.platform.wsgen.classpath=${j2ee.server.home}/modules/webservices-osgi.jar:${j2ee.server.home}/modules/endorsed/webservices-api-osgi.jar:${j2ee.server.home}/modules/jaxb-osgi.jar:${j2ee.server.home}/modules/endorsed/jaxb-api-osgi.jar:${j2ee.server.home}/modules/javax.ejb.jar diff --git a/nbproject/project.xml b/nbproject/project.xml index 5240332..0f5d405 100644 --- a/nbproject/project.xml +++ b/nbproject/project.xml @@ -1,107 +1,107 @@ - - - org.netbeans.modules.web.project - - - SimDeCS - 1.6.5 - - - ${libs.hibernate-support.classpath} - WEB-INF/lib - - - ${file.reference.primefaces-3.1-SNAPSHOT.jar} - WEB-INF/lib - - - ${file.reference.avalon-framework-4.1.3.jar} - WEB-INF/lib - - - ${file.reference.commons-fileupload-1.2.2.jar} - WEB-INF/lib - - - ${file.reference.commons-io-2.1.jar} - WEB-INF/lib - - - ${file.reference.commons-lang3-3.1.jar} - WEB-INF/lib - - - ${file.reference.commons-logging-1.1.jar} - WEB-INF/lib - - - ${file.reference.icu4j-3.8.jar} - WEB-INF/lib - - - ${file.reference.javahelp-2.0.02.jar} - WEB-INF/lib - - - ${file.reference.jaxme2-0.5.1.jar} - WEB-INF/lib - - - ${file.reference.jaxme2-rt-0.5.1.jar} - WEB-INF/lib - - - ${file.reference.jaxmeapi-0.5.1.jar} - WEB-INF/lib - - - ${file.reference.jaxmejs-0.5.1.jar} - WEB-INF/lib - - - ${file.reference.jaxmexs-0.5.1.jar} - WEB-INF/lib - - - ${file.reference.jpf-1.5.jar} - WEB-INF/lib - - - ${file.reference.junit-4.1.jar} - WEB-INF/lib - - - ${file.reference.log4j-1.2.12.jar} - WEB-INF/lib - - - ${file.reference.logkit-1.0.1.jar} - WEB-INF/lib - - - ${file.reference.unbbayes-4.10.4-1s.jar} - WEB-INF/lib - - - ${file.reference.xalan-2.7.0.jar} - WEB-INF/lib - - - ${file.reference.xml-apis-1.0.b2.jar} - WEB-INF/lib - - - ${file.reference.jade.jar} - WEB-INF/lib - - - - - - - - - - - - + + + org.netbeans.modules.web.project + + + SimDeCS + 1.6.5 + + + ${libs.hibernate-support.classpath} + WEB-INF/lib + + + ${file.reference.primefaces-3.1-SNAPSHOT.jar} + WEB-INF/lib + + + ${file.reference.avalon-framework-4.1.3.jar} + WEB-INF/lib + + + ${file.reference.commons-fileupload-1.2.2.jar} + WEB-INF/lib + + + ${file.reference.commons-io-2.1.jar} + WEB-INF/lib + + + ${file.reference.commons-lang3-3.1.jar} + WEB-INF/lib + + + ${file.reference.commons-logging-1.1.jar} + WEB-INF/lib + + + ${file.reference.icu4j-3.8.jar} + WEB-INF/lib + + + ${file.reference.javahelp-2.0.02.jar} + WEB-INF/lib + + + ${file.reference.jaxme2-0.5.1.jar} + WEB-INF/lib + + + ${file.reference.jaxme2-rt-0.5.1.jar} + WEB-INF/lib + + + ${file.reference.jaxmeapi-0.5.1.jar} + WEB-INF/lib + + + ${file.reference.jaxmejs-0.5.1.jar} + WEB-INF/lib + + + ${file.reference.jaxmexs-0.5.1.jar} + WEB-INF/lib + + + ${file.reference.jpf-1.5.jar} + WEB-INF/lib + + + ${file.reference.junit-4.1.jar} + WEB-INF/lib + + + ${file.reference.log4j-1.2.12.jar} + WEB-INF/lib + + + ${file.reference.logkit-1.0.1.jar} + WEB-INF/lib + + + ${file.reference.unbbayes-4.10.4-1s.jar} + WEB-INF/lib + + + ${file.reference.xalan-2.7.0.jar} + WEB-INF/lib + + + ${file.reference.xml-apis-1.0.b2.jar} + WEB-INF/lib + + + ${file.reference.jade.jar} + WEB-INF/lib + + + + + + + + + + + + diff --git a/src/conf/persistence.xml b/src/conf/persistence.xml index da0757c..2e3e8ce 100644 --- a/src/conf/persistence.xml +++ b/src/conf/persistence.xml @@ -20,11 +20,13 @@ org.ufcspa.simdecs.entities.TipoEventoLog org.ufcspa.simdecs.entities.Usuario org.ufcspa.simdecs.entities.TaticaPedagogica + org.ufcspa.simdecs.entities.IntervencaoPedagogica true + NONE - + diff --git a/src/java/org/ufcspa/simdecs/comunicacao/BaseComunicacao.java b/src/java/org/ufcspa/simdecs/comunicacao/BaseComunicacao.java index df01da9..dd8de90 100644 --- a/src/java/org/ufcspa/simdecs/comunicacao/BaseComunicacao.java +++ b/src/java/org/ufcspa/simdecs/comunicacao/BaseComunicacao.java @@ -68,21 +68,21 @@ public abstract class BaseComunicacao extends HttpServlet { out.println("" ); out.println(" " ); out.println(" " ); - out.println(" "); Map paramsError = request.getParameterMap(); Iterator iError = paramsError.keySet().iterator(); - + StringBuilder parametros = new StringBuilder(); while ( iError.hasNext() ) { String key = (String) iError.next(); String value = ((String[]) paramsError.get( key ))[ 0 ]; - out.println(" "); + parametros.append(";"); + parametros.append(key); + parametros.append(":"); + parametros.append(value); } - out.println(" "); - out.println(" "); - out.println(" " + stack2string(e)); - out.println(" "); + out.println(" "); + out.println(" "); out.println(" " ); out.println("" ); diff --git a/src/java/org/ufcspa/simdecs/comunicacao/MetodoConfiancaEtapa.java b/src/java/org/ufcspa/simdecs/comunicacao/MetodoConfiancaEtapa.java index d202ad6..28fcfba 100644 --- a/src/java/org/ufcspa/simdecs/comunicacao/MetodoConfiancaEtapa.java +++ b/src/java/org/ufcspa/simdecs/comunicacao/MetodoConfiancaEtapa.java @@ -89,9 +89,10 @@ public class MetodoConfiancaEtapa extends BaseComunicacao { out.println(""); out.println(" "); - out.println(" "); +// out.println(" "); + out.println(" "); + out.println(" " ); -// out.println(" "); out.println(""); } diff --git a/src/java/org/ufcspa/simdecs/comunicacao/MetodoConfiancaInicial.java b/src/java/org/ufcspa/simdecs/comunicacao/MetodoConfiancaInicial.java index ac67a7d..c5b4c0d 100644 --- a/src/java/org/ufcspa/simdecs/comunicacao/MetodoConfiancaInicial.java +++ b/src/java/org/ufcspa/simdecs/comunicacao/MetodoConfiancaInicial.java @@ -64,9 +64,9 @@ public class MetodoConfiancaInicial extends BaseComunicacao { out.println(""); out.println(" "); - out.println(" "); +// out.println(" "); + out.println(" "); out.println(" " ); -// out.println(" "); out.println(""); } diff --git a/src/java/org/ufcspa/simdecs/comunicacao/MetodoGravaHistorico.java b/src/java/org/ufcspa/simdecs/comunicacao/MetodoGravaHistorico.java index b580447..58e1c1e 100644 --- a/src/java/org/ufcspa/simdecs/comunicacao/MetodoGravaHistorico.java +++ b/src/java/org/ufcspa/simdecs/comunicacao/MetodoGravaHistorico.java @@ -58,9 +58,9 @@ public class MetodoGravaHistorico extends BaseComunicacao { out.println(""); // out.println(" "); - out.println(" "); +// out.println(" "); out.println(" " ); -// out.println(" "); + out.println(" "); out.println(""); } diff --git a/src/java/org/ufcspa/simdecs/comunicacao/MetodoGravaLog.java b/src/java/org/ufcspa/simdecs/comunicacao/MetodoGravaLog.java index c008952..8fdd8ad 100644 --- a/src/java/org/ufcspa/simdecs/comunicacao/MetodoGravaLog.java +++ b/src/java/org/ufcspa/simdecs/comunicacao/MetodoGravaLog.java @@ -28,8 +28,10 @@ public class MetodoGravaLog extends BaseComunicacao { return Long.parseLong(id); } - private void registraLog(EntityManager em, SessaoUsuario sessaoUsuario, String pUID, boolean desmarcado) { + private String registraLog(EntityManager em, SessaoUsuario sessaoUsuario, String pUID, boolean desmarcado) { + String taticaPedagogica=null; + // Sintoma vindo de NodoPaciente if (pUID.toLowerCase().startsWith("sintoma-np-")) { NodoPaciente nodoPaciente = em.find(NodoPaciente.class, getIdFromUID(pUID, "sintoma-np-")); @@ -47,10 +49,12 @@ public class MetodoGravaLog extends BaseComunicacao { log.setPaciente(nodoPaciente.getPaciente()); log.setRede(nodoPaciente.getPaciente().getRede()); log.setTipo(em.find(TipoEventoLog.class, TipoEventoLog.PERGUNTA_SINAL_SINTOMA)); - log.setDescricao("CLICOU SOBRE SINAL/SINTOMA INDICADO PELO PROFESSOR!"); em.persist(log); em.getTransaction().commit(); + + if (nodoPaciente.getNodo().getTaticaPedagogica() != null && nodoPaciente.getNodo().getTaticaPedagogica() != "") + taticaPedagogica = nodoPaciente.getNodo().getTaticaPedagogica(); } // Sintoma vindo de Nodo @@ -71,9 +75,11 @@ public class MetodoGravaLog extends BaseComunicacao { log.setRede(paciente.getRede()); log.setPaciente(paciente); log.setTipo(em.find(TipoEventoLog.class, TipoEventoLog.PERGUNTA_SINAL_SINTOMA)); - log.setDescricao("CLICOU SOBRE SINAL/SINTOMA NAO INDICADO PELO PROFESSOR!"); em.persist(log); + if (nodo.getTaticaPedagogica() != null && nodo.getTaticaPedagogica() != "") + taticaPedagogica = nodo.getTaticaPedagogica(); + em.getTransaction().commit(); } @@ -94,10 +100,12 @@ public class MetodoGravaLog extends BaseComunicacao { log.setPaciente(nodoPaciente.getPaciente()); log.setRede(nodoPaciente.getPaciente().getRede()); log.setTipo(em.find(TipoEventoLog.class, TipoEventoLog.SOLICITA_EXAME_FISICO)); - log.setDescricao("CLICOU SOBRE EXAME FISICO INDICADO PELO PROFESSOR!"); em.persist(log); em.getTransaction().commit(); + + if (nodoPaciente.getNodo().getTaticaPedagogica() != null && nodoPaciente.getNodo().getTaticaPedagogica() != "") + taticaPedagogica = nodoPaciente.getNodo().getTaticaPedagogica(); } @@ -118,10 +126,12 @@ public class MetodoGravaLog extends BaseComunicacao { log.setPaciente(nodoPaciente.getPaciente()); log.setRede(nodoPaciente.getPaciente().getRede()); log.setTipo(em.find(TipoEventoLog.class, TipoEventoLog.SOLICITA_EXAME_COMPLEMENTAR)); - log.setDescricao("CLICOU SOBRE EXAME COMPLEMENTAR INDICADO PELO PROFESSOR!"); em.persist(log); em.getTransaction().commit(); + + if (nodoPaciente.getNodo().getTaticaPedagogica() != null && nodoPaciente.getNodo().getTaticaPedagogica() != "") + taticaPedagogica = nodoPaciente.getNodo().getTaticaPedagogica(); } // Historico médico if (pUID.toLowerCase().startsWith("historico-medico-")) { @@ -139,7 +149,6 @@ public class MetodoGravaLog extends BaseComunicacao { log.setPaciente(paciente); log.setRede(paciente.getRede()); log.setTipo(em.find(TipoEventoLog.class, TipoEventoLog.PERGUNTA_HISTORICO)); - log.setDescricao("CLICOU SOBRE O HISTORICO INDICADO PELO PROFESSOR!"); em.persist(log); em.getTransaction().commit(); @@ -163,10 +172,11 @@ public class MetodoGravaLog extends BaseComunicacao { log.setPaciente(paciente); log.setRede(paciente.getRede()); log.setTipo(em.find(TipoEventoLog.class, TipoEventoLog.SELECIONA_DIAGNOSTICO)); - log.setDescricao("SELECIONOU O DIAGNOSTICO"); em.persist(log); em.getTransaction().commit(); + if (nodo.getTaticaPedagogica() != null && nodo.getTaticaPedagogica() != "") + taticaPedagogica = nodo.getTaticaPedagogica(); } // Conduta @@ -187,12 +197,14 @@ public class MetodoGravaLog extends BaseComunicacao { log.setPaciente(paciente); log.setRede(paciente.getRede()); log.setTipo(em.find(TipoEventoLog.class, TipoEventoLog.SELECIONA_CONDUTA)); - log.setDescricao("SELECIONOU A CONDUTA"); em.persist(log); em.getTransaction().commit(); + if (nodo.getTaticaPedagogica() != null && nodo.getTaticaPedagogica() != "") + taticaPedagogica = nodo.getTaticaPedagogica(); } + return taticaPedagogica; } @Override @@ -207,7 +219,7 @@ public class MetodoGravaLog extends BaseComunicacao { String pDesmarcado = request.getParameter("desmarcado"); boolean desmarcado = false; - if (pDesmarcado != null && !pDesmarcado.equals("")) { + if (pDesmarcado != null && pDesmarcado.equals("true")) { desmarcado = true; } @@ -216,7 +228,7 @@ public class MetodoGravaLog extends BaseComunicacao { return; } - registraLog(em, sessaoUsuario, pUID, desmarcado); + String taticaPedagocica = registraLog(em, sessaoUsuario, pUID, desmarcado); out.println(""); @@ -231,9 +243,12 @@ public class MetodoGravaLog extends BaseComunicacao { //if (isPar) // out.println(" "); //else - out.println(" "); + if (taticaPedagocica != null && !taticaPedagocica.equals("")) + out.println(" "); + else + out.println(" "); + out.println(" " ); -// out.println(" "); out.println(""); } diff --git a/src/java/org/ufcspa/simdecs/comunicacao/MetodoIniciaCaso.java b/src/java/org/ufcspa/simdecs/comunicacao/MetodoIniciaCaso.java index 4b336c1..4dcd11c 100644 --- a/src/java/org/ufcspa/simdecs/comunicacao/MetodoIniciaCaso.java +++ b/src/java/org/ufcspa/simdecs/comunicacao/MetodoIniciaCaso.java @@ -13,9 +13,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.ufcspa.simdecs.entities.*; import org.ufcspa.simdecs.util.DbUtil; -import org.ufcspa.simdecs.util.NodoBean; -import org.ufcspa.simdecs.util.UnBUtil; +import org.ufcspa.simdecs.util.UnBBayesUtil; import unbbayes.prs.bn.ProbabilisticNode; +import unbbayes.prs.bn.TreeVariable; /** * @@ -41,10 +41,11 @@ public class MetodoIniciaCaso extends BaseComunicacao { } - private String getRespostaNodo(Nodo nodo, Paciente paciente) { + private String getRespostaNodo(Nodo nodo, Paciente paciente) throws Exception { EntityManager em = DbUtil.getInstance().getEntityManager(); - UnBUtil unBUtil = UnBUtil.getInstance(paciente.getRede()); + + UnBBayesUtil unBUtil = new UnBBayesUtil(paciente.getRede()); unBUtil.abreRede(paciente.getRede()); Iterator it = em.createQuery("From NodoPaciente Where paciente.id=:pIdPaciente") @@ -63,8 +64,8 @@ public class MetodoIniciaCaso extends BaseComunicacao { continue; } - ProbabilisticNode pn = unBUtil.getNodeByName(nodoPac.getNodo().getNome()); - unBUtil.ativarNodo(pn); + ProbabilisticNode pn = (ProbabilisticNode) unBUtil.getNodeByName(nodoPac.getNodo().getNome()); + unBUtil.setNodeState(pn, "Yes", 1, "Not", 0); } @@ -73,8 +74,7 @@ public class MetodoIniciaCaso extends BaseComunicacao { pcProbabilidade = (int) (1+Math.random()*50); } else { - NodoBean nodoBean = unBUtil.getNodoBeanByNodo(nodo); - pcProbabilidade = nodoBean.getPercentualProbabilidade(); + pcProbabilidade = unBUtil.getProbabilidadeByState((TreeVariable) unBUtil.getNodeByName(nodo.getNome()), "Yes") * 100; } List respostas = em.createQuery("From RespostaNodo where nodo.id=:pIdNodo") diff --git a/src/java/org/ufcspa/simdecs/comunicacao/MetodoRegistraAcao.java b/src/java/org/ufcspa/simdecs/comunicacao/MetodoRegistraAcao.java index dbfd2b9..f284af4 100644 --- a/src/java/org/ufcspa/simdecs/comunicacao/MetodoRegistraAcao.java +++ b/src/java/org/ufcspa/simdecs/comunicacao/MetodoRegistraAcao.java @@ -89,8 +89,8 @@ public class MetodoRegistraAcao extends BaseComunicacao { NegociacaoPedagogica negociacaoPedagogica = new NegociacaoPedagogica(pIdSessao, paciente); out.println(""); - out.println(" "); -// out.println(" "); +// out.println(" "); + out.println(" "); out.println(" " ); out.println(""); diff --git a/src/java/org/ufcspa/simdecs/entities/Caso.java b/src/java/org/ufcspa/simdecs/entities/Caso.java index a0e26ab..7e93c9a 100644 --- a/src/java/org/ufcspa/simdecs/entities/Caso.java +++ b/src/java/org/ufcspa/simdecs/entities/Caso.java @@ -108,7 +108,6 @@ public class Caso implements Serializable { @Override public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Caso)) { return false; } diff --git a/src/java/org/ufcspa/simdecs/entities/DependenciaNodo.java b/src/java/org/ufcspa/simdecs/entities/DependenciaNodo.java index 346cd19..615bf3f 100644 --- a/src/java/org/ufcspa/simdecs/entities/DependenciaNodo.java +++ b/src/java/org/ufcspa/simdecs/entities/DependenciaNodo.java @@ -56,7 +56,6 @@ public class DependenciaNodo implements Serializable { @Override public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof DependenciaNodo)) { return false; } diff --git a/src/java/org/ufcspa/simdecs/entities/IntervaloTabelaResposta.java b/src/java/org/ufcspa/simdecs/entities/IntervaloTabelaResposta.java index c405dd2..8e6cd2a 100644 --- a/src/java/org/ufcspa/simdecs/entities/IntervaloTabelaResposta.java +++ b/src/java/org/ufcspa/simdecs/entities/IntervaloTabelaResposta.java @@ -83,7 +83,6 @@ public class IntervaloTabelaResposta implements Serializable { @Override public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof IntervaloTabelaResposta)) { return false; } diff --git a/src/java/org/ufcspa/simdecs/entities/IntervencaoPedagogica.java b/src/java/org/ufcspa/simdecs/entities/IntervencaoPedagogica.java new file mode 100644 index 0000000..e993426 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/entities/IntervencaoPedagogica.java @@ -0,0 +1,140 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.ufcspa.simdecs.entities; + +import java.io.Serializable; +import java.util.Date; +import javax.persistence.*; + +/** + * + * @author maroni + */ +@Entity +@Table(name="Intervencao_Pedagogica", uniqueConstraints={@UniqueConstraint(columnNames={"sessao_id", "estrategia", "resultado"})}) +public class IntervencaoPedagogica implements Serializable { + + @Id + @SequenceGenerator(name="seqIntervencaoPedagogica", sequenceName="SQ_INTERVENCAO_PEDAGOGICA") + @GeneratedValue(strategy=GenerationType.AUTO, generator="seqIntervencaoPedagogica") + private Long id; + + @ManyToOne + @JoinColumn(name="sessao_id", nullable=false) + private SessaoUsuario sessaoUsuario; + + @Column(length=30, nullable=false) + private String estrategia; + + @Column(length=30, nullable=false) + private String resultado; + + @ManyToOne + @JoinColumn(name="tatica_id", nullable=false) + private TaticaPedagogica tatica; + + @Temporal(TemporalType.TIMESTAMP) + @Column(nullable=false) + private Date dataGeracao; + + @Column(nullable=false) + private boolean aplicada; + + public boolean isAplicada() { + return aplicada; + } + + public void setAplicada(boolean aplicada) { + this.aplicada = aplicada; + } + + public Date getDataGeracao() { + return dataGeracao; + } + + public void setDataGeracao(Date dataGeracao) { + this.dataGeracao = dataGeracao; + } + + public String getEstrategia() { + return estrategia; + } + + public void setEstrategia(String estrategia) { + this.estrategia = estrategia; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getResultado() { + return resultado; + } + + public void setResultado(String resultado) { + this.resultado = resultado; + } + + public SessaoUsuario getSessaoUsuario() { + return sessaoUsuario; + } + + public void setSessaoUsuario(SessaoUsuario sessaoUsuario) { + this.sessaoUsuario = sessaoUsuario; + } + + public TaticaPedagogica getTatica() { + return tatica; + } + + public void setTatica(TaticaPedagogica tatica) { + this.tatica = tatica; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final IntervencaoPedagogica other = (IntervencaoPedagogica) obj; + if (this.sessaoUsuario != other.sessaoUsuario && (this.sessaoUsuario == null || !this.sessaoUsuario.equals(other.sessaoUsuario))) { + return false; + } + if ((this.estrategia == null) ? (other.estrategia != null) : !this.estrategia.equals(other.estrategia)) { + return false; + } + if ((this.resultado == null) ? (other.resultado != null) : !this.resultado.equals(other.resultado)) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 43 * hash + (this.sessaoUsuario != null ? this.sessaoUsuario.hashCode() : 0); + hash = 43 * hash + (this.estrategia != null ? this.estrategia.hashCode() : 0); + hash = 43 * hash + (this.resultado != null ? this.resultado.hashCode() : 0); + return hash; + } + + @Override + public String toString() { + return "IntervencaoPedagogica{" + "id=" + id + ", sessaoUsuario=" + sessaoUsuario + ", estrategia=" + estrategia + ", resultado=" + resultado + ", tatica=" + tatica + ", dataGeracao=" + dataGeracao + ", aplicada=" + aplicada + '}'; + } + + public IntervencaoPedagogica() { + } + + +} diff --git a/src/java/org/ufcspa/simdecs/entities/Log.java b/src/java/org/ufcspa/simdecs/entities/Log.java index a69e20f..0e0e4af 100644 --- a/src/java/org/ufcspa/simdecs/entities/Log.java +++ b/src/java/org/ufcspa/simdecs/entities/Log.java @@ -34,7 +34,7 @@ public class Log implements Serializable { @SequenceGenerator(name="seqLog", sequenceName="SQLOG") @GeneratedValue(strategy=GenerationType.AUTO, generator="seqLog") @Column(name = "idlog", nullable=false) - private Integer id; + private Long id; @Column(nullable=false) @Temporal(TemporalType.TIMESTAMP) @@ -151,11 +151,11 @@ public class Log implements Serializable { this.descricao = descricao; } - public Integer getId() { + public Long getId() { return id; } - public void setId(Integer id) { + public void setId(Long id) { this.id = id; } diff --git a/src/java/org/ufcspa/simdecs/entities/Nodo.java b/src/java/org/ufcspa/simdecs/entities/Nodo.java index 1929c78..16c3ff6 100644 --- a/src/java/org/ufcspa/simdecs/entities/Nodo.java +++ b/src/java/org/ufcspa/simdecs/entities/Nodo.java @@ -13,6 +13,10 @@ import javax.persistence.*; * @author maroni */ @Entity +@NamedQueries( { + @NamedQuery(name="Nodo.all", query="From Nodo"), + @NamedQuery(name="Nodo.getByTipo", query="From Nodo where tipo=:pTipo") + }) public class Nodo implements Serializable, IdHolder, Comparable { public static final String SINAL_SINTOMA = "SINAL_SINTOMA"; diff --git a/src/java/org/ufcspa/simdecs/entities/NodoPaciente.java b/src/java/org/ufcspa/simdecs/entities/NodoPaciente.java index e6e7df9..dcdbb73 100644 --- a/src/java/org/ufcspa/simdecs/entities/NodoPaciente.java +++ b/src/java/org/ufcspa/simdecs/entities/NodoPaciente.java @@ -50,7 +50,6 @@ public class NodoPaciente implements Serializable { @Override public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof NodoPaciente)) { return false; } diff --git a/src/java/org/ufcspa/simdecs/entities/Paciente.java b/src/java/org/ufcspa/simdecs/entities/Paciente.java index 3c35df3..2c1664a 100644 --- a/src/java/org/ufcspa/simdecs/entities/Paciente.java +++ b/src/java/org/ufcspa/simdecs/entities/Paciente.java @@ -88,7 +88,6 @@ public class Paciente implements Serializable { @Override public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Paciente)) { return false; } diff --git a/src/java/org/ufcspa/simdecs/entities/Rede.java b/src/java/org/ufcspa/simdecs/entities/Rede.java index 289db95..1f6e4ff 100644 --- a/src/java/org/ufcspa/simdecs/entities/Rede.java +++ b/src/java/org/ufcspa/simdecs/entities/Rede.java @@ -57,7 +57,6 @@ public class Rede implements Serializable, IdHolder, Comparable { @Override public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Rede)) { return false; } diff --git a/src/java/org/ufcspa/simdecs/entities/RedeAluno.java b/src/java/org/ufcspa/simdecs/entities/RedeAluno.java index 2f823a5..0f93503 100644 --- a/src/java/org/ufcspa/simdecs/entities/RedeAluno.java +++ b/src/java/org/ufcspa/simdecs/entities/RedeAluno.java @@ -48,7 +48,6 @@ public class RedeAluno implements Serializable { @Override public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof RedeAluno)) { return false; } diff --git a/src/java/org/ufcspa/simdecs/entities/SessaoUsuario.java b/src/java/org/ufcspa/simdecs/entities/SessaoUsuario.java index 5edd227..8abd3f8 100644 --- a/src/java/org/ufcspa/simdecs/entities/SessaoUsuario.java +++ b/src/java/org/ufcspa/simdecs/entities/SessaoUsuario.java @@ -54,7 +54,6 @@ public class SessaoUsuario implements Serializable { @Override public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof SessaoUsuario)) { return false; } diff --git a/src/java/org/ufcspa/simdecs/entities/SinonimoResposta.java b/src/java/org/ufcspa/simdecs/entities/SinonimoResposta.java index 47f54c4..7b57c41 100644 --- a/src/java/org/ufcspa/simdecs/entities/SinonimoResposta.java +++ b/src/java/org/ufcspa/simdecs/entities/SinonimoResposta.java @@ -52,7 +52,6 @@ public class SinonimoResposta implements Serializable { @Override public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof SinonimoResposta)) { return false; } diff --git a/src/java/org/ufcspa/simdecs/entities/TabelaResposta.java b/src/java/org/ufcspa/simdecs/entities/TabelaResposta.java index 8daa599..a729712 100644 --- a/src/java/org/ufcspa/simdecs/entities/TabelaResposta.java +++ b/src/java/org/ufcspa/simdecs/entities/TabelaResposta.java @@ -51,7 +51,6 @@ public class TabelaResposta implements Serializable { @Override public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof TabelaResposta)) { return false; } diff --git a/src/java/org/ufcspa/simdecs/entities/TaticaPedagogica.java b/src/java/org/ufcspa/simdecs/entities/TaticaPedagogica.java index 048b0c3..3fa2013 100644 --- a/src/java/org/ufcspa/simdecs/entities/TaticaPedagogica.java +++ b/src/java/org/ufcspa/simdecs/entities/TaticaPedagogica.java @@ -5,17 +5,14 @@ package org.ufcspa.simdecs.entities; import java.io.Serializable; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; +import javax.persistence.*; /** * * @author maroni */ @Entity +@Table(name="Tatica_Pedagogica", uniqueConstraints={@UniqueConstraint(columnNames={"estrategia", "resultado"})}) public class TaticaPedagogica implements Serializable { private static final long serialVersionUID = 1L; @@ -31,10 +28,10 @@ public class TaticaPedagogica implements Serializable { this.id = id; } - @Column(length=10, nullable=false) - private String problema; + @Column(length=30, nullable=false) + private String resultado; - @Column(length=10, nullable=false) + @Column(length=30, nullable=false) private String estrategia; @Column(length=200, nullable=false) @@ -52,7 +49,6 @@ public class TaticaPedagogica implements Serializable { @Override public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof TaticaPedagogica)) { return false; } @@ -92,14 +88,12 @@ public class TaticaPedagogica implements Serializable { this.mensagem = mensagem; } - public String getProblema() { - return problema; + public String getResultado() { + return resultado; } - public void setProblema(String problema) { - this.problema = problema; + public void setResultado(String resultado) { + this.resultado = resultado; } - - } diff --git a/src/java/org/ufcspa/simdecs/entities/Usuario.java b/src/java/org/ufcspa/simdecs/entities/Usuario.java index 3c8afdf..ff7a7d7 100644 --- a/src/java/org/ufcspa/simdecs/entities/Usuario.java +++ b/src/java/org/ufcspa/simdecs/entities/Usuario.java @@ -78,7 +78,6 @@ public class Usuario implements Serializable { @Override public boolean equals(Object object) { - // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof Usuario)) { return false; } diff --git a/src/java/org/ufcspa/simdecs/exceptions/InvalidNodeState.java b/src/java/org/ufcspa/simdecs/exceptions/InvalidNodeState.java new file mode 100644 index 0000000..67e7a64 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/exceptions/InvalidNodeState.java @@ -0,0 +1,17 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.ufcspa.simdecs.exceptions; + +/** + * + * @author maroni + */ +public class InvalidNodeState extends Exception { + + public InvalidNodeState(String string) { + super(string); + } + +} diff --git a/src/java/org/ufcspa/simdecs/exceptions/InvalidParameterException.java b/src/java/org/ufcspa/simdecs/exceptions/InvalidParameterException.java new file mode 100644 index 0000000..fe3f134 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/exceptions/InvalidParameterException.java @@ -0,0 +1,17 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.ufcspa.simdecs.exceptions; + +/** + * + * @author maroni + */ +public class InvalidParameterException extends Exception { + + public InvalidParameterException(String string) { + super(string); + } + +} diff --git a/src/java/org/ufcspa/simdecs/mb/editarcasos/EditarCasoBean.java b/src/java/org/ufcspa/simdecs/mb/editarcasos/EditarCasoBean.java index bc6f06a..ecb8819 100644 --- a/src/java/org/ufcspa/simdecs/mb/editarcasos/EditarCasoBean.java +++ b/src/java/org/ufcspa/simdecs/mb/editarcasos/EditarCasoBean.java @@ -4,11 +4,8 @@ */ package org.ufcspa.simdecs.mb.editarcasos; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import org.ufcspa.simdecs.util.NodoBean; +import java.util.*; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import org.primefaces.component.commandbutton.CommandButton; @@ -20,9 +17,11 @@ import org.ufcspa.simdecs.entities.Paciente; import org.ufcspa.simdecs.entities.PerguntaNodo; import org.ufcspa.simdecs.entities.Rede; import org.ufcspa.simdecs.mb.DefaultManagedBean; -import org.ufcspa.simdecs.util.NodoBean; -import org.ufcspa.simdecs.util.UnBUtil; +import org.ufcspa.simdecs.util.ProbabilisticBean; +import org.ufcspa.simdecs.util.UnBBayesUtil; +import unbbayes.prs.Node; import unbbayes.prs.bn.ProbabilisticNode; +import unbbayes.prs.bn.TreeVariable; /** * @@ -198,78 +197,135 @@ public class EditarCasoBean extends DefaultManagedBean { addInfoMessage("Salvo com Sucesso!", "Caso clínico salvo com sucesso!"); } - public void processaRede() { + public void processaRede() throws Exception { idPaciente = Long.valueOf(getTextParameter("pIdPaciente")); Paciente paciente = em.find(Paciente.class, idPaciente); - UnBUtil unBUtil = UnBUtil.getInstance(paciente.getRede()); - unBUtil.abreRede(paciente.getRede()); + UnBBayesUtil unBUtil = new UnBBayesUtil(paciente.getRede()); // Sinais e Sintomas Iterator it = sinaisSintomas.getSource().iterator(); while(it.hasNext()) { - ProbabilisticNode pn = unBUtil.getNodeByName((String) it.next()); + ProbabilisticNode pn = (ProbabilisticNode) unBUtil.getNodeByName((String) it.next()); if (pn != null) - unBUtil.desativarNodo(pn); + unBUtil.setNodeState(pn, "Yes", 0, "Not", 1); } it = sinaisSintomas.getTarget().iterator(); while(it.hasNext()) { - ProbabilisticNode pn = unBUtil.getNodeByName((String) it.next()); + ProbabilisticNode pn = (ProbabilisticNode) unBUtil.getNodeByName((String) it.next()); if (pn != null) - unBUtil.ativarNodo(pn); + unBUtil.setNodeState(pn, "Yes", 1, "Not", 0); } // Historicos it = historicos.getSource().iterator(); while(it.hasNext()) { - ProbabilisticNode pn = unBUtil.getNodeByName((String) it.next()); + ProbabilisticNode pn = (ProbabilisticNode) unBUtil.getNodeByName((String) it.next()); if (pn != null) - unBUtil.desativarNodo(pn); + unBUtil.setNodeState(pn, "Yes", 0, "Not", 1); } it = historicos.getTarget().iterator(); while(it.hasNext()) { - ProbabilisticNode pn = unBUtil.getNodeByName((String) it.next()); + ProbabilisticNode pn = (ProbabilisticNode) unBUtil.getNodeByName((String) it.next()); if (pn != null) - unBUtil.ativarNodo(pn); + unBUtil.setNodeState(pn, "Yes", 1, "Not", 0); } // Exames Físicos it = examesFisicos.getSource().iterator(); while(it.hasNext()) { - ProbabilisticNode pn = unBUtil.getNodeByName((String) it.next()); + ProbabilisticNode pn = (ProbabilisticNode) unBUtil.getNodeByName((String) it.next()); if (pn != null) - unBUtil.desativarNodo(pn); + unBUtil.setNodeState(pn, "Yes", 0, "Not", 1); } it = examesFisicos.getTarget().iterator(); while(it.hasNext()) { - ProbabilisticNode pn = unBUtil.getNodeByName((String) it.next()); + ProbabilisticNode pn = (ProbabilisticNode) unBUtil.getNodeByName((String) it.next()); if (pn != null) - unBUtil.ativarNodo(pn); + unBUtil.setNodeState(pn, "Yes", 1, "Not", 0); } // Exames Complementares it = examesComplementares.getSource().iterator(); while(it.hasNext()) { - ProbabilisticNode pn = unBUtil.getNodeByName((String) it.next()); + ProbabilisticNode pn = (ProbabilisticNode) unBUtil.getNodeByName((String) it.next()); if (pn != null) - unBUtil.desativarNodo(pn); + unBUtil.setNodeState(pn, "Yes", 0, "Not", 1); } it = examesComplementares.getTarget().iterator(); while(it.hasNext()) { - ProbabilisticNode pn = unBUtil.getNodeByName((String) it.next()); + ProbabilisticNode pn = (ProbabilisticNode) unBUtil.getNodeByName((String) it.next()); if (pn != null) - unBUtil.ativarNodo(pn); + unBUtil.setNodeState(pn, "Yes", 1, "Not", 0); } - diagnosticos = unBUtil.getProbabilidadeDiagnosticos(); - condutas = unBUtil.getProbabilidadeCondutas(); + populaProbabilidadeDiagnosticos(unBUtil); + populaProbabilidadeCondutas(unBUtil); + } + + + private void populaProbabilidadeCondutas(UnBBayesUtil unBUtil) { + Iterator itConds = em.createNamedQuery("Nodo.getByTipo") + .setParameter("pTipo", Nodo.CONDUTA) + .getResultList().iterator(); + + condutas = new ArrayList(); + + while(itConds.hasNext()) { + Nodo nodo = itConds.next(); + NodoBean nodoBean = new NodoBean(nodo, (Float) unBUtil.getProbabilidadeByState((TreeVariable) unBUtil.getNodeByName(nodo.getNome()), "Yes")); + condutas.add(nodoBean); + } + + Collections.sort(condutas, new Comparator() { + @Override + public int compare(Object o1, Object o2) { + NodoBean nodo1 = (NodoBean) o1; + NodoBean nodo2 = (NodoBean) o2; + + if (nodo1.getProbabilidade() > nodo2.getProbabilidade()) + return -1; + else if (nodo1.getProbabilidade() < nodo2.getProbabilidade()) + return 1; + else + return 0; + } + }); } + private void populaProbabilidadeDiagnosticos(UnBBayesUtil unBUtil) { + Iterator itDiags = em.createNamedQuery("Nodo.getByTipo") + .setParameter("pTipo", Nodo.DIAGNOSTICO) + .getResultList().iterator(); + + diagnosticos = new ArrayList(); + + while(itDiags.hasNext()) { + Nodo nodo = itDiags.next(); + NodoBean nodoBean = new NodoBean(nodo, (Float) unBUtil.getProbabilidadeByState((TreeVariable) unBUtil.getNodeByName(nodo.getNome()), "Yes")); + diagnosticos.add(nodoBean); + } + + Collections.sort(diagnosticos, new Comparator() { + @Override + public int compare(Object o1, Object o2) { + NodoBean nodo1 = (NodoBean) o1; + NodoBean nodo2 = (NodoBean) o2; + + if (nodo1.getProbabilidade() > nodo2.getProbabilidade()) + return -1; + else if (nodo1.getProbabilidade() < nodo2.getProbabilidade()) + return 1; + else + return 0; + } + }); + } private String getPerguntaNodo(Long idNodo) { List perguntas = em.createQuery("From PerguntaNodo where nodo.id=:pIdNodo") @@ -348,7 +404,7 @@ public class EditarCasoBean extends DefaultManagedBean { populate(); } - public void selecionaPaciente() { + public void selecionaPaciente() throws Exception { Paciente paciente = em.find(Paciente.class, Long.valueOf(getTextParameter("pIdPaciente"))); idPaciente = paciente.getId(); @@ -406,10 +462,10 @@ public class EditarCasoBean extends DefaultManagedBean { examesFisicos = new DualListModel(origemExamesFisicos, destinoExamesFisicos); examesComplementares = new DualListModel(origemExamesComplementares, destinoExamesComplementares); - UnBUtil unBUtil = UnBUtil.getInstance(paciente.getRede()); + // UnBBayesUtil unBUtil = new UnBBayesUtil(paciente.getRede()); - diagnosticos = unBUtil.getProbabilidadeDiagnosticos(); - condutas = unBUtil.getProbabilidadeCondutas(); + // populaProbabilidadeDiagnosticos(unBUtil); + // populaProbabilidadeCondutas(unBUtil); } public Caso getCaso() { diff --git a/src/java/org/ufcspa/simdecs/mb/editarcasos/LoginBean.java b/src/java/org/ufcspa/simdecs/mb/editarcasos/LoginBean.java index c8d0893..98c47e2 100644 --- a/src/java/org/ufcspa/simdecs/mb/editarcasos/LoginBean.java +++ b/src/java/org/ufcspa/simdecs/mb/editarcasos/LoginBean.java @@ -15,7 +15,7 @@ import org.ufcspa.simdecs.mb.DefaultManagedBean; * * @author maroni */ -@ManagedBean +@ManagedBean(name="loginBean") @RequestScoped public class LoginBean extends DefaultManagedBean { diff --git a/src/java/org/ufcspa/simdecs/mediador/LogExecucao.java b/src/java/org/ufcspa/simdecs/mediador/LogExecucao.java index dbdbd6e..3b9ca65 100644 --- a/src/java/org/ufcspa/simdecs/mediador/LogExecucao.java +++ b/src/java/org/ufcspa/simdecs/mediador/LogExecucao.java @@ -4,8 +4,10 @@ */ package org.ufcspa.simdecs.mediador; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import javax.persistence.EntityManager; import org.ufcspa.simdecs.entities.Log; @@ -21,31 +23,31 @@ public class LogExecucao { private String confiancaAtual; private boolean abriuFichaPaciente; - private int perguntasRealizadas; - private int perguntasDisponiveis; - private int perguntasProfessor; - private int perguntasBogusRealizadas; - private int examesFisicosRealizados; - private int examesFisicosProfessor; - private int examesFisicosDisponiveis; - private int examesComplementaresRealizados; - private int examesComplementaresProfessor; - private int examesComplementaresDisponiveis; - private int desmarcacoesDiagnostico; - private int desmarcacoesConduta; + private float perguntasRealizadas; + private float perguntasDisponiveis; + private float perguntasProfessor; + private float perguntasBogusRealizadas; + private float examesFisicosRealizados; + private float examesFisicosProfessor; + private float examesFisicosDisponiveis; + private float examesComplementaresRealizados; + private float examesComplementaresProfessor; + private float examesComplementaresDisponiveis; + private float desmarcacoesDiagnostico; + private float desmarcacoesConduta; private float examesComplementaresCustoTotal; private float examesComplementaresCustoProfessor; private float examesComplementaresCustoRealizado; - private int examesComplementaresTempoTotal; - private int examesComplementaresTempoProfessor; - private int examesComplementaresTempoRealizado; + private float examesComplementaresTempoTotal; + private float examesComplementaresTempoProfessor; + private float examesComplementaresTempoRealizado; private float examesFisicosCustoTotal; private float examesFisicosCustoProfessor; private float examesFisicosCustoRealizado; - private int examesFisicosTempoTotal; - private int examesFisicosTempoProfessor; - private int examesFisicosTempoRealizado; + private float examesFisicosTempoTotal; + private float examesFisicosTempoProfessor; + private float examesFisicosTempoRealizado; private boolean concluiuInvestigacao; private boolean concluiuDiagnostico; @@ -55,6 +57,7 @@ public class LogExecucao { private Nodo diagnostico; private Map condutas; + private List nodosInvestigacao; private EntityManager em; @@ -79,6 +82,7 @@ public class LogExecucao { confiancaAtual = ""; concluiuInvestigacao = concluiuDiagnostico = concluiuConduta = encerrouCaso = abriuFichaPaciente = false; + nodosInvestigacao = new ArrayList(); em = DbUtil.getInstance().getEntityManager(); @@ -107,8 +111,10 @@ public class LogExecucao { if (log.getNodo().getBogus()) perguntasBogusRealizadas+=1; - else + else { perguntasRealizadas+=1; + nodosInvestigacao.add(log.getNodo()); + } } // Registra encerramento de etapas @@ -136,6 +142,7 @@ public class LogExecucao { examesFisicosRealizados+=1; examesFisicosCustoRealizado+=log.getNodo().getCusto(); examesFisicosTempoRealizado+=log.getNodo().getTempo(); + nodosInvestigacao.add(log.getNodo()); } // Soma os exames complementares perguntados pelo aluno @@ -143,6 +150,7 @@ public class LogExecucao { examesComplementaresRealizados+=1; examesComplementaresCustoRealizado+=log.getNodo().getCusto(); examesComplementaresTempoRealizado+=log.getNodo().getTempo(); + nodosInvestigacao.add(log.getNodo()); } // Soma as desmarcações de diagnósticos @@ -226,80 +234,40 @@ public class LogExecucao { return abriuFichaPaciente; } - public String getConfiancaAtual() { - return confiancaAtual; - } - - public int getDesmarcacoesConduta() { - return desmarcacoesConduta; - } - - public int getDesmarcacoesDiagnostico() { - return desmarcacoesDiagnostico; - } - - public EntityManager getEm() { - return em; - } - - public int getExamesComplementaresDisponiveis() { - return examesComplementaresDisponiveis; - } - - public int getExamesComplementaresProfessor() { - return examesComplementaresProfessor; - } - - public int getExamesComplementaresRealizados() { - return examesComplementaresRealizados; - } - - public int getExamesFisicosDisponiveis() { - return examesFisicosDisponiveis; - } - - public int getExamesFisicosProfessor() { - return examesFisicosProfessor; + public boolean isConcluiuConduta() { + return concluiuConduta; } - public int getExamesFisicosRealizados() { - return examesFisicosRealizados; + public boolean isConcluiuDiagnostico() { + return concluiuDiagnostico; } - public int getPerguntasBogusRealizadas() { - return perguntasBogusRealizadas; + public boolean isConcluiuInvestigacao() { + return concluiuInvestigacao; } - public int getPerguntasDisponiveis() { - return perguntasDisponiveis; + public Map getCondutas() { + return condutas; } - public int getPerguntasProfessor() { - return perguntasProfessor; + public String getConfiancaAtual() { + return confiancaAtual; } - public int getPerguntasRealizadas() { - return perguntasRealizadas; + public float getDesmarcacoesConduta() { + return desmarcacoesConduta; } - public Map getCondutas() { - return condutas; + public float getDesmarcacoesDiagnostico() { + return desmarcacoesDiagnostico; } public Nodo getDiagnostico() { return diagnostico; } - public boolean isConcluiuConduta() { - return concluiuConduta; - } - - public boolean isConcluiuDiagnostico() { - return concluiuDiagnostico; - } - - public boolean isConcluiuInvestigacao() { - return concluiuInvestigacao; + public EntityManager getEm() { + return em; } public boolean isEncerrouCaso() { @@ -318,15 +286,27 @@ public class LogExecucao { return examesComplementaresCustoTotal; } - public int getExamesComplementaresTempoProfessor() { + public float getExamesComplementaresDisponiveis() { + return examesComplementaresDisponiveis; + } + + public float getExamesComplementaresProfessor() { + return examesComplementaresProfessor; + } + + public float getExamesComplementaresRealizados() { + return examesComplementaresRealizados; + } + + public float getExamesComplementaresTempoProfessor() { return examesComplementaresTempoProfessor; } - public int getExamesComplementaresTempoRealizado() { + public float getExamesComplementaresTempoRealizado() { return examesComplementaresTempoRealizado; } - public int getExamesComplementaresTempoTotal() { + public float getExamesComplementaresTempoTotal() { return examesComplementaresTempoTotal; } @@ -342,18 +322,52 @@ public class LogExecucao { return examesFisicosCustoTotal; } - public int getExamesFisicosTempoProfessor() { + public float getExamesFisicosDisponiveis() { + return examesFisicosDisponiveis; + } + + public float getExamesFisicosProfessor() { + return examesFisicosProfessor; + } + + public float getExamesFisicosRealizados() { + return examesFisicosRealizados; + } + + public float getExamesFisicosTempoProfessor() { return examesFisicosTempoProfessor; } - public int getExamesFisicosTempoRealizado() { + public float getExamesFisicosTempoRealizado() { return examesFisicosTempoRealizado; } - public int getExamesFisicosTempoTotal() { + public float getExamesFisicosTempoTotal() { return examesFisicosTempoTotal; } + public List getNodosInvestigacao() { + return nodosInvestigacao; + } + + public float getPerguntasBogusRealizadas() { + return perguntasBogusRealizadas; + } + + public float getPerguntasDisponiveis() { + return perguntasDisponiveis; + } + + public float getPerguntasProfessor() { + return perguntasProfessor; + } + + public float getPerguntasRealizadas() { + return perguntasRealizadas; + } + + + @Override public String toString() { return "LogExecucao{" + "confiancaAtual=" + confiancaAtual + "\nabriuFichaPaciente=" + abriuFichaPaciente + "\nperguntasRealizadas=" + perguntasRealizadas + "\nperguntasDisponiveis=" + perguntasDisponiveis + "\nperguntasProfessor=" + perguntasProfessor + "\nperguntasBogusRealizadas=" + perguntasBogusRealizadas + "\nexamesFisicosRealizados=" + examesFisicosRealizados + "\nexamesFisicosProfessor=" + examesFisicosProfessor + "\nexamesFisicosDisponiveis=" + examesFisicosDisponiveis + "\nexamesComplementaresRealizados=" + examesComplementaresRealizados + "\nexamesComplementaresProfessor=" + examesComplementaresProfessor + "\nexamesComplementaresDisponiveis=" + examesComplementaresDisponiveis + "\ndesmarcacoesDiagnostico=" + desmarcacoesDiagnostico + "\ndesmarcacoesConduta=" + desmarcacoesConduta + "\nexamesComplementaresCustoTotal=" + examesComplementaresCustoTotal + "\nexamesComplementaresCustoProfessor=" + examesComplementaresCustoProfessor + "\nexamesComplementaresCustoRealizado=" + examesComplementaresCustoRealizado + "\nexamesComplementaresTempoTotal=" + examesComplementaresTempoTotal + "\nexamesComplementaresTempoProfessor=" + examesComplementaresTempoProfessor + "\nexamesComplementaresTempoRealizado=" + examesComplementaresTempoRealizado + "\nexamesFisicosCustoTotal=" + examesFisicosCustoTotal + "\nexamesFisicosCustoProfessor=" + examesFisicosCustoProfessor + "\nexamesFisicosCustoRealizado=" + examesFisicosCustoRealizado + "\nexamesFisicosTempoTotal=" + examesFisicosTempoTotal + "\nexamesFisicosTempoProfessor=" + examesFisicosTempoProfessor + "\nexamesFisicosTempoRealizado=" + examesFisicosTempoRealizado + "\nconcluiuInvestigacao=" + concluiuInvestigacao + "\nconcluiuDiagnostico=" + concluiuDiagnostico + "\nconcluiuConduta=" + concluiuConduta + "\nencerrouCaso=" + encerrouCaso + "\ndiagnostico=" + diagnostico + "\ncondutas=" + condutas + '}'; diff --git a/src/java/org/ufcspa/simdecs/mediador/NegociacaoPedagogica.java b/src/java/org/ufcspa/simdecs/mediador/NegociacaoPedagogica.java index 0595dd3..12f2a2a 100644 --- a/src/java/org/ufcspa/simdecs/mediador/NegociacaoPedagogica.java +++ b/src/java/org/ufcspa/simdecs/mediador/NegociacaoPedagogica.java @@ -4,7 +4,16 @@ */ package org.ufcspa.simdecs.mediador; -import org.ufcspa.simdecs.entities.Paciente; +import java.util.*; +import javax.persistence.EntityManager; +import org.ufcspa.simdecs.entities.*; +import org.ufcspa.simdecs.util.DbUtil; +import org.ufcspa.simdecs.util.NodoBean; +import org.ufcspa.simdecs.util.ProbabilisticBean; +import org.ufcspa.simdecs.util.UnBBayesUtil; +import unbbayes.prs.bn.ProbabilisticNode; +import unbbayes.prs.bn.TreeVariable; +import unbbayes.prs.id.DecisionNode; /** * @@ -12,66 +21,454 @@ import org.ufcspa.simdecs.entities.Paciente; */ public class NegociacaoPedagogica { - - + public static final String NAO_ABRIU_FICHA_PACIENTE = "NAO_ABRIU_FICHA_PACIENTE"; + + public static final String INVESTIGACAO_ADEQUADA = "INVESTIGACAO_ADEQUADA"; public static final String INVESTIGACAO_INSUFICIENTE = "INVESTIGACAO_INSUFICIENTE"; - public static final String INVESTIGACAO_EXCESSIVA = "INVESTIGACAO_EXCESSIVA"; - public static final String INVESTIGACAO_BOGUS = "INVESTIGACAO_BOGUS"; - public static final String INVESTIGACAO_DISPENDIOSA = "INVESTIGACAO_DISPENDIOSA"; - public static final String INVESTIGACAO_DEMORADA = "INVESTIGACAO_DEMORADA"; + public static final String INVESTIGACAO_EXCESSIVA = "INVESTIGACAO_EXCESSIVA"; + public static final String INVESTIGACAO_BOGUS = "INVESTIGACAO_BOGUS"; + public static final String INVESTIGACAO_DISPENDIOSA = "INVESTIGACAO_DISPENDIOSA"; + public static final String INVESTIGACAO_DEMORADA = "INVESTIGACAO_DEMORADA"; - public static final String DIAGNOSTICO_INCORRETO_IMPLAUSIVEL = "DIAGNOSTICO_INCORRETO_IMPLAUSIVEL"; - public static final String DIAGNOSTICO_INCORRETO_PLAUSIVEL = "DIAGNOSTICO_INCORRETO_PLAUSIVEL"; + public static final String DIAGNOSTICO_ADEQUADO = "DIAGNOSTICO_ADEQUADO"; + public static final String DIAGNOSTICO_INCORRETO_IMPLAUSIVEL= "DIAGNOSTICO_INCORRETO_IMPLAUSIVEL"; + public static final String DIAGNOSTICO_INCORRETO_PLAUSIVEL = "DIAGNOSTICO_INCORRETO_PLAUSIVEL"; - public static final String CONDUTA_INCORRETA_COERENTE = "CONDUTA_INCORRETA_COERENTE"; + public static final String CONDUTA_ADEQUADA = "CONDUTA_ADEQUADA"; + public static final String CONDUTA_INCORRETA_COERENTE = "CONDUTA_INCORRETA_COERENTE"; public static final String CONDUTA_INCORRETA_INCOERENTE = "CONDUTA_INCORRETA_INCOERENTE"; - public static final String CONDUTA_INSUFICIENTE = "CONDUTA_INSUFICIENTE"; - public static final String CONDUTA_EXCESSIVA = "CONDUTA_EXCESSIVA"; - public static final String CONDUTA_DEMORADA = "CONDUTA_DEMORADA"; - public static final String CONDUTA_DISPENDIOSA = "CONDUTA_DISPENDIOSA"; + public static final String CONDUTA_INSUFICIENTE = "CONDUTA_INSUFICIENTE"; + public static final String CONDUTA_EXCESSIVA = "CONDUTA_EXCESSIVA"; + public static final String CONDUTA_DEMORADA = "CONDUTA_DEMORADA"; + public static final String CONDUTA_DISPENDIOSA = "CONDUTA_DISPENDIOSA"; + + + private LogExecucao logExecucao; + private EntityManager em; - // Anamnese - float anamneseInsuficiente; - float anamneseSuficiente; - float anamneseExcessiva; - - // Exame Físico - float exameFisicoInsuficiente; - float exameFisicoSuficiente; - float exameFisicoExcessiva; - - // Exame Complementar - float exameComplementarInsuficiente; - float exameComplementarSuficiente; - float exameComplementarExcessiva; + private String estrategia; + private List resultadosSimulacao; + + + private boolean anamneseInsuficiente = false; + private boolean anamneseExcessiva = false; + private boolean exameFisicoInsuficiente = false; + private boolean exameFisicoExcessivo = false; + private boolean exameComplementarInsuficiente = false; + private boolean exameComplementarExcessivo = false; + private boolean perguntouBogus = false; - // Abertura da Ficha do Paciente - float abriuFichaPacienteSim; - float abriuFichaPacienteNao; - // Bogus - float bogusPresente; - float bogusAusente; + private void populaEstrategia() throws Exception { + // Carrega o endereço do diagrama de influencia do banco e abre a rede no disco + Rede redeDI = em.find(Rede.class, 1000L); + UnBBayesUtil diagramaInfluencia = new UnBBayesUtil(redeDI); + + anamneseInsuficiente = false; + anamneseExcessiva = false; + exameFisicoInsuficiente = false; + exameFisicoExcessivo = false; + exameComplementarInsuficiente = false; + exameComplementarExcessivo = false; + perguntouBogus = false; + + + // Define a probabilidade do nodo Anamnese + { + if (logExecucao.getPerguntasDisponiveis() > 0) { + ProbabilisticNode nodoAnamnese = (ProbabilisticNode) diagramaInfluencia.getNodeByName("Anamnese"); + float pcPerguntasAnamnese = logExecucao.getPerguntasRealizadas() / logExecucao.getPerguntasDisponiveis() * 100; +System.out.println("PERCENTUAL ANAMNESE: " + pcPerguntasAnamnese); + if (pcPerguntasAnamnese <= 20) { + diagramaInfluencia.setNodeState(nodoAnamnese, "Insuficiente", 1, "Suficiente", 0, "Excessiva", 0); + anamneseInsuficiente = true; + } + else if (pcPerguntasAnamnese > 20 && pcPerguntasAnamnese <= 80) + diagramaInfluencia.setNodeState(nodoAnamnese, "Insuficiente", 0, "Suficiente", 1, "Excessiva", 0); + else { + diagramaInfluencia.setNodeState(nodoAnamnese, "Insuficiente", 0, "Suficiente", 0, "Excessiva", 1); + anamneseExcessiva = true; + } + } + } - // Hesitação no Diagnóstico - float hesitacaoDiagnosticoPresente; - float hesitacaoDiagnosticoAusente; + // Define a probabilidade do nodo Exame Fisico + { + if (logExecucao.getExamesFisicosDisponiveis() > 0) { + ProbabilisticNode nodoExameFisico = (ProbabilisticNode) diagramaInfluencia.getNodeByName("ExameFisico"); + float pcExameFisico = logExecucao.getExamesFisicosRealizados() / logExecucao.getExamesFisicosDisponiveis() * 100; +System.out.println("PERCENTUAL EXAME FISICO: " + pcExameFisico); + + if (pcExameFisico <= 20) { + diagramaInfluencia.setNodeState(nodoExameFisico, "Insuficiente", 1, "Suficiente", 0, "Excessiva", 0); + exameFisicoInsuficiente = true; + } + else if (pcExameFisico > 20 && pcExameFisico <= 80) + diagramaInfluencia.setNodeState(nodoExameFisico, "Insuficiente", 0, "Suficiente", 1, "Excessiva", 0); + else { + diagramaInfluencia.setNodeState(nodoExameFisico, "Insuficiente", 0, "Suficiente", 0, "Excessiva", 1); + exameFisicoExcessivo = true; + } + } + } + + // Define a probabilidade do nodo Exame Complementar + { + if (logExecucao.getExamesComplementaresProfessor() > 0) { + ProbabilisticNode nodoExameComplementar = (ProbabilisticNode) diagramaInfluencia.getNodeByName("ExameComplementar"); + float pcExameComplementar = logExecucao.getExamesComplementaresRealizados() / logExecucao.getExamesComplementaresProfessor() * 100; +System.out.println("PERCENTUAL EXAME COMPLEMENTAR: " + pcExameComplementar); + + if (pcExameComplementar <= 20) { + diagramaInfluencia.setNodeState(nodoExameComplementar, "Insuficiente", 1, "Suficiente", 0, "Excessiva", 0); + exameComplementarInsuficiente = true; + } + else if (pcExameComplementar > 20 && pcExameComplementar <= 80) + diagramaInfluencia.setNodeState(nodoExameComplementar, "Insuficiente", 0, "Suficiente", 1, "Excessiva", 0); + else { + diagramaInfluencia.setNodeState(nodoExameComplementar, "Insuficiente", 0, "Suficiente", 0, "Excessiva", 1); + exameFisicoExcessivo = true; + } + } + } + + // Define a probabilidade do nodo abriu ficha do paciente + { + ProbabilisticNode nodoAbriuFichaPaciente = (ProbabilisticNode) diagramaInfluencia.getNodeByName("AbriuFichaPaciente"); + + if (logExecucao.isAbriuFichaPaciente()) + diagramaInfluencia.setNodeState(nodoAbriuFichaPaciente, "Sim", 1, "Nao", 0); + else + diagramaInfluencia.setNodeState(nodoAbriuFichaPaciente, "Sim", 0, "Nao", 1); + } + + // Define a probabilidade do nodo Bogus + { + if (logExecucao.getPerguntasDisponiveis() > 0) { + ProbabilisticNode nodoBogus = (ProbabilisticNode) diagramaInfluencia.getNodeByName("Bogus"); + float pcNodoBogus = logExecucao.getPerguntasBogusRealizadas() / logExecucao.getPerguntasDisponiveis() * 100; +System.out.println("PERCENTUAL BOGUS: " + pcNodoBogus); - // Hesitação na Conduta - float hesitacaoCondutaPresente; - float hesitacaoCondutaAusente; + if (pcNodoBogus <= 10) + diagramaInfluencia.setNodeState(nodoBogus, "Presente", 0, "Ausente", 1); + else if (pcNodoBogus > 10 && pcNodoBogus <= 30) { + diagramaInfluencia.setNodeState(nodoBogus, "Presente", 0.4f, "Ausente", 0.6f); + perguntouBogus = true; + } + else { + diagramaInfluencia.setNodeState(nodoBogus, "Presente", 1, "Ausente", 0); + perguntouBogus = true; + } + } + } + + // Define a probabilidade de hesitação diagnostica + { + ProbabilisticNode nodoHestiacaoDiagnostico = (ProbabilisticNode) diagramaInfluencia.getNodeByName("HesitacaoDiagnostico"); + + if (logExecucao.getDesmarcacoesDiagnostico() == 0) + diagramaInfluencia.setNodeState(nodoHestiacaoDiagnostico, "Presente", 0, "Ausente", 1); + else if (logExecucao.getDesmarcacoesDiagnostico() == 1) + diagramaInfluencia.setNodeState(nodoHestiacaoDiagnostico, "Presente", 0.6f, "Ausente", 0.4f); + else + diagramaInfluencia.setNodeState(nodoHestiacaoDiagnostico, "Presente", 1, "Ausente", 0); + } + + // Define a probabilidade de hesitação na conduta + { + ProbabilisticNode nodoHestiacaoConduta = (ProbabilisticNode) diagramaInfluencia.getNodeByName("HesitacaoConduta"); + + if (logExecucao.getDesmarcacoesConduta() == 0) + diagramaInfluencia.setNodeState(nodoHestiacaoConduta, "Presente", 0, "Ausente", 1); + else if (logExecucao.getDesmarcacoesConduta() == 1) + diagramaInfluencia.setNodeState(nodoHestiacaoConduta, "Presente", 0.6f, "Ausente", 0.4f); + else + diagramaInfluencia.setNodeState(nodoHestiacaoConduta, "Presente", 1, "Ausente", 0); + } + + // Define a probabilidade de hesitação na conduta + { + ProbabilisticNode nodoConfianca = (ProbabilisticNode) diagramaInfluencia.getNodeByName("Confianca"); + + if (logExecucao.getConfiancaAtual().equals(Log.CONFIANCA_BAIXA)) + diagramaInfluencia.setNodeState(nodoConfianca, "Baixa", 1, "Media", 0, "Alta", 0); + else if (logExecucao.getConfiancaAtual().equals(Log.CONFIANCA_MEDIA)) + diagramaInfluencia.setNodeState(nodoConfianca, "Baixa", 0, "Media", 1, "Alta", 0); + else if (logExecucao.getConfiancaAtual().equals(Log.CONFIANCA_ALTA)) + diagramaInfluencia.setNodeState(nodoConfianca, "Baixa", 0, "Media", 0, "Alta", 1); + } + + // Mostra o resultado do diagrama de influencia + DecisionNode nodoTatica = (DecisionNode) diagramaInfluencia.getNodeByName("Tatica"); + List probs = diagramaInfluencia.getProbabilidadesDescOrder(nodoTatica); + + for (ProbabilisticBean prob : probs) { + estrategia = prob.getState().toUpperCase(); + break; + } + } + + public UnBBayesUtil processaRedeAluno(Paciente paciente) throws Exception { + + UnBBayesUtil unBUtil = new UnBBayesUtil(paciente.getRede()); + + List nodosPaciente = em.createQuery("From NodoPaciente np Where np.paciente.id=:pPaciente") + .setParameter("pPaciente", paciente.getId()) + .getResultList(); + + for(NodoPaciente nodo : nodosPaciente) { + ProbabilisticNode pn = (ProbabilisticNode) unBUtil.getNodeByName(nodo.getNodo().getNome()); + if (pn != null) + unBUtil.setNodeState(pn, "Yes", 1, "Not", 0); + } + + return unBUtil; + + } + + private List getProbabilidades(UnBBayesUtil unBUtil, String tipoNodo) { + Iterator itNodos = em.createNamedQuery("Nodo.getByTipo") + .setParameter("pTipo", tipoNodo) + .getResultList().iterator(); + + ArrayList nodos = new ArrayList(); + + while(itNodos.hasNext()) { + Nodo nodo = itNodos.next(); + NodoBean nodoBean = new NodoBean(nodo, (Float) unBUtil.getProbabilidadeByState((TreeVariable) unBUtil.getNodeByName(nodo.getNome()), "Yes")); + nodos.add(nodoBean); + } + + Collections.sort(nodos, new Comparator() { + @Override + public int compare(Object o1, Object o2) { + NodoBean nodo1 = (NodoBean) o1; + NodoBean nodo2 = (NodoBean) o2; + + if (nodo1.getProbabilidade() > nodo2.getProbabilidade()) + return -1; + else if (nodo1.getProbabilidade() < nodo2.getProbabilidade()) + return 1; + else + return 0; + } + }); + + return nodos; + } - // Confiança - float confiancaBaixa; - float confiancaMedia; - float confiancaAlta; - - private LogExecucao logExecucao; - public NegociacaoPedagogica(long idSessao, Paciente paciente) { + private void populaResultadoSimulacao(Paciente paciente) throws Exception { + resultadosSimulacao = new ArrayList(); + + if (logExecucao.isConcluiuInvestigacao()) { + // Verifica se abriu a ficha do paciente + if (!logExecucao.isAbriuFichaPaciente()) + resultadosSimulacao.add(NAO_ABRIU_FICHA_PACIENTE); + + // Verifica se a investigação é insuficiente ou excessiva + int fatorInsuficiente = 0; + if (anamneseInsuficiente) + fatorInsuficiente++; + if (exameComplementarInsuficiente) + fatorInsuficiente++; + if (exameFisicoInsuficiente) + fatorInsuficiente++; + + int fatorExcessivo = 0; + if (anamneseExcessiva) + fatorExcessivo++; + if (exameComplementarExcessivo) + fatorExcessivo++; + if (exameFisicoExcessivo) + fatorExcessivo++; + + if (fatorExcessivo != 0 || fatorInsuficiente != 0) { + if (fatorInsuficiente > fatorExcessivo) + resultadosSimulacao.add(INVESTIGACAO_INSUFICIENTE); + else + resultadosSimulacao.add(INVESTIGACAO_EXCESSIVA); + } + + // Verifica se é bogus + if (perguntouBogus) + resultadosSimulacao.add(INVESTIGACAO_BOGUS); + + // Verifica se a anamnese teve alto custo! + if (logExecucao.getExamesComplementaresCustoProfessor() > 0) { + float pcCusto = logExecucao.getExamesComplementaresCustoRealizado() / logExecucao.getExamesComplementaresCustoProfessor() * 100; + if (pcCusto > 150) + resultadosSimulacao.add(INVESTIGACAO_DISPENDIOSA); + } + + // Verifica se a anamnese foi demorada! + if (logExecucao.getExamesComplementaresTempoProfessor() > 0 || logExecucao.getExamesFisicosTempoProfessor() > 0) { + float pcTempo = (logExecucao.getExamesComplementaresTempoRealizado() + logExecucao.getExamesFisicosTempoRealizado()) / + (logExecucao.getExamesComplementaresTempoProfessor() + logExecucao.getExamesFisicosTempoProfessor()) * 100; + + if (pcTempo > 150) + resultadosSimulacao.add(INVESTIGACAO_DEMORADA); + } + } + + boolean diagnosticoCorreto = false; + + + // Verifica se o diagnóstico foi adequado + if (logExecucao.isConcluiuDiagnostico()) { + UnBBayesUtil redeAluno = processaRedeAluno(paciente); + List diagnosticos = getProbabilidades(redeAluno, Nodo.DIAGNOSTICO); + Nodo primeiroDiagnostico=null; + Nodo segundoDiagnostico=null; + int i=0; + for(NodoBean nodo : diagnosticos) { + if (i == 0) + primeiroDiagnostico = nodo.getNodo(); + else if (i == 1) + segundoDiagnostico = nodo.getNodo(); + + if (++i == 2) + break; + } + +System.out.println("PRIMEIRO: " + primeiroDiagnostico); +System.out.println("LOG: " + logExecucao.getDiagnostico()); + // Nao selecionou o primeiro diagnostico + if (primeiroDiagnostico != null && !logExecucao.getDiagnostico().equals(primeiroDiagnostico)) + if (segundoDiagnostico != null && logExecucao.getDiagnostico().equals(segundoDiagnostico)) + resultadosSimulacao.add(DIAGNOSTICO_INCORRETO_PLAUSIVEL); + else + resultadosSimulacao.add(DIAGNOSTICO_INCORRETO_IMPLAUSIVEL); + + // Registra se o diagnóstico está correto + if (primeiroDiagnostico.equals(logExecucao.getDiagnostico())) + diagnosticoCorreto = true; + } + + + // Ativa condutas do diagnostico proposto + if (logExecucao.isConcluiuConduta()) { + UnBBayesUtil unBUtil = new UnBBayesUtil(paciente.getRede()); + unBUtil.setNodeState((ProbabilisticNode)unBUtil.getNodeByName(logExecucao.getDiagnostico().getNome()), "Yes", 1, "Not", 0); + List condutas = getProbabilidades(unBUtil, Nodo.CONDUTA); + + + // Se o diagnóstico for incorreto verifica o tipo da conduta + if (!diagnosticoCorreto) { + + // Neste caso (diagnóstico incorreto) avalia somente a primeira conduta. + for(NodoBean nodo : condutas) { + if (logExecucao.getCondutas().containsValue(nodo.getNodo())) { + resultadosSimulacao.add(CONDUTA_INCORRETA_COERENTE); + return; + } + else { + resultadosSimulacao.add(CONDUTA_INCORRETA_INCOERENTE); + return; + } + } + } else { + // Caso o diagnostico esteja incorreto verifica se a conduta foi suficiente ou insuficiente + int i=1; + int condutasAdotadas=0; + int condutasPossiveis=0; + for(NodoBean nodo : condutas) { + condutasPossiveis++; + + if (!logExecucao.getCondutas().containsValue(nodo.getNodo())) { + if (i == 1) { + resultadosSimulacao.add(CONDUTA_INCORRETA_INCOERENTE); + return; + } + } else + condutasAdotadas++; + + if (i++ == 2) + break; + } + + if (condutasAdotadas < condutasPossiveis) + resultadosSimulacao.add(CONDUTA_INSUFICIENTE); + else if (condutasAdotadas > condutasPossiveis) + resultadosSimulacao.add(CONDUTA_EXCESSIVA); + } + + + // AVALIAR O TEMPO E CUSTO DA CONDUTA + int c=1; + float custoTotalCondutas=0; + int tempoTotalConudtas=0; + for(NodoBean nodo : condutas) { + custoTotalCondutas+=nodo.getNodo().getCusto(); + tempoTotalConudtas+=nodo.getNodo().getTempo(); + if (c++ == 2) + break; + } + + float custoRealizadoCondutas=0; + int tempoRealizadoCondutas=0; + for(Nodo nodoConduta : logExecucao.getCondutas().values()) { + custoRealizadoCondutas+=nodoConduta.getCusto(); + tempoRealizadoCondutas+=nodoConduta.getTempo(); + } + + if (custoTotalCondutas > 0) { + float pcCustoConduta = custoRealizadoCondutas / custoTotalCondutas * 100; + if (pcCustoConduta >= 150) + resultadosSimulacao.add(CONDUTA_DISPENDIOSA); + } + + + if (tempoRealizadoCondutas > 0) { + float pcTempoConduta = tempoRealizadoCondutas / tempoTotalConudtas * 100; + if (pcTempoConduta >= 150) + resultadosSimulacao.add(CONDUTA_DEMORADA); + } + + } + } + + public NegociacaoPedagogica(long idSessao, Paciente paciente) throws Exception { + em = DbUtil.getInstance().getEntityManager(); + + // Busca o log de execução logExecucao = new LogExecucao(idSessao, paciente.getCaso().getId(), paciente.getRede().getId()); System.out.println(logExecucao); + + populaEstrategia(); + populaResultadoSimulacao(paciente); + + System.out.println("ESTRATÉGIA: " + estrategia); + System.out.println("RESULTADOS:"); + + for(String resultado : resultadosSimulacao) { + System.out.println(resultado); +/* + IntervencaoPedagogica intervencao = new IntervencaoPedagogica(); + + if (!em.getTransaction().isActive()) + em.getTransaction().begin(); + + intervencao.setAplicada(false); + intervencao.setDataGeracao(new Date()); + intervencao.setEstrategia(estrategia); + intervencao.setResultado(resultado); + intervencao.setSessaoUsuario(em.find(SessaoUsuario.class, idSessao)); + + TaticaPedagogica tatica = (TaticaPedagogica) em.createQuery("From TaticaPedagogica where resultado=:pResultado and estrategia=:pEstrategia") + .setParameter("pResultado", resultado) + .setParameter("pEstrategia", estrategia) + .getSingleResult(); + intervencao.setTatica(tatica); + + em.persist(intervencao); + em.getTransaction().commit(); + +*/ + } + + } } diff --git a/src/java/org/ufcspa/simdecs/util/NodoBean.java b/src/java/org/ufcspa/simdecs/util/NodoBean.java index a95dd68..67bc1ea 100644 --- a/src/java/org/ufcspa/simdecs/util/NodoBean.java +++ b/src/java/org/ufcspa/simdecs/util/NodoBean.java @@ -4,8 +4,8 @@ */ package org.ufcspa.simdecs.util; +import java.util.ArrayList; import org.ufcspa.simdecs.entities.Nodo; -import unbbayes.prs.bn.ProbabilisticNode; /** * @@ -14,13 +14,17 @@ import unbbayes.prs.bn.ProbabilisticNode; public class NodoBean { private Nodo nodo; - private ProbabilisticNode probabilisticNode; + private float probabilidade; - public NodoBean(Nodo nodo, ProbabilisticNode probabilisticNode) { - this.nodo = nodo; - this.probabilisticNode = probabilisticNode; + public NodoBean() { } + + public NodoBean(Nodo nodo, float probabilidade) { + this.nodo = nodo; + this.probabilidade = probabilidade; + } + public Nodo getNodo() { return nodo; } @@ -29,23 +33,16 @@ public class NodoBean { this.nodo = nodo; } - public ProbabilisticNode getProbabilisticNode() { - return probabilisticNode; + public float getProbabilidade() { + return probabilidade; } - public void setProbabilisticNode(ProbabilisticNode probabilisticNode) { - this.probabilisticNode = probabilisticNode; - } - - public float getProbabilidade() { - for (int pb = 0; pb < probabilisticNode.getStatesSize(); pb++) { - if (probabilisticNode.getStateAt(pb).toLowerCase().equals("yes")) - return probabilisticNode.getMarginalAt(pb); - } - return 0; + public void setProbabilidade(float probabilidade) { + this.probabilidade = probabilidade; } public float getPercentualProbabilidade() { return Math.round(getProbabilidade() * 100); } } + diff --git a/src/java/org/ufcspa/simdecs/util/ProbabilisticBean.java b/src/java/org/ufcspa/simdecs/util/ProbabilisticBean.java new file mode 100644 index 0000000..630e841 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/util/ProbabilisticBean.java @@ -0,0 +1,36 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.ufcspa.simdecs.util; + +/** + * + * @author maroni + */ +public class ProbabilisticBean { + + private String state; + private Float probability; + + public ProbabilisticBean(String state, Float probability) { + this.state = state; + this.probability = probability; + } + + public Float getProbability() { + return probability; + } + + public void setProbability(Float probability) { + this.probability = probability; + } + + public String getState() { + return state; + } + + public void setState(String state) { + this.state = state; + } +} diff --git a/src/java/org/ufcspa/simdecs/util/UnBBayesUtil.java b/src/java/org/ufcspa/simdecs/util/UnBBayesUtil.java new file mode 100644 index 0000000..5a826f7 --- /dev/null +++ b/src/java/org/ufcspa/simdecs/util/UnBBayesUtil.java @@ -0,0 +1,170 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.ufcspa.simdecs.util; + +import java.io.File; +import java.security.InvalidParameterException; +import java.util.*; +import org.ufcspa.simdecs.entities.Rede; +import org.ufcspa.simdecs.exceptions.InvalidNodeState; +import unbbayes.io.xmlbif.version6.XMLBIFIO; +import unbbayes.prs.Node; +import unbbayes.prs.bn.JunctionTreeAlgorithm; +import unbbayes.prs.bn.ProbabilisticNetwork; +import unbbayes.prs.bn.ProbabilisticNode; +import unbbayes.prs.bn.TreeVariable; + +/** + * + * @author maroni + */ +public class UnBBayesUtil { + + + private ProbabilisticNetwork rede; + + public UnBBayesUtil(Rede redeEntity) throws Exception { + abreRede(redeEntity); + } + + public final void abreRede(Rede redeEntity) throws Exception { + // required to run unbbayes gui classes on server + System.setProperty("java.awt.headless", "false"); + rede = new ProbabilisticNetwork(null); + XMLBIFIO.loadXML(new File(redeEntity.getArquivo()), rede); + + compilar(); + } + + public void compilar() { + JunctionTreeAlgorithm jt = new JunctionTreeAlgorithm(); + jt.setNet(rede); + jt.run(); + } + + + public Node getNodeByName(String nodeName) { + for(Node node : rede.getNodes()) { + if (node.getName().toLowerCase().equals(nodeName.toLowerCase())) + return node; + } + + return null; + } + + + public void setNodeState(ProbabilisticNode node, Object ... stateProbs) throws Exception { + HashMap states = new HashMap(); + String state = null; + Float probability = null; + + for (Object stateProb : stateProbs) { + if (state == null) + if (stateProb instanceof String) + state = (String) stateProb; + else + throw new InvalidParameterException("Os parametros devem ser informados no formato: state(string), prob(float), ..., ..."); + else if (state != null) + if ( !(stateProb instanceof String) ) { + if (stateProb instanceof Integer) + probability = new Float ((Integer) stateProb); + else if (stateProb instanceof Float) + probability = (Float) stateProb; + else + throw new InvalidParameterException("Os parametros devem ser informados no formato: state(string), prob(float), ..., ..."); + + states.put(state.toLowerCase(), probability); + probability = null; + state = null; + } else + throw new InvalidParameterException("Os parametros devem ser informados no formato: state(string), prob(float), ..., ..."); + } + + float likelihood[] = new float[node.getStatesSize()]; //nr. de estados do nodo + for(int i=0; i < node.getStatesSize(); i++) { + Float prob = states.get(node.getStateAt(i).toLowerCase()); + states.remove(node.getStateAt(i).toLowerCase()); + if (prob != null) + likelihood[i] = prob; + else + likelihood[i] = 0; + } + + if (states.size() > 0) { + StringBuilder invalidStates = new StringBuilder(); + for (String key : states.keySet()) { + invalidStates.append(key); + invalidStates.append(" "); + } + throw new InvalidNodeState("Estados de nodos inválidos: " + invalidStates); + } + + node.addLikeliHood(likelihood); + rede.updateEvidences(); + } + + public List getProbabilidades(TreeVariable node) { + + List listProbs = new ArrayList(); + + for (int i=0; i < node.getStatesSize(); i++) + listProbs.add(new ProbabilisticBean(node.getStateAt(i), node.getMarginalAt(i))); + + return listProbs; + } + + public float getProbabilidadeByState(TreeVariable node, String state) { + for (ProbabilisticBean bean : getProbabilidades(node)) { + if (state.toLowerCase().equals(bean.getState().toLowerCase())) + return bean.getProbability(); + } + + return 0; + } + + public List getProbabilidadesAscOrder(TreeVariable node) { + List listProbs = getProbabilidades(node); + + Collections.sort(listProbs, new Comparator() { + @Override + public int compare(Object o1, Object o2) { + ProbabilisticBean nodo1 = (ProbabilisticBean) o1; + ProbabilisticBean nodo2 = (ProbabilisticBean) o2; + + if (nodo1.getProbability() > nodo2.getProbability()) + return 1; + else if (nodo1.getProbability() < nodo2.getProbability()) + return -1; + else + return 0; + } + }); + + return listProbs; + } + + public List getProbabilidadesDescOrder(TreeVariable node) { + List listProbs = getProbabilidades(node); + + Collections.sort(listProbs, new Comparator() { + @Override + public int compare(Object o1, Object o2) { + ProbabilisticBean nodo1 = (ProbabilisticBean) o1; + ProbabilisticBean nodo2 = (ProbabilisticBean) o2; + + if (nodo1.getProbability() > nodo2.getProbability()) + return -1; + else if (nodo1.getProbability() < nodo2.getProbability()) + return 1; + else + return 0; + } + }); + + return listProbs; + } + + +} diff --git a/src/java/org/ufcspa/simdecs/util/UnBUtil.java b/src/java/org/ufcspa/simdecs/util/UnBUtil.java deleted file mode 100644 index 8b3e252..0000000 --- a/src/java/org/ufcspa/simdecs/util/UnBUtil.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.ufcspa.simdecs.util; - -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import javax.persistence.EntityManager; -import org.ufcspa.simdecs.entities.Nodo; -import org.ufcspa.simdecs.entities.Rede; -import unbbayes.io.xmlbif.version6.XMLBIFIO; -import unbbayes.prs.Node; -import unbbayes.prs.bn.JunctionTreeAlgorithm; -import unbbayes.prs.bn.ProbabilisticNetwork; -import unbbayes.prs.bn.ProbabilisticNode; - -/** - * - * @author maroni - */ -public class UnBUtil { - - - private static UnBUtil unBUtil; - private ProbabilisticNetwork rede; - - private UnBUtil(Rede redeEntity) { - abreRede(redeEntity); - } - - public final void abreRede(Rede redeEntity) { - try { - // required to run unbbayes gui classes on server - System.setProperty("java.awt.headless", "false"); - rede = new ProbabilisticNetwork(null); - XMLBIFIO.loadXML(new File(redeEntity.getArquivo()), rede); - - } catch (Exception e) { - e.printStackTrace(); - System.exit(1); - } - - compilar(); - } - - public static UnBUtil getInstance(Rede redeEntity) { - if (unBUtil == null) - unBUtil = new UnBUtil(redeEntity); - - return unBUtil; - } - - public ProbabilisticNode getNodeByName(String name) { - for(Node node : rede.getNodes()) { - if (node.getName().equals(name)) - return (ProbabilisticNode) node; - } - - return null; - } - - public NodoBean getNodoBeanByNodo(Nodo nodo) { - for(Node node : rede.getNodes()) { - if (node.getName().equals(nodo.getNome())) - return new NodoBean(nodo, (ProbabilisticNode) node); - } - - return null; - } - - public ProbabilisticNetwork getRede() { - return rede; - } - - public void compilar() { - JunctionTreeAlgorithm jt = new JunctionTreeAlgorithm(); - jt.setNet(rede); - jt.run(); - } - - public void setProbablidadeNodo(ProbabilisticNode pn, float sim, float nao) { - float likelihood[] = new float[pn.getStatesSize()]; //nr. de estados do nodo - likelihood[0] = sim; - likelihood[1] = nao; - - pn.addLikeliHood(likelihood); - try { - unBUtil.getRede().updateEvidences(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public void ativarNodo(ProbabilisticNode pn) { - setProbablidadeNodo(pn, 1f, 0.0f); - } - - public void desativarNodo(ProbabilisticNode pn) { - setProbablidadeNodo(pn, 0.0f, 1f); - } - - public List getProbabilidadeNodos(String tipo) { - EntityManager em = DbUtil.getInstance().getEntityManager(); - List nodos = new ArrayList(); - - for (int j = 0; j < rede.getNodeCount(); j++) { - ProbabilisticNode nodoAtual = (ProbabilisticNode) rede.getNodeAt(j); - - - Nodo nodo = (Nodo) em.createQuery("From Nodo where nome=:pNome") - .setParameter("pNome", nodoAtual.getName()) - .getSingleResult(); - - - if (!nodo.getTipo().equals(tipo)) - continue; - - nodos.add(new NodoBean(nodo, nodoAtual)); - } - - Collections.sort(nodos, new Comparator() { - @Override - public int compare(Object o1, Object o2) { - NodoBean nodo1 = (NodoBean) o1; - NodoBean nodo2 = (NodoBean) o2; - - if (nodo1.getProbabilidade() < nodo2.getProbabilidade()) - return 1; - else if (nodo1.getProbabilidade() > nodo2.getProbabilidade()) - return -1; - else - return 0; - } - }); - - return nodos; - } - - public List getProbabilidadeDiagnosticos() { - return getProbabilidadeNodos(Nodo.DIAGNOSTICO); - } - - public List getProbabilidadeCondutas() { - return getProbabilidadeNodos(Nodo.CONDUTA); - } - - public void print() { - for (int j = 0; j < rede.getNodeCount(); j++) { - ProbabilisticNode nodoAtual = (ProbabilisticNode) rede.getNodeAt(j); - System.out.println(nodoAtual.getName()); - - // Verificando a tabela de probabilidades do nodo - for (int pb = 0; pb < nodoAtual.getStatesSize(); pb++) { - System.out.println(nodoAtual.getStateAt(pb)+":"+nodoAtual.getMarginalAt(pb)); - } - System.out.println(""); - } - } -} diff --git a/web/WEB-INF/glassfish-web.xml b/web/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000..8f43e43 --- /dev/null +++ b/web/WEB-INF/glassfish-web.xml @@ -0,0 +1,11 @@ + + + + /simdecs + + + + Keep a copy of the generated servlet class' java code. + + + diff --git a/web/redes/di.xml b/web/redes/di.xml new file mode 100644 index 0000000..e2ca130 --- /dev/null +++ b/web/redes/di.xml @@ -0,0 +1,390 @@ + + + + 1.0 + di + UnBBayes + + + 40 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Investigacao + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0.33333298563957214 + 0.33333298563957214 + 0.33333298563957214 + + + + + + 0.33333298563957214 + 0.33333298563957214 + 0.33333298563957214 + + + + + + 0.33333298563957214 + 0.33333298563957214 + 0.33333298563957214 + + + + + + 0.33333298563957214 + 0.33333298563957214 + 0.33333298563957214 + + + + + + + + + + + 0.0 + 0.0 + 1.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 1.0 + 0.0 + 1.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 1.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 1.0 + 0.0 + 0.0 + 0.0 + 0.0 + 1.0 + 0.0 + 1.0 + 0.0 + 0.0 + 0.0 + 0.0 + 1.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 1.0 + 0.0 + + + + + + + + + + + 0.05000000074505806 + 0.949999988079071 + 0.699999988079071 + 0.30000001192092896 + 0.30000001192092896 + 0.699999988079071 + 0.10000000149011612 + 0.8999999761581421 + 0.75 + 0.25 + 0.3499999940395355 + 0.6499999761581421 + 0.6000000238418579 + 0.4000000059604645 + 0.8500000238418579 + 0.15000000596046448 + 0.699999988079071 + 0.30000001192092896 + 0.699999988079071 + 0.30000001192092896 + 0.949999988079071 + 0.05000000074505806 + 0.800000011920929 + 0.20000000298023224 + + + + + + 0.5 + 0.5 + + + + + + 0.5 + 0.5 + + + + + + 0.5 + 0.5 + + + + + + + + + + + 0.949999988079071 + 0.02500000037252903 + 0.02500000037252903 + 0.800000011920929 + 0.15000000596046448 + 0.05000000074505806 + 0.3499999940395355 + 0.05000000074505806 + 0.6000000238418579 + 0.25 + 0.25 + 0.5 + 0.4000000059604645 + 0.550000011920929 + 0.05000000074505806 + 0.3499999940395355 + 0.15000000596046448 + 0.5 + 0.800000011920929 + 0.05000000074505806 + 0.15000000596046448 + 0.6000000238418579 + 0.05000000074505806 + 0.3499999940395355 + 0.15000000596046448 + 0.05000000074505806 + 0.800000011920929 + 0.800000011920929 + 0.10000000149011612 + 0.10000000149011612 + 0.6000000238418579 + 0.3499999940395355 + 0.05000000074505806 + 0.3499999940395355 + 0.05000000074505806 + 0.6000000238418579 + 0.5 + 0.44999998807907104 + 0.05000000074505806 + 0.33333298563957214 + 0.33333298563957214 + 0.33333298563957214 + 0.20000000298023224 + 0.20000000298023224 + 0.6000000238418579 + 0.5 + 0.10000000149011612 + 0.4000000059604645 + 0.30000001192092896 + 0.30000001192092896 + 0.4000000059604645 + 0.10000000149011612 + 0.10000000149011612 + 0.800000011920929 + 0.699999988079071 + 0.15000000596046448 + 0.15000000596046448 + 0.4000000059604645 + 0.20000000298023224 + 0.4000000059604645 + 0.15000000596046448 + 0.15000000596046448 + 0.699999988079071 + 0.4000000059604645 + 0.20000000298023224 + 0.4000000059604645 + 0.30000001192092896 + 0.30000001192092896 + 0.4000000059604645 + 0.05000000074505806 + 0.20000000298023224 + 0.75 + 0.3499999940395355 + 0.05000000074505806 + 0.6000000238418579 + 0.10000000149011612 + 0.4000000059604645 + 0.5 + 0.2547770142555237 + 0.019108299165964127 + 0.7261149883270264 + + + + + + 0.5 + 0.5 + + + + + + + + + + + 0.15000000596046448 + 0.15000000596046448 + 0.699999988079071 + 0.20000000298023224 + 0.20000000298023224 + 0.6000000238418579 + 0.20000000298023224 + 0.6000000238418579 + 0.20000000298023224 + 0.8999999761581421 + 0.05000000074505806 + 0.05000000074505806 + 0.05000000074505806 + 0.05000000074505806 + 0.8999999761581421 + 0.05000000074505806 + 0.05000000074505806 + 0.8999999761581421 + 0.10000000149011612 + 0.10000000149011612 + 0.800000011920929 + 0.02500000037252903 + 0.02500000037252903 + 0.949999988079071 + + + + + \ No newline at end of file diff --git a/web/simulador/endereco.txt b/web/simulador/endereco.txt index 276dc87..8eb132d 100755 --- a/web/simulador/endereco.txt +++ b/web/simulador/endereco.txt @@ -1 +1 @@ -http://200.18.67.61/simdecs2/ \ No newline at end of file +http://localhost:8080/simdecs/ \ No newline at end of file diff --git a/web/style.css b/web/style.css index 2a765cf..bc4752e 100644 --- a/web/style.css +++ b/web/style.css @@ -7,7 +7,6 @@ */ /* - TODO customize this sample style Syntax recommendation http://www.w3.org/TR/REC-CSS2/ */ diff --git a/web/teste2.xhtml b/web/teste2.xhtml new file mode 100644 index 0000000..45b66bf --- /dev/null +++ b/web/teste2.xhtml @@ -0,0 +1,12 @@ + + + + + Facelet Title + + + Hello from Facelets + + + -- 1.7.6.4