slQ0R>>Z52
zZD@7=>%{a-HlPYM$g97L|3$(^cCYo$)-1m?KZ7)RXL=qt$Pv
znfLs6+W&TSEoSw*>3@U$&cYVFf_adhX_qvd=dUz*=RnscE1y#0U0uX9!3mtX}>
zTi-Nwp3+>-H1q0r)Blg?%z*axDbw_QvHf?`|2=f1`xErMs(0!Bf8m=1*_8~<>%4{L^4$Vk&w16i
z=b2K?v-ju!`kd+yI9=_p26|@9G?&lzu2DH>X>Sqpzf<*|f10tG#NKdSSkZz1z5_AG
u{Gu!6ddV|eu8&vvmxAC!_vHM-SgF$Ypc#vmQfyLt7-O{>W4)YHDaPO4IP^vU
literal 0
HcmV?d00001
diff --git a/sut-gestaoHospital/hospital-ui/src/index.html b/sut-gestaoHospital/hospital-ui/src/index.html
new file mode 100644
index 0000000..9414b85
--- /dev/null
+++ b/sut-gestaoHospital/hospital-ui/src/index.html
@@ -0,0 +1,16 @@
+
+
+
+
+ Sistema de Gestão Hospitalar
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sut-gestaoHospital/hospital-ui/src/karma.conf.js b/sut-gestaoHospital/hospital-ui/src/karma.conf.js
new file mode 100644
index 0000000..23e4a92
--- /dev/null
+++ b/sut-gestaoHospital/hospital-ui/src/karma.conf.js
@@ -0,0 +1,32 @@
+// Karma configuration file, see link for more information
+// https://karma-runner.github.io/1.0/config/configuration-file.html
+
+module.exports = function (config) {
+ config.set({
+ basePath: '',
+ frameworks: ['jasmine', '@angular-devkit/build-angular'],
+ plugins: [
+ require('karma-jasmine'),
+ require('karma-chrome-launcher'),
+ require('karma-jasmine-html-reporter'),
+ require('karma-coverage-istanbul-reporter'),
+ require('@angular-devkit/build-angular/plugins/karma')
+ ],
+ client: {
+ clearContext: false // leave Jasmine Spec Runner output visible in browser
+ },
+ coverageIstanbulReporter: {
+ dir: require('path').join(__dirname, '../coverage/hospital-ui'),
+ reports: ['html', 'lcovonly', 'text-summary'],
+ fixWebpackSourcePaths: true
+ },
+ reporters: ['progress', 'kjhtml'],
+ port: 9876,
+ colors: true,
+ logLevel: config.LOG_INFO,
+ autoWatch: true,
+ browsers: ['Chrome'],
+ singleRun: false,
+ restartOnFileChange: true
+ });
+};
diff --git a/sut-gestaoHospital/hospital-ui/src/main.ts b/sut-gestaoHospital/hospital-ui/src/main.ts
new file mode 100644
index 0000000..c7b673c
--- /dev/null
+++ b/sut-gestaoHospital/hospital-ui/src/main.ts
@@ -0,0 +1,12 @@
+import { enableProdMode } from '@angular/core';
+import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
+
+import { AppModule } from './app/app.module';
+import { environment } from './environments/environment';
+
+if (environment.production) {
+ enableProdMode();
+}
+
+platformBrowserDynamic().bootstrapModule(AppModule)
+ .catch(err => console.error(err));
diff --git a/sut-gestaoHospital/hospital-ui/src/polyfills.ts b/sut-gestaoHospital/hospital-ui/src/polyfills.ts
new file mode 100644
index 0000000..75d6393
--- /dev/null
+++ b/sut-gestaoHospital/hospital-ui/src/polyfills.ts
@@ -0,0 +1,63 @@
+/**
+ * This file includes polyfills needed by Angular and is loaded before the app.
+ * You can add your own extra polyfills to this file.
+ *
+ * This file is divided into 2 sections:
+ * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
+ * 2. Application imports. Files imported after ZoneJS that should be loaded before your main
+ * file.
+ *
+ * The current setup is for so-called "evergreen" browsers; the last versions of browsers that
+ * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
+ * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
+ *
+ * Learn more in https://angular.io/guide/browser-support
+ */
+
+/***************************************************************************************************
+ * BROWSER POLYFILLS
+ */
+
+/** IE10 and IE11 requires the following for NgClass support on SVG elements */
+// import 'classlist.js'; // Run `npm install --save classlist.js`.
+
+/**
+ * Web Animations `@angular/platform-browser/animations`
+ * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
+ * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
+ */
+// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
+
+/**
+ * By default, zone.js will patch all possible macroTask and DomEvents
+ * user can disable parts of macroTask/DomEvents patch by setting following flags
+ * because those flags need to be set before `zone.js` being loaded, and webpack
+ * will put import in the top of bundle, so user need to create a separate file
+ * in this directory (for example: zone-flags.ts), and put the following flags
+ * into that file, and then add the following code before importing zone.js.
+ * import './zone-flags.ts';
+ *
+ * The flags allowed in zone-flags.ts are listed here.
+ *
+ * The following flags will work for all browsers.
+ *
+ * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
+ * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
+ * (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
+ *
+ * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
+ * with the following flag, it will bypass `zone.js` patch for IE/Edge
+ *
+ * (window as any).__Zone_enable_cross_context_check = true;
+ *
+ */
+
+/***************************************************************************************************
+ * Zone JS is required by default for Angular itself.
+ */
+import 'zone.js/dist/zone'; // Included with Angular CLI.
+
+
+/***************************************************************************************************
+ * APPLICATION IMPORTS
+ */
diff --git a/sut-gestaoHospital/hospital-ui/src/styles.css b/sut-gestaoHospital/hospital-ui/src/styles.css
new file mode 100644
index 0000000..25a3146
--- /dev/null
+++ b/sut-gestaoHospital/hospital-ui/src/styles.css
@@ -0,0 +1,3 @@
+body{
+ background-image: linear-gradient( #330033,#7800FF,#330033,#7800FF,#330033);
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/hospital-ui/src/test.ts b/sut-gestaoHospital/hospital-ui/src/test.ts
new file mode 100644
index 0000000..1631789
--- /dev/null
+++ b/sut-gestaoHospital/hospital-ui/src/test.ts
@@ -0,0 +1,20 @@
+// This file is required by karma.conf.js and loads recursively all the .spec and framework files
+
+import 'zone.js/dist/zone-testing';
+import { getTestBed } from '@angular/core/testing';
+import {
+ BrowserDynamicTestingModule,
+ platformBrowserDynamicTesting
+} from '@angular/platform-browser-dynamic/testing';
+
+declare const require: any;
+
+// First, initialize the Angular testing environment.
+getTestBed().initTestEnvironment(
+ BrowserDynamicTestingModule,
+ platformBrowserDynamicTesting()
+);
+// Then we find all the tests.
+const context = require.context('./', true, /\.spec\.ts$/);
+// And load the modules.
+context.keys().map(context);
diff --git a/sut-gestaoHospital/hospital-ui/src/tsconfig.app.json b/sut-gestaoHospital/hospital-ui/src/tsconfig.app.json
new file mode 100644
index 0000000..190fd30
--- /dev/null
+++ b/sut-gestaoHospital/hospital-ui/src/tsconfig.app.json
@@ -0,0 +1,11 @@
+{
+ "extends": "../tsconfig.json",
+ "compilerOptions": {
+ "outDir": "../out-tsc/app",
+ "types": []
+ },
+ "exclude": [
+ "test.ts",
+ "**/*.spec.ts"
+ ]
+}
diff --git a/sut-gestaoHospital/hospital-ui/src/tsconfig.spec.json b/sut-gestaoHospital/hospital-ui/src/tsconfig.spec.json
new file mode 100644
index 0000000..de77336
--- /dev/null
+++ b/sut-gestaoHospital/hospital-ui/src/tsconfig.spec.json
@@ -0,0 +1,18 @@
+{
+ "extends": "../tsconfig.json",
+ "compilerOptions": {
+ "outDir": "../out-tsc/spec",
+ "types": [
+ "jasmine",
+ "node"
+ ]
+ },
+ "files": [
+ "test.ts",
+ "polyfills.ts"
+ ],
+ "include": [
+ "**/*.spec.ts",
+ "**/*.d.ts"
+ ]
+}
diff --git a/sut-gestaoHospital/hospital-ui/src/tslint.json b/sut-gestaoHospital/hospital-ui/src/tslint.json
new file mode 100644
index 0000000..aa7c3ee
--- /dev/null
+++ b/sut-gestaoHospital/hospital-ui/src/tslint.json
@@ -0,0 +1,17 @@
+{
+ "extends": "../tslint.json",
+ "rules": {
+ "directive-selector": [
+ true,
+ "attribute",
+ "app",
+ "camelCase"
+ ],
+ "component-selector": [
+ true,
+ "element",
+ "app",
+ "kebab-case"
+ ]
+ }
+}
diff --git a/sut-gestaoHospital/hospital-ui/tsconfig.json b/sut-gestaoHospital/hospital-ui/tsconfig.json
new file mode 100644
index 0000000..b271fd9
--- /dev/null
+++ b/sut-gestaoHospital/hospital-ui/tsconfig.json
@@ -0,0 +1,22 @@
+{
+ "compileOnSave": false,
+ "compilerOptions": {
+ "baseUrl": "./",
+ "outDir": "./dist/out-tsc",
+ "sourceMap": true,
+ "declaration": false,
+ "module": "es2015",
+ "moduleResolution": "node",
+ "emitDecoratorMetadata": true,
+ "experimentalDecorators": true,
+ "importHelpers": true,
+ "target": "es5",
+ "typeRoots": [
+ "node_modules/@types"
+ ],
+ "lib": [
+ "es2018",
+ "dom"
+ ]
+ }
+}
diff --git a/sut-gestaoHospital/hospital-ui/tslint.json b/sut-gestaoHospital/hospital-ui/tslint.json
new file mode 100644
index 0000000..868ecba
--- /dev/null
+++ b/sut-gestaoHospital/hospital-ui/tslint.json
@@ -0,0 +1,75 @@
+{
+ "extends": "tslint:recommended",
+ "rulesDirectory": [
+ "codelyzer"
+ ],
+ "rules": {
+ "array-type": false,
+ "arrow-parens": false,
+ "deprecation": {
+ "severity": "warn"
+ },
+ "import-blacklist": [
+ true,
+ "rxjs/Rx"
+ ],
+ "interface-name": false,
+ "max-classes-per-file": false,
+ "max-line-length": [
+ true,
+ 140
+ ],
+ "member-access": false,
+ "member-ordering": [
+ true,
+ {
+ "order": [
+ "static-field",
+ "instance-field",
+ "static-method",
+ "instance-method"
+ ]
+ }
+ ],
+ "no-consecutive-blank-lines": false,
+ "no-console": [
+ true,
+ "debug",
+ "info",
+ "time",
+ "timeEnd",
+ "trace"
+ ],
+ "no-empty": false,
+ "no-inferrable-types": [
+ true,
+ "ignore-params"
+ ],
+ "no-non-null-assertion": true,
+ "no-redundant-jsdoc": true,
+ "no-switch-case-fall-through": true,
+ "no-use-before-declare": true,
+ "no-var-requires": false,
+ "object-literal-key-quotes": [
+ true,
+ "as-needed"
+ ],
+ "object-literal-sort-keys": false,
+ "ordered-imports": false,
+ "quotemark": [
+ true,
+ "single"
+ ],
+ "trailing-comma": false,
+ "no-output-on-prefix": true,
+ "use-input-property-decorator": true,
+ "use-output-property-decorator": true,
+ "use-host-property-decorator": true,
+ "no-input-rename": true,
+ "no-output-rename": true,
+ "use-life-cycle-interface": true,
+ "use-pipe-transform-interface": true,
+ "component-class-suffix": true,
+ "directive-class-suffix": true
+ }
+}
diff --git a/sut-gestaoHospital/mvnw b/sut-gestaoHospital/mvnw
new file mode 100644
index 0000000..5551fde
--- /dev/null
+++ b/sut-gestaoHospital/mvnw
@@ -0,0 +1,286 @@
+#!/bin/sh
+# ----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# ----------------------------------------------------------------------------
+
+# ----------------------------------------------------------------------------
+# Maven2 Start Up Batch script
+#
+# Required ENV vars:
+# ------------------
+# JAVA_HOME - location of a JDK home dir
+#
+# Optional ENV vars
+# -----------------
+# M2_HOME - location of maven2's installed home dir
+# MAVEN_OPTS - parameters passed to the Java VM when running Maven
+# e.g. to debug Maven itself, use
+# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+# ----------------------------------------------------------------------------
+
+if [ -z "$MAVEN_SKIP_RC" ] ; then
+
+ if [ -f /etc/mavenrc ] ; then
+ . /etc/mavenrc
+ fi
+
+ if [ -f "$HOME/.mavenrc" ] ; then
+ . "$HOME/.mavenrc"
+ fi
+
+fi
+
+# OS specific support. $var _must_ be set to either true or false.
+cygwin=false;
+darwin=false;
+mingw=false
+case "`uname`" in
+ CYGWIN*) cygwin=true ;;
+ MINGW*) mingw=true;;
+ Darwin*) darwin=true
+ # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
+ # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
+ if [ -z "$JAVA_HOME" ]; then
+ if [ -x "/usr/libexec/java_home" ]; then
+ export JAVA_HOME="`/usr/libexec/java_home`"
+ else
+ export JAVA_HOME="/Library/Java/Home"
+ fi
+ fi
+ ;;
+esac
+
+if [ -z "$JAVA_HOME" ] ; then
+ if [ -r /etc/gentoo-release ] ; then
+ JAVA_HOME=`java-config --jre-home`
+ fi
+fi
+
+if [ -z "$M2_HOME" ] ; then
+ ## resolve links - $0 may be a link to maven's home
+ PRG="$0"
+
+ # need this for relative symlinks
+ while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG="`dirname "$PRG"`/$link"
+ fi
+ done
+
+ saveddir=`pwd`
+
+ M2_HOME=`dirname "$PRG"`/..
+
+ # make it fully qualified
+ M2_HOME=`cd "$M2_HOME" && pwd`
+
+ cd "$saveddir"
+ # echo Using m2 at $M2_HOME
+fi
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin ; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME=`cygpath --unix "$M2_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+ [ -n "$CLASSPATH" ] &&
+ CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
+fi
+
+# For Mingw, ensure paths are in UNIX format before anything is touched
+if $mingw ; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME="`(cd "$M2_HOME"; pwd)`"
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
+ # TODO classpath?
+fi
+
+if [ -z "$JAVA_HOME" ]; then
+ javaExecutable="`which javac`"
+ if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
+ # readlink(1) is not available as standard on Solaris 10.
+ readLink=`which readlink`
+ if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
+ if $darwin ; then
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
+ else
+ javaExecutable="`readlink -f \"$javaExecutable\"`"
+ fi
+ javaHome="`dirname \"$javaExecutable\"`"
+ javaHome=`expr "$javaHome" : '\(.*\)/bin'`
+ JAVA_HOME="$javaHome"
+ export JAVA_HOME
+ fi
+ fi
+fi
+
+if [ -z "$JAVACMD" ] ; then
+ if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ else
+ JAVACMD="`which java`"
+ fi
+fi
+
+if [ ! -x "$JAVACMD" ] ; then
+ echo "Error: JAVA_HOME is not defined correctly." >&2
+ echo " We cannot execute $JAVACMD" >&2
+ exit 1
+fi
+
+if [ -z "$JAVA_HOME" ] ; then
+ echo "Warning: JAVA_HOME environment variable is not set."
+fi
+
+CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
+
+# traverses directory structure from process work directory to filesystem root
+# first directory with .mvn subdirectory is considered project base directory
+find_maven_basedir() {
+
+ if [ -z "$1" ]
+ then
+ echo "Path not specified to find_maven_basedir"
+ return 1
+ fi
+
+ basedir="$1"
+ wdir="$1"
+ while [ "$wdir" != '/' ] ; do
+ if [ -d "$wdir"/.mvn ] ; then
+ basedir=$wdir
+ break
+ fi
+ # workaround for JBEAP-8937 (on Solaris 10/Sparc)
+ if [ -d "${wdir}" ]; then
+ wdir=`cd "$wdir/.."; pwd`
+ fi
+ # end of workaround
+ done
+ echo "${basedir}"
+}
+
+# concatenates all lines of a file
+concat_lines() {
+ if [ -f "$1" ]; then
+ echo "$(tr -s '\n' ' ' < "$1")"
+ fi
+}
+
+BASE_DIR=`find_maven_basedir "$(pwd)"`
+if [ -z "$BASE_DIR" ]; then
+ exit 1;
+fi
+
+##########################################################################################
+# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+# This allows using the maven wrapper in projects that prohibit checking in binary data.
+##########################################################################################
+if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found .mvn/wrapper/maven-wrapper.jar"
+ fi
+else
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
+ fi
+ jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
+ while IFS="=" read key value; do
+ case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
+ esac
+ done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Downloading from: $jarUrl"
+ fi
+ wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
+
+ if command -v wget > /dev/null; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found wget ... using wget"
+ fi
+ wget "$jarUrl" -O "$wrapperJarPath"
+ elif command -v curl > /dev/null; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Found curl ... using curl"
+ fi
+ curl -o "$wrapperJarPath" "$jarUrl"
+ else
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo "Falling back to using Java to download"
+ fi
+ javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
+ if [ -e "$javaClass" ]; then
+ if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo " - Compiling MavenWrapperDownloader.java ..."
+ fi
+ # Compiling the Java class
+ ("$JAVA_HOME/bin/javac" "$javaClass")
+ fi
+ if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
+ # Running the downloader
+ if [ "$MVNW_VERBOSE" = true ]; then
+ echo " - Running MavenWrapperDownloader.java ..."
+ fi
+ ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
+ fi
+ fi
+ fi
+fi
+##########################################################################################
+# End of extension
+##########################################################################################
+
+export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
+if [ "$MVNW_VERBOSE" = true ]; then
+ echo $MAVEN_PROJECTBASEDIR
+fi
+MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+ [ -n "$M2_HOME" ] &&
+ M2_HOME=`cygpath --path --windows "$M2_HOME"`
+ [ -n "$JAVA_HOME" ] &&
+ JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+ [ -n "$CLASSPATH" ] &&
+ CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+ [ -n "$MAVEN_PROJECTBASEDIR" ] &&
+ MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
+fi
+
+WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+exec "$JAVACMD" \
+ $MAVEN_OPTS \
+ -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
+ "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
+ ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
diff --git a/sut-gestaoHospital/mvnw.cmd b/sut-gestaoHospital/mvnw.cmd
new file mode 100644
index 0000000..e5cfb0a
--- /dev/null
+++ b/sut-gestaoHospital/mvnw.cmd
@@ -0,0 +1,161 @@
+@REM ----------------------------------------------------------------------------
+@REM Licensed to the Apache Software Foundation (ASF) under one
+@REM or more contributor license agreements. See the NOTICE file
+@REM distributed with this work for additional information
+@REM regarding copyright ownership. The ASF licenses this file
+@REM to you under the Apache License, Version 2.0 (the
+@REM "License"); you may not use this file except in compliance
+@REM with the License. You may obtain a copy of the License at
+@REM
+@REM http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing,
+@REM software distributed under the License is distributed on an
+@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+@REM KIND, either express or implied. See the License for the
+@REM specific language governing permissions and limitations
+@REM under the License.
+@REM ----------------------------------------------------------------------------
+
+@REM ----------------------------------------------------------------------------
+@REM Maven2 Start Up Batch script
+@REM
+@REM Required ENV vars:
+@REM JAVA_HOME - location of a JDK home dir
+@REM
+@REM Optional ENV vars
+@REM M2_HOME - location of maven2's installed home dir
+@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
+@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
+@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
+@REM e.g. to debug Maven itself, use
+@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
+@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
+@REM ----------------------------------------------------------------------------
+
+@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
+@echo off
+@REM set title of command window
+title %0
+@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
+@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
+
+@REM set %HOME% to equivalent of $HOME
+if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
+
+@REM Execute a user defined script before this one
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
+@REM check for pre script, once with legacy .bat ending and once with .cmd ending
+if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
+if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
+:skipRcPre
+
+@setlocal
+
+set ERROR_CODE=0
+
+@REM To isolate internal variables from possible post scripts, we use another setlocal
+@setlocal
+
+@REM ==== START VALIDATION ====
+if not "%JAVA_HOME%" == "" goto OkJHome
+
+echo.
+echo Error: JAVA_HOME not found in your environment. >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+:OkJHome
+if exist "%JAVA_HOME%\bin\java.exe" goto init
+
+echo.
+echo Error: JAVA_HOME is set to an invalid directory. >&2
+echo JAVA_HOME = "%JAVA_HOME%" >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+goto error
+
+@REM ==== END VALIDATION ====
+
+:init
+
+@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
+@REM Fallback to current working directory if not found.
+
+set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
+IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
+
+set EXEC_DIR=%CD%
+set WDIR=%EXEC_DIR%
+:findBaseDir
+IF EXIST "%WDIR%"\.mvn goto baseDirFound
+cd ..
+IF "%WDIR%"=="%CD%" goto baseDirNotFound
+set WDIR=%CD%
+goto findBaseDir
+
+:baseDirFound
+set MAVEN_PROJECTBASEDIR=%WDIR%
+cd "%EXEC_DIR%"
+goto endDetectBaseDir
+
+:baseDirNotFound
+set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
+cd "%EXEC_DIR%"
+
+:endDetectBaseDir
+
+IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
+
+@setlocal EnableExtensions EnableDelayedExpansion
+for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
+@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
+
+:endReadAdditionalConfig
+
+SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
+set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
+set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
+
+set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"
+FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO (
+ IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
+)
+
+@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
+@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
+if exist %WRAPPER_JAR% (
+ echo Found %WRAPPER_JAR%
+) else (
+ echo Couldn't find %WRAPPER_JAR%, downloading it ...
+ echo Downloading from: %DOWNLOAD_URL%
+ powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"
+ echo Finished downloading %WRAPPER_JAR%
+)
+@REM End of extension
+
+%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
+if ERRORLEVEL 1 goto error
+goto end
+
+:error
+set ERROR_CODE=1
+
+:end
+@endlocal & set ERROR_CODE=%ERROR_CODE%
+
+if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
+@REM check for post script, once with legacy .bat ending and once with .cmd ending
+if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
+if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
+:skipRcPost
+
+@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
+if "%MAVEN_BATCH_PAUSE%" == "on" pause
+
+if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
+
+exit /B %ERROR_CODE%
diff --git a/sut-gestaoHospital/pom.xml b/sut-gestaoHospital/pom.xml
new file mode 100644
index 0000000..035e916
--- /dev/null
+++ b/sut-gestaoHospital/pom.xml
@@ -0,0 +1,65 @@
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 2.1.3.RELEASE
+
+
+ com.codenation
+ gestaohospitalar
+ 0.0.1
+ gestaohospitalar
+ Code:Nation - Sistema de Gestão Hospitalar
+
+
+ 1.8
+
+
+
+
+ io.springfox
+ springfox-swagger2
+ 2.6.1
+
+
+ io.springfox
+ springfox-swagger-ui
+ 2.6.1
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.springframework.boot
+ spring-boot-starter-hateoas
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-mongodb
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/GestaohospitalarApplication.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/GestaohospitalarApplication.java
new file mode 100644
index 0000000..5644363
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/GestaohospitalarApplication.java
@@ -0,0 +1,13 @@
+package br.com.codenation.hospital;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class GestaohospitalarApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(GestaohospitalarApplication.class, args);
+ }
+
+}
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/config/Instantiation.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/config/Instantiation.java
new file mode 100644
index 0000000..2a0461c
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/config/Instantiation.java
@@ -0,0 +1,205 @@
+package br.com.codenation.hospital.config;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.TimeZone;
+
+import org.bson.types.ObjectId;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.CommandLineRunner;
+import org.springframework.context.annotation.Configuration;
+
+import br.com.codenation.hospital.domain.Hospital;
+import br.com.codenation.hospital.domain.Location;
+import br.com.codenation.hospital.domain.LocationBuilder;
+import br.com.codenation.hospital.domain.LocationCategory;
+import br.com.codenation.hospital.domain.Patient;
+import br.com.codenation.hospital.domain.Product;
+import br.com.codenation.hospital.domain.ProductType;
+import br.com.codenation.hospital.repository.HospitalRepository;
+import br.com.codenation.hospital.repository.LocationRepository;
+import br.com.codenation.hospital.repository.PatientRepository;
+import br.com.codenation.hospital.repository.ProductRepository;
+
+//Operação de instanciação da base de dados
+
+@Configuration
+public class Instantiation implements CommandLineRunner{
+
+ @Autowired
+ private HospitalRepository hospitalRepository;
+
+ @Autowired
+ private PatientRepository patientRepository;
+
+ @Autowired
+ private ProductRepository productRepository;
+
+ @Autowired
+ private LocationRepository locationRepository;
+
+ @Override
+ public void run(String... args) throws Exception {
+ DateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
+ sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
+
+ hospitalRepository.deleteAll(); //deleta todos dados do mongodb
+ patientRepository.deleteAll();
+ productRepository.deleteAll();
+ locationRepository.deleteAll();
+
+ Location locationUm = new LocationBuilder()
+ .setReferenceId("Av. Albert Einstein, 627 - Jardim Leonor, São Paulo - SP, 05652-900")
+ .setLocationCategory(LocationCategory.HOSPITAL)
+ .setName("Hospital Israelita Albert Einstein")
+ .setLatitude(-23.5920091D)
+ .setLongitude(-46.6388042029871D)
+ .build();
+
+ Location locationDois = new LocationBuilder()
+ .setReferenceId("Rua Engenheiro Oscar Americano, 840 - Jardim Guedala, São Paulo - SP, 05605-050")
+ .setLocationCategory(LocationCategory.HOSPITAL)
+ .setName("Hospital São Luiz Unidade Morumbi")
+ .setLatitude(-23.591093D)
+ .setLongitude(-46.703459)
+ .build();
+
+ Location locationTres = new LocationBuilder()
+ .setReferenceId("Av. Prof. Francisco Morato, 719 - Butantã, São Paulo - SP, 05513-000")
+ .setLocationCategory(LocationCategory.HOSPITAL)
+ .setName("Hospital Next Butantã")
+ .setLatitude(-23.578151D)
+ .setLongitude(-46.708343D)
+ .build();
+
+
+ Location locationPatientUm = new LocationBuilder()
+ .setReferenceId("R. José Pepe, 40-142 - Jardim Leonor, São Paulo - SP, 05652-080")
+ .setLocationCategory(LocationCategory.PATIENT)
+ .setName("Maria")
+ .setLatitude(-23.597442D)
+ .setLongitude(-46.713830D)
+ .build();
+
+ Location locationPatientDois = new LocationBuilder()
+ .setReferenceId("Rua Dr. Celso Dario Guimarães, 201 - Jardim Morumby, São Paulo - SP, 05655-030")
+ .setLocationCategory(LocationCategory.PATIENT)
+ .setName("Pedro")
+ .setLatitude(-23.608176D)
+ .setLongitude(-46.71718D)
+ .build();
+
+ Location locationPatientTres = new LocationBuilder()
+ .setReferenceId("R. Alvorada do Sul, 183 - Morumbi, São Paulo - SP, 05612-010")
+ .setLocationCategory(LocationCategory.PATIENT)
+ .setName("Joana")
+ .setLatitude(-23.591692D)
+ .setLongitude(-46.708806D)
+ .build();
+
+ Location locationPatientQuatro = new LocationBuilder()
+ .setReferenceId("Av. George Saville Dodd, 45 - Morumbi, São Paulo - SP, 05608-020")
+ .setLocationCategory(LocationCategory.PATIENT)
+ .setName("Arya")
+ .setLatitude(-23.580128D)
+ .setLongitude(-46.708799D)
+ .build();
+
+
+ Location locationPatientCinco = new LocationBuilder()
+ .setReferenceId("Rua dos Limantos, 156 - Cidade Jardim, São Paulo - SP, 05675-020")
+ .setLocationCategory(LocationCategory.PATIENT)
+ .setName("João")
+ .setLatitude(-23.593855D)
+ .setLongitude(-46.701794D)
+ .build();
+
+ Location locationPatientSeis = new LocationBuilder()
+ .setReferenceId("Av. Morumbi, 354 - Morumbi, São Paulo - SP, 05606-010")
+ .setLocationCategory(LocationCategory.PATIENT)
+ .setName("Gabriel")
+ .setLatitude(-23.578307D)
+ .setLongitude(-46.706638D)
+ .build();
+
+ Location locationPatientSete = new LocationBuilder()
+ .setReferenceId("R. Campo Verde, 700 - Jardim Europa, São Paulo - SP, 04794-000")
+ .setLocationCategory(LocationCategory.PATIENT)
+ .setName("Ana")
+ .setLatitude(-23.577483D)
+ .setLongitude(-46.694697D)
+ .build();
+
+ Location locationPatientOito = new LocationBuilder()
+ .setReferenceId("R. Campo Verde, 516 - Jardim Europa, São Paulo - SP, 01456-010")
+ .setLocationCategory(LocationCategory.PATIENT)
+ .setName("Paula")
+ .setLatitude(-23.576718D)
+ .setLongitude(-46.693139D)
+ .build();
+
+ locationRepository.saveAll(Arrays.asList(locationUm,locationDois,locationTres)); //adiciona dados
+ locationRepository.saveAll(Arrays.asList(locationPatientUm,locationPatientDois,locationPatientTres)); //adiciona dados
+ locationRepository.saveAll(Arrays.asList(locationPatientQuatro,locationPatientCinco,locationPatientSeis)); //adiciona dados
+ locationRepository.saveAll(Arrays.asList(locationPatientSete,locationPatientOito)); //adiciona dados
+
+ Hospital hospitalUm = new Hospital("1", "Hospital Israelita Albert Einstein", "Av. Albert Einstein, 627 - Jardim Leonor, São Paulo - SP, 05652-900", 21,5, locationUm);
+ Hospital hospitalDois = new Hospital("2", "Hospital São Luiz Unidade Morumbi", "Rua Engenheiro Oscar Americano, 840 - Jardim Guedala, São Paulo - SP, 05605-050", 11,6, locationDois);
+ Hospital hospitalTres = new Hospital("3", "Hospital Next Butantã", "Av. Prof. Francisco Morato, 719 - Butantã, São Paulo - SP, 05513-000", 32,12, locationTres);
+
+ hospitalRepository.saveAll(Arrays.asList(hospitalUm,hospitalDois,hospitalTres)); //adiciona dados
+
+ Patient pacient1 = new Patient("1", "Maria", "864789205", sdf.parse("16/07/2003"), "feminino", sdf.parse("16/07/2019"), locationPatientUm);
+ Patient pacient2 = new Patient("2", "Pedro", "864789205", sdf.parse("16/07/2003"), "masculino", sdf.parse("16/07/2019"), locationPatientDois);
+ Patient pacient3 = new Patient("3", "Joana", "864789205", sdf.parse("16/07/2003"), "feminino", sdf.parse("16/07/2019"), locationPatientTres);
+ Patient pacient4 = new Patient("4", "Arya", "864789205", sdf.parse("16/07/2003"), "feminino", sdf.parse("16/07/2019"), locationPatientQuatro);
+ Patient pacient5 = new Patient("5", "João", "864789205", sdf.parse("16/07/2003"), "masculino", sdf.parse("16/07/2019"), locationPatientCinco);
+ Patient pacient6 = new Patient("6", "Gabriel", "864789205", sdf.parse("16/07/2003"), "masculino", sdf.parse("16/07/2019"), locationPatientSeis);
+ Patient pacient7 = new Patient("7", "Ana", "864789205", sdf.parse("16/07/2003"), "feminino", sdf.parse("16/07/2019"), locationPatientSete);
+ Patient pacient8 = new Patient("8", "Paula", "864789205", sdf.parse("16/07/2003"), "feminino", sdf.parse("16/07/2019"), locationPatientOito);
+
+ patientRepository.saveAll(Arrays.asList(pacient1,pacient2,pacient3,pacient4,pacient5,pacient6,pacient7,pacient8));
+
+
+ // Se cambia la instanciación del identificador de productos (ObjectId a String) para facilitar comparación de resultados de test
+
+ /*Product produto1 = new Product(ObjectId.get(), "Alimento", "Maçã", 12, ProductType.COMMON);
+ Product produto2 = new Product(ObjectId.get(), "Alimento", "Arroz", 3, ProductType.COMMON);
+ Product produto3 = new Product(ObjectId.get(), "Alimento", "Feijão", 2, ProductType.COMMON);
+ Product produto4 = new Product(ObjectId.get(), "Alimento", "Massa", 5, ProductType.COMMON);
+ Product produto5 = new Product(ObjectId.get(), "Alimento", "Massa", 5, ProductType.COMMON);
+
+ Product produto6 = new Product(ObjectId.get(), "Banco de Sangue", "Sangue", 8, ProductType.BLOOD);
+ Product produto7 = new Product(ObjectId.get(), "Banco de Sangue", "Sangue", 1, ProductType.BLOOD);
+ Product produto8 = new Product(ObjectId.get(), "Banco de Sangue", "Sangue", 4, ProductType.BLOOD);*/
+
+ Product produto1 = new Product("1", "Alimento", "Maçã", 12, ProductType.COMMON);
+ Product produto2 = new Product("2", "Alimento", "Arroz", 3, ProductType.COMMON);
+ Product produto3 = new Product("3", "Alimento", "Feijão", 2, ProductType.COMMON);
+ Product produto4 = new Product("4", "Alimento", "Massa", 5, ProductType.COMMON);
+ Product produto5 = new Product("5", "Alimento", "Massa", 5, ProductType.COMMON);
+
+ Product produto6 = new Product("6", "Banco de Sangue", "Sangue", 8, ProductType.BLOOD);
+ Product produto7 = new Product("7", "Banco de Sangue", "Sangue", 1, ProductType.BLOOD);
+ Product produto8 = new Product("8", "Banco de Sangue", "Sangue", 4, ProductType.BLOOD);
+
+
+ productRepository.saveAll(Arrays.asList(produto1,produto2,produto3,produto4,produto5,produto6,produto7,produto8));
+
+ //referenciando pacientes e produtos ao hospital
+ hospitalUm.getPatients().addAll(Arrays.asList(pacient1,pacient2));
+ hospitalTres.getPatients().addAll(Arrays.asList(pacient3,pacient4,pacient5,pacient6,pacient7,pacient8));
+
+ hospitalUm.getProducts().addAll(Arrays.asList(produto5,produto6));
+ hospitalDois.getProducts().addAll(Arrays.asList(produto1,produto7));
+ hospitalTres.getProducts().addAll(Arrays.asList(produto2,produto3,produto4,produto8));
+
+ hospitalRepository.save(hospitalUm);
+ hospitalRepository.save(hospitalDois);
+ hospitalRepository.save(hospitalTres);
+
+// MongoCollection collection = database.getCollection("hospital_collection");
+// collection.createIndex(Indexes.geo2dsphere("location"));
+ }
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/config/SwaggerConfig.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/config/SwaggerConfig.java
new file mode 100644
index 0000000..d1c6bcd
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/config/SwaggerConfig.java
@@ -0,0 +1,35 @@
+package br.com.codenation.hospital.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+import springfox.documentation.builders.ApiInfoBuilder;
+import springfox.documentation.builders.PathSelectors;
+import springfox.documentation.builders.RequestHandlerSelectors;
+import springfox.documentation.service.ApiInfo;
+import springfox.documentation.spi.DocumentationType;
+import springfox.documentation.spring.web.plugins.Docket;
+import springfox.documentation.swagger2.annotations.EnableSwagger2;
+
+@Configuration
+@EnableSwagger2
+// url Swagger - http://localhost:8080/swagger-ui.html
+public class SwaggerConfig {
+
+ @Bean
+ public Docket api() {
+ return new Docket(DocumentationType.SWAGGER_2).select()
+ .apis(RequestHandlerSelectors.basePackage("br.com.codenation.hospital.resource"))
+ .paths(PathSelectors.any()).build()
+ .apiInfo(apiInfo());
+
+ }
+
+ private ApiInfo apiInfo() {
+ return new ApiInfoBuilder().title("Sistema de Gestão Hospital API")
+ .description("Documentação da API de acesso aos endpoints da GestaoHospitalAPI - Aceleradev Brasil\r\n" +
+ "Jornada de desafios da Aceleradev Brasil - CodeNation")
+ .version("1.0")
+ .build();
+ }
+}
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/constant/Constant.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/constant/Constant.java
new file mode 100644
index 0000000..4b8d4d0
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/constant/Constant.java
@@ -0,0 +1,10 @@
+package br.com.codenation.hospital.constant;
+
+public class Constant {
+
+ public final static String V1 = "/v1/hospitais/";
+ public final static String V1Path = "/v1/hospitais/{hospital_id}/";
+ private Constant() {
+ throw new AssertionError();
+ }
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/Hospital.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/Hospital.java
new file mode 100644
index 0000000..872cfbf
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/Hospital.java
@@ -0,0 +1,211 @@
+package br.com.codenation.hospital.domain;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.DBRef;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import br.com.codenation.hospital.resource.exception.ResourceNotFoundException;
+
+@Document(collection="hospital_collection")
+// https://codeboje.de/spring-data-mongodb/
+// https://lishman.io/object-mapping-with-spring-data-mongodb
+public class Hospital implements Serializable{
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ private String id;
+ private String name;
+ private String address;
+ private int beds;
+ private int availableBeds;
+
+ private Location location;
+
+ //só serão acessados se forem carregados
+ //Using Collection References
+ @DBRef(lazy=true)
+ private List patients = new ArrayList<>();
+
+ //Using Collection References
+ @DBRef(lazy=true)
+ private List products = new ArrayList<>();
+
+ public Hospital() {
+
+ }
+
+ public Hospital(String id) {
+ super();
+ this.id = id;
+ }
+
+ public Hospital(String id, String name, String address, int beds, int availableBeds) {
+ super();
+ this.id = id;
+ this.name = name;
+ this.address = address;
+ this.beds = beds;
+ this.availableBeds = availableBeds;
+ }
+
+ public Hospital(String id, String name, String address, int beds, int availableBeds, Location location) {
+ super();
+ this.id = id;
+ this.name = name;
+ this.address = address;
+ this.beds = beds;
+ this.availableBeds = availableBeds;
+ this.location = location;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public int getBeds() {
+ return beds;
+ }
+
+ public void setBeds(int beds) {
+ this.beds = beds;
+ }
+
+ public int getAvailableBeds() {
+ return availableBeds;
+ }
+
+ public void setAvailableBeds(int availableBeds) {
+ if(availableBeds < 0){
+ throw new RuntimeException("Não possui leitos disponiveis");
+ }
+ this.availableBeds = availableBeds;
+ }
+
+ public List getPatients() {
+ return patients;
+ }
+
+ public boolean temVaga(){
+ return availableBeds > 0;
+ }
+
+ public void addPacient(Patient patient){
+ this.availableBeds--;
+ patients.add(patient);
+ }
+
+ public void removePacient(Patient patient){
+ availableBeds++;
+ patients.remove(patient);
+ }
+
+ public void setPatients(List patients) {
+ this.patients = patients;
+ }
+
+ public List getProducts() {
+ return products;
+ }
+
+ public void setProducts(List products) {
+ this.products = products;
+ }
+
+ public void setProduct(Product product) {
+ this.products.add(product);
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public void setLocation(Location location) {
+ this.location = location;
+ }
+
+ public Patient hasPatient(Patient patient){
+ return patients.stream()
+ .filter(patientFilter -> patientFilter.equals(patient))
+ .findFirst()
+ .orElseThrow(() -> new ResourceNotFoundException("Paciente não está neste hospital!"));
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((address == null) ? 0 : address.hashCode());
+ result = prime * result + availableBeds;
+ result = prime * result + beds;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((patients == null) ? 0 : patients.hashCode());
+ result = prime * result + ((products == null) ? 0 : products.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Hospital other = (Hospital) obj;
+ if (address == null) {
+ if (other.address != null)
+ return false;
+ } else if (!address.equals(other.address))
+ return false;
+ if (availableBeds != other.availableBeds)
+ return false;
+ if (beds != other.beds)
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (patients == null) {
+ if (other.patients != null)
+ return false;
+ } else if (!patients.equals(other.patients))
+ return false;
+ if (products == null) {
+ if (other.products != null)
+ return false;
+ } else if (!products.equals(other.products))
+ return false;
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/Location.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/Location.java
new file mode 100644
index 0000000..633d559
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/Location.java
@@ -0,0 +1,134 @@
+package br.com.codenation.hospital.domain;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
+import org.springframework.data.mongodb.core.index.GeoSpatialIndexType;
+import org.springframework.data.mongodb.core.index.GeoSpatialIndexed;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection = "location_collection")
+public class Location implements Serializable{
+ private static final long serialVersionUID = 19L;
+
+ @Id
+ private String id;
+ private String name;
+ private String referenceId;
+ private LocationCategory locationCategory;
+
+ @GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE)
+ private GeoJsonPoint position;
+
+ public Location() {
+ }
+
+ public Location(String referenceId, LocationCategory locationCategory, String name, GeoJsonPoint position) {
+ this.referenceId = referenceId;
+ this.locationCategory = locationCategory;
+ this.name = name;
+ this.position = position;
+ }
+
+ public Location(LocationCategory locationCategory, String name, GeoJsonPoint position) {
+ this.locationCategory = locationCategory;
+ this.name = name;
+ this.position = position;
+ }
+
+ public Location(String referenceId, LocationCategory locationCategory, String name, double longitude, double latitude) {
+ GeoJsonPoint position = new GeoJsonPoint(latitude, longitude);
+
+ this.referenceId = referenceId;
+ this.locationCategory = locationCategory;
+ this.name = name;
+ this.position = position;
+ }
+
+ public Location(LocationCategory locationCategory, String name, double longitude, double latitude) {
+ GeoJsonPoint position = new GeoJsonPoint(latitude, longitude);
+
+ this.locationCategory = locationCategory;
+ this.name = name;
+ this.position = position;
+ }
+
+ public Location(String subject, GeoJsonPoint position) {
+ this.name = subject;
+ this.position = position;
+ }
+
+ public Location(String subject, double longitude, double latitude) {
+ GeoJsonPoint position = new GeoJsonPoint(latitude, longitude);
+
+ this.name = subject;
+ this.position = position;
+ }
+
+ public String getId() {
+ return this.id;
+ }
+
+ public void setId(final String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public GeoJsonPoint getLocation() {
+ return this.position;
+ }
+
+ public void setLocation(final GeoJsonPoint position) {
+ this.position = position;
+ }
+
+ public LocationCategory getLocationCategory() {
+ return locationCategory;
+ }
+
+ public void setLocationCategory(LocationCategory locationCategory) {
+ this.locationCategory = locationCategory;
+ }
+
+ public GeoJsonPoint getPosition() {
+ return position;
+ }
+
+ public void setPosition(GeoJsonPoint position) {
+ this.position = position;
+ }
+
+ public String getReferenceId() {
+ return referenceId;
+ }
+
+ public void setReferenceId(String referenceId) {
+ this.referenceId = referenceId;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) return true;
+ if (o == null || this.getClass() != o.getClass()) return false;
+ final Location that = (Location) o;
+ return Objects.equals(this.getId(), that.getId()) &&
+ Objects.equals(this.getName(), that.getName()) &&
+ Objects.equals(this.getReferenceId(), that.getReferenceId()) &&
+ Objects.equals(this.getPosition(), that.getPosition()) &&
+ Objects.equals(this.getLocationCategory(), that.getLocationCategory());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.getId(), this.getReferenceId(), this.getName(), this.getPosition(), this.getLocationCategory());
+ }
+}
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/LocationBuilder.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/LocationBuilder.java
new file mode 100644
index 0000000..fb40e39
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/LocationBuilder.java
@@ -0,0 +1,38 @@
+package br.com.codenation.hospital.domain;
+
+public class LocationBuilder {
+ private Double latitude;
+ private Double longitude;
+ private String name;
+ private String referenceId;
+ private LocationCategory category;
+
+ public LocationBuilder setLatitude(Double latitude) {
+ this.latitude = latitude;
+ return this;
+ }
+
+ public LocationBuilder setLongitude(Double longitude) {
+ this.longitude = longitude;
+ return this;
+ }
+
+ public LocationBuilder setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public LocationBuilder setLocationCategory(LocationCategory category) {
+ this.category = category;
+ return this;
+ }
+
+ public LocationBuilder setReferenceId(String referenceId) {
+ this.referenceId = referenceId;
+ return this;
+ }
+
+ public Location build() {
+ return new Location(referenceId, category, name, latitude, longitude);
+ }
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/LocationCategory.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/LocationCategory.java
new file mode 100644
index 0000000..a7d813b
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/LocationCategory.java
@@ -0,0 +1,16 @@
+package br.com.codenation.hospital.domain;
+
+public enum LocationCategory {
+ HOSPITAL("HOSPITAL"),
+ PATIENT("PACIENTE");
+
+ private String descricao;
+
+ LocationCategory(String descricao) {
+ this.descricao = descricao;
+ }
+
+ public String getDescricao() {
+ return descricao;
+ }
+}
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/Patient.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/Patient.java
new file mode 100644
index 0000000..b8b624c
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/Patient.java
@@ -0,0 +1,207 @@
+package br.com.codenation.hospital.domain;
+
+import java.io.Serializable;
+import java.util.Date;
+
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection="patient_collection")
+public class Patient implements Serializable{
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ private String id;
+ private String name;
+ private String cpf;
+ private Date birthDate;
+ private String gender;
+ private Date entryDate;
+ private Date exitDate;
+ private boolean active;
+
+ private Location location;
+ private String idHospital; //added reference to an hospital
+
+ public Patient() {
+ this.active = false;
+ this.exitDate = null;
+ }
+
+ public Patient(String name, String cpf, Date birthDate, String gender) {
+ this.name = name;
+ this.cpf = cpf;
+ this.birthDate = birthDate;
+ this.gender = gender;
+ }
+
+ public Patient(String id, String name, String cpf, Date birthDate, String gender, Date entryDate) {
+ super();
+ this.id = id;
+ this.name = name;
+ this.cpf = cpf;
+ this.birthDate = birthDate;
+ this.gender = gender;
+ this.entryDate = entryDate;
+ this.exitDate = null;
+ this.active = false;
+ }
+
+ public Patient(String id, String name, String cpf, Date birthDate, String gender, Date entryDate, Location location) {
+ super();
+ this.id = id;
+ this.name = name;
+ this.cpf = cpf;
+ this.birthDate = birthDate;
+ this.gender = gender;
+ this.entryDate = entryDate;
+ this.exitDate = null;
+ this.active = false;
+ this.location = location;
+ }
+ //added constructor with the reference to an hospital
+ public Patient(String id, String name, String cpf, Date birthDate, String gender, Date entryDate, Location location,String idHospital) {
+ super();
+ this.id = id;
+ this.name = name;
+ this.cpf = cpf;
+ this.birthDate = birthDate;
+ this.gender = gender;
+ this.entryDate = entryDate;
+ this.exitDate = null;
+ this.active = false;
+ this.location = location;
+ this.idHospital = idHospital;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String paciente_id) {
+ this.id = paciente_id;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getCpf() {
+ return cpf;
+ }
+ public void setCpf(String cpf) {
+ this.cpf = cpf;
+ }
+ public Date getBirthDate() {
+ return birthDate;
+ }
+ public void setBirthDate(Date birthDate) {
+ this.birthDate = birthDate;
+ }
+ public String getGender() {
+ return gender;
+ }
+ public void setGender(String gender) {
+ this.gender = gender;
+ }
+ public Date getExitDate() {
+ return entryDate;
+ }
+ public void setExitDate(Date exitDate) {
+ this.exitDate = exitDate;
+ }
+ public Date getEntryDate() {
+ return entryDate;
+ }
+ public void setEntryDate(Date entryDate) {
+ this.entryDate = entryDate;
+ }
+ public void setActive(Boolean active){
+ this.active = active;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public void setLocation(Location location) {
+ this.location = location;
+ }
+
+ //Added getters y seeter for idHopital
+ public String getIdHospital() {
+ return idHospital;
+ }
+
+ public void setIdHospital(String idHospital) {
+ this.idHospital = idHospital;
+ }
+
+
+ public boolean isActive(){return this.active;}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (active ? 1231 : 1237);
+ result = prime * result + ((birthDate == null) ? 0 : birthDate.hashCode());
+ result = prime * result + ((cpf == null) ? 0 : cpf.hashCode());
+ result = prime * result + ((entryDate == null) ? 0 : entryDate.hashCode());
+ result = prime * result + ((exitDate == null) ? 0 : exitDate.hashCode());
+ result = prime * result + ((gender == null) ? 0 : gender.hashCode());
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Patient other = (Patient) obj;
+ if (active != other.active)
+ return false;
+ if (birthDate == null) {
+ if (other.birthDate != null)
+ return false;
+ } else if (!birthDate.equals(other.birthDate))
+ return false;
+ if (cpf == null) {
+ if (other.cpf != null)
+ return false;
+ } else if (!cpf.equals(other.cpf))
+ return false;
+ if (entryDate == null) {
+ if (other.entryDate != null)
+ return false;
+ } else if (!entryDate.equals(other.entryDate))
+ return false;
+ if (exitDate == null) {
+ if (other.exitDate != null)
+ return false;
+ } else if (!exitDate.equals(other.exitDate))
+ return false;
+ if (gender == null) {
+ if (other.gender != null)
+ return false;
+ } else if (!gender.equals(other.gender))
+ return false;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/Product.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/Product.java
new file mode 100644
index 0000000..555ed46
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/Product.java
@@ -0,0 +1,138 @@
+package br.com.codenation.hospital.domain;
+
+import java.io.Serializable;
+
+import org.bson.types.ObjectId;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+@Document(collection="product_collection")
+public class Product implements Serializable{
+ private static final long serialVersionUID = 1L;
+
+
+ @Id
+ //Cambia el tipo del _id (ObjectId a String) para facilitar comparación de resultados de test
+ private String _id;
+ private String name;
+ private String description;
+ private int quantity;
+ private ProductType productType;
+ private String hospitalId; //added reference to the hospital
+
+ public Product() {
+
+ }
+
+ public Product(String _id, String name, String description, int quantity, ProductType productType) {
+ this._id = _id;
+ this.name = name;
+ this.description = description;
+ this.quantity = quantity;
+ this.productType = productType;
+ }
+
+ public Product(String name, String description, int quantity, ProductType productType) {
+ this.name = name;
+ this.description = description;
+ this.quantity = quantity;
+ this.productType = productType;
+ }
+
+ //added constructor with the reference to an hospital
+ public Product(String id, String name, String description, int quantity, ProductType productType,String hospitalId) {
+ this._id = id;
+ this.name = name;
+ this.description = description;
+ this.quantity = quantity;
+ this.productType = productType;
+ this.hospitalId = hospitalId;
+ }
+
+ public String getId() {
+ //return _id.toHexString();
+ return _id;
+ }
+
+ //add setter for product _id
+ public void setId(String id) {
+ this._id=id;
+ }
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getDescription() {
+ return description;
+ }
+ public void setDescription(String description) {
+ this.description = description;
+ }
+ public int getQuantity() {
+ return quantity;
+ }
+ public void setQuantity(int quantity) {
+ this.quantity = quantity;
+ }
+ public ProductType getProductType() {
+ return productType;
+ }
+ public void setProductType(ProductType productType) {
+ this.productType = productType;
+ }
+
+ public void diminuiQuantidade(int quantity){
+ this.quantity-=quantity;
+ }
+
+ //added getters and setters for idHospital
+ public String getHospitalId() {
+ return hospitalId;
+ }
+ public void setIdHospital(String hospitalId) {
+ this.hospitalId = hospitalId;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + ((_id == null) ? 0 : _id.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + quantity;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Product other = (Product) obj;
+ if (description == null) {
+ if (other.description != null)
+ return false;
+ } else if (!description.equals(other.description))
+ return false;
+ if (_id == null) {
+ if (other._id != null)
+ return false;
+ } else if (!_id.equals(other._id))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (quantity != other.quantity)
+ return false;
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/ProductType.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/ProductType.java
new file mode 100644
index 0000000..721aa4f
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/domain/ProductType.java
@@ -0,0 +1,16 @@
+package br.com.codenation.hospital.domain;
+
+public enum ProductType {
+ COMMON("Comum"),
+ BLOOD("Sangue");
+
+ private String descricao;
+
+ ProductType(String descricao) {
+ this.descricao = descricao;
+ }
+
+ public String getDescricao() {
+ return descricao;
+ }
+}
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/dto/HospitalDTO.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/dto/HospitalDTO.java
new file mode 100644
index 0000000..3d08fc3
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/dto/HospitalDTO.java
@@ -0,0 +1,88 @@
+package br.com.codenation.hospital.dto;
+
+import java.io.Serializable;
+import br.com.codenation.hospital.domain.Hospital;
+
+public class HospitalDTO implements Serializable{
+ private static final long serialVersionUID = 1L;
+
+ private String id;
+ private String name;
+ private String address;
+ private int beds;
+ private int availableBeds;
+ private String longitude;
+ private String latitude;
+
+ public HospitalDTO() {
+
+ }
+
+ public HospitalDTO(Hospital obj) {
+ this.id = obj.getId();
+ this.name = obj.getName();
+ this.address = obj.getAddress();
+ this.beds = obj.getBeds();
+ this.availableBeds = obj.getAvailableBeds();
+ if(obj.getLocation() != null) {
+ this.longitude = String.valueOf(obj.getLocation().getPosition().getX());
+ this.latitude = String.valueOf(obj.getLocation().getPosition().getY());
+ }
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getAddress() {
+ return address;
+ }
+
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public int getBeds() {
+ return beds;
+ }
+
+ public void setBeds(int beds) {
+ this.beds = beds;
+ }
+
+ public int getAvailableBeds() {
+ return availableBeds;
+ }
+
+ public void setAvailableBeds(int availableBeds) {
+ this.availableBeds = availableBeds;
+ }
+
+ public String getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(String longitude) {
+ this.longitude = longitude;
+ }
+
+ public String getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(String latitude) {
+ this.latitude = latitude;
+ }
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/dto/LocationDTO.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/dto/LocationDTO.java
new file mode 100644
index 0000000..10c5475
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/dto/LocationDTO.java
@@ -0,0 +1,96 @@
+package br.com.codenation.hospital.dto;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+import br.com.codenation.hospital.domain.Location;
+import br.com.codenation.hospital.domain.Product;
+
+public class LocationDTO implements Serializable {
+ private static final long serialVersionUID = 10L;
+
+ private String id;
+ private String name;
+ private String referenceId;
+ private String category;
+ private String longitude;
+ private String latitude;
+
+ public LocationDTO(String category, String name, String longitude, String latitude) {
+ this.category = category;
+ this.name = name;
+ this.longitude = longitude;
+ this.latitude = latitude;
+ }
+
+ public LocationDTO(Location obj) {
+ this.id = obj.getId();
+ this.category = obj.getLocationCategory().getDescricao();
+ this.referenceId = obj.getReferenceId();
+ this.name = obj.getName();
+ this.latitude = String.valueOf(obj.getPosition().getY());
+ this.longitude = String.valueOf(obj.getPosition().getX());
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getLongitude() {
+ return longitude;
+ }
+
+ public void setLongitude(String longitude) {
+ this.longitude = longitude;
+ }
+
+ public String getLatitude() {
+ return latitude;
+ }
+
+ public void setLatitude(String latitude) {
+ this.latitude = latitude;
+ }
+
+ public String getReferenceId() {
+ return referenceId;
+ }
+
+ public void setReferenceId(String referenceId) {
+ this.referenceId = referenceId;
+ }
+
+ @Override
+ public boolean equals(final Object o) {
+ if (this == o) return true;
+ if (o == null || this.getClass() != o.getClass()) return false;
+ final LocationDTO that = (LocationDTO) o;
+ return Objects.equals(this.getId(), that.getId()) &&
+ Objects.equals(this.getReferenceId(), that.getReferenceId()) &&
+ Objects.equals(this.getName(), that.getName()) &&
+ Objects.equals(this.getLongitude(), that.getLongitude()) &&
+ Objects.equals(this.getLatitude(), that.getLatitude()) &&
+ Objects.equals(this.getCategory(), that.getCategory());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(this.getId(), this.getName(), this.getReferenceId(), this.getLongitude(), this.getLatitude(), this.getCategory());
+ }
+}
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/dto/ProductDTO.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/dto/ProductDTO.java
new file mode 100644
index 0000000..d21552c
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/dto/ProductDTO.java
@@ -0,0 +1,97 @@
+package br.com.codenation.hospital.dto;
+
+import java.io.Serializable;
+
+import javax.validation.constraints.NotEmpty;
+
+import br.com.codenation.hospital.domain.Product;
+import br.com.codenation.hospital.domain.ProductType;
+
+public class ProductDTO implements Serializable{
+ private static final long serialVersionUID = 1L;
+
+ private String id;
+
+ @NotEmpty
+ private String name;
+
+
+ private String description;
+
+ @NotEmpty
+ private int quantity;
+
+ @NotEmpty
+ private ProductType productType;
+
+ //added reference to hospital
+ private String hospitalDTOId;
+
+ public ProductDTO() {
+
+ }
+
+ public ProductDTO(Product obj) {
+ this.id = obj.getId();
+ this.name = obj.getName();
+ this.quantity = obj.getQuantity();
+ this.productType = obj.getProductType();
+ this.hospitalDTOId = obj.getHospitalId();
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getProductName() {
+ return name;
+ }
+
+ public void setProductName(String productName) {
+ this.name = productName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(int quantity) {
+ this.quantity = quantity;
+ }
+
+ public ProductType getProductType() {
+ return productType;
+ }
+
+ public void setProductType(ProductType productType) {
+ this.productType = productType;
+ }
+ //added setters and getters for hospitalId
+ public void setHospitalId(String hospitalDTOId) {
+ this.hospitalDTOId = hospitalDTOId;
+ }
+
+ public String getHospitalDTOId() {
+ return hospitalDTOId;
+ }
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/integration/LocationIQResponse.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/integration/LocationIQResponse.java
new file mode 100644
index 0000000..aa6e891
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/integration/LocationIQResponse.java
@@ -0,0 +1,107 @@
+package br.com.codenation.hospital.integration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonGetter;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class LocationIQResponse {
+
+ private String placeId;
+ private String licence;
+ private String osmType;
+ private String osmId;
+ private List boundingbox;
+ private String lat;
+ private String lon;
+ private String displayName;
+ private String classfication;
+ private String type;
+ private String importance;
+ private String icon;
+
+
+ public LocationIQResponse() {
+ boundingbox = new ArrayList<>();
+ }
+
+ @JsonCreator
+ public LocationIQResponse(
+ @JsonProperty("place_id") String placeId,
+ @JsonProperty("licence") String licence,
+ @JsonProperty("osm_type") String osmType,
+ @JsonProperty("osm_id") String osmId,
+ @JsonProperty("boundingbox") List boundingbox,
+ @JsonProperty("lat") String lat,
+ @JsonProperty("lon") String lon,
+ @JsonProperty("display_name") String displayName,
+ @JsonProperty("class") String classfication,
+ @JsonProperty("type") String type,
+ @JsonProperty("importance") String importance,
+ @JsonProperty("icon") String icon)
+ {
+ this.placeId = placeId;
+ this.licence = licence;
+ this.osmType = osmType;
+ this.osmId = osmId;
+ this.boundingbox = boundingbox;
+ this.lat = lat;
+ this.lon = lon;
+ this.displayName = displayName;
+ this.classfication = classfication;
+ this.type = type;
+ this.importance = importance;
+ this.icon = icon;
+ }
+
+ public String getPlaceId() {
+ return placeId;
+ }
+
+ public String getLicence() {
+ return licence;
+ }
+
+ public String getOsmType() {
+ return osmType;
+ }
+
+ public String getOsmId() {
+ return osmId;
+ }
+
+ public List getBoundingbox() {
+ return boundingbox;
+ }
+
+ public String getLat() {
+ return lat;
+ }
+
+ public String getLon() {
+ return lon;
+ }
+
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ public String getClassfication() {
+ return classfication;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public String getImportance() {
+ return importance;
+ }
+
+ public String getIcon() {
+ return icon;
+ }
+
+}
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/integration/LocationIQService.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/integration/LocationIQService.java
new file mode 100644
index 0000000..7c4d37a
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/integration/LocationIQService.java
@@ -0,0 +1,81 @@
+package br.com.codenation.hospital.integration;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import br.com.codenation.hospital.resource.ProductResource;
+
+@Service
+public class LocationIQService {
+ private static final Logger LOGGER = LoggerFactory.getLogger(LocationIQService.class);
+
+ private final String locationKey = "43b382813d8baa";
+ private final String locationFormat = "json";
+ private final String locationUrl = "https://us1.locationiq.com/v1/search.php";
+
+ public LocationIQService() {
+ }
+
+ public List getLocationIQResponse(String search) {
+ return CallLocationIQAPI(search);
+ }
+
+ private List CallLocationIQAPI(String search) {
+ ArrayList locationsResponse = new ArrayList<>();
+
+ try {
+ Thread.sleep(1000);
+
+ URL url = new URL(locationUrl + "?key=" + locationKey + "&q=" + URLEncoder.encode(search, "UTF-8") + "&format=" + locationFormat);
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ conn.setRequestMethod("GET");
+ conn.setRequestProperty("Accept", "application/json");
+
+ BufferedReader br;
+ if (200 <= conn.getResponseCode() && conn.getResponseCode() <= 299) {
+ br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
+ } else {
+ br = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
+ }
+
+ StringBuilder sb = new StringBuilder();
+ String output;
+ while ((output = br.readLine()) != null) {
+ sb.append(output);
+ }
+
+ if (conn.getResponseCode() != 200) {
+ LOGGER.error("Failed : HTTP error - Error with message: {}", sb.toString());
+ throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
+ }
+
+ conn.disconnect();
+
+ locationsResponse = new ObjectMapper()
+ .readValue(sb.toString(), new TypeReference>() {});
+
+ } catch (MalformedURLException e) {
+ LOGGER.error("getLocationIQResponse - MalformedURLException - Error with message: {}", e.getMessage());
+ } catch (IOException e) {
+ LOGGER.error("getLocationIQResponse - IOException - Error with message: {}", e.getMessage());
+ } catch (InterruptedException e) {
+ LOGGER.error("getLocationIQResponse - InterruptedException - Error with message: {}", e.getMessage());
+ }
+
+ return locationsResponse;
+ }
+}
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/repository/HospitalRepository.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/repository/HospitalRepository.java
new file mode 100644
index 0000000..583206f
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/repository/HospitalRepository.java
@@ -0,0 +1,16 @@
+package br.com.codenation.hospital.repository;
+
+import java.util.List;
+
+import org.springframework.data.geo.Point;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+import br.com.codenation.hospital.domain.Hospital;
+import br.com.codenation.hospital.domain.Product;
+
+@Repository
+public interface HospitalRepository extends MongoRepository{
+ List findByNameLikeIgnoreCase(String name);
+
+// List findByPositionNearAndAvailableBeds(Point p, int beds);
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/repository/LocationRepository.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/repository/LocationRepository.java
new file mode 100644
index 0000000..b25c09a
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/repository/LocationRepository.java
@@ -0,0 +1,26 @@
+package br.com.codenation.hospital.repository;
+
+import br.com.codenation.hospital.domain.Hospital;
+import br.com.codenation.hospital.domain.Location;
+import br.com.codenation.hospital.domain.Product;
+
+import java.util.List;
+
+import org.springframework.data.geo.Box;
+import org.springframework.data.geo.Circle;
+import org.springframework.data.geo.Distance;
+import org.springframework.data.geo.Point;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface LocationRepository extends MongoRepository {
+
+ List findByNameAndLocationNear(String sid, Point p, Distance d);
+
+ List findByNameLikeIgnoreCase(String subject);
+
+ List findByPositionNear(Point p, Distance d);
+
+
+}
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/repository/PatientRepository.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/repository/PatientRepository.java
new file mode 100644
index 0000000..ec5a29f
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/repository/PatientRepository.java
@@ -0,0 +1,11 @@
+package br.com.codenation.hospital.repository;
+
+import org.springframework.data.mongodb.repository.MongoRepository;
+import org.springframework.stereotype.Repository;
+
+import br.com.codenation.hospital.domain.Patient;
+
+@Repository
+public interface PatientRepository extends MongoRepository{
+
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/repository/ProductRepository.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/repository/ProductRepository.java
new file mode 100644
index 0000000..ae6f117
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/repository/ProductRepository.java
@@ -0,0 +1,14 @@
+package br.com.codenation.hospital.repository;
+
+import java.util.List;
+
+import org.bson.types.ObjectId;
+import org.springframework.data.mongodb.repository.MongoRepository;
+import br.com.codenation.hospital.domain.Product;
+
+
+public interface ProductRepository extends MongoRepository{
+ Product findBy_id(ObjectId _id);
+
+ List findByNameLikeIgnoreCase(String name);
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/HospitalResource.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/HospitalResource.java
new file mode 100644
index 0000000..ca5140d
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/HospitalResource.java
@@ -0,0 +1,129 @@
+package br.com.codenation.hospital.resource;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import br.com.codenation.hospital.domain.LocationBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import br.com.codenation.hospital.constant.Constant;
+import br.com.codenation.hospital.domain.Hospital;
+import br.com.codenation.hospital.domain.Location;
+import br.com.codenation.hospital.dto.HospitalDTO;
+import br.com.codenation.hospital.resource.exception.ResourceNotFoundException;
+import br.com.codenation.hospital.services.HospitalService;
+
+@CrossOrigin("http://localhost:4200") // permissão para o Angular
+@RestController
+@RequestMapping(path = Constant.V1)
+public class HospitalResource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ProductResource.class);
+
+ @Autowired
+ private HospitalService service;
+
+ @GetMapping()
+ public ResponseEntity> findAll() {
+ try {
+ List list = service.findAll();
+ List listDTO = list.stream().map(x -> new HospitalDTO(x)).collect(Collectors.toList());
+ return ResponseEntity.ok().body(listDTO);
+ } catch (Exception e) {
+ LOGGER.error("findAllHospital - Error with message: {}", e.getMessage());
+ return ResponseEntity.badRequest().build();
+ }
+ }
+
+ @GetMapping(path = "/{hospital_id}")
+ public ResponseEntity findById(@PathVariable String hospital_id) {
+ try {
+ Hospital obj = service.findById(hospital_id);
+
+ HospitalDTO hospitalDTO = new HospitalDTO(obj);
+
+ return Optional.ofNullable(hospitalDTO).map(hospitalResponse -> ResponseEntity.ok().body(hospitalResponse))
+ .orElseGet(() -> ResponseEntity.notFound().build());
+ } catch (Exception e) {
+ LOGGER.error("findHospitalById - Error with message: {}", e.getMessage());
+ return ResponseEntity.notFound().build();
+ }
+ }
+
+
+ @PostMapping()
+ public ResponseEntity insert(@RequestBody HospitalDTO objDTO) {
+ try {
+ Hospital obj = service.fromDTO(objDTO);
+ if(obj.getName().equals("") || obj.getAddress().equals("") || obj.getBeds()<0 || obj.getAvailableBeds()<0) {
+ throw new ResourceNotFoundException("Preencha os campos corretamente!"); //precisa tratar erro
+ }
+ obj = service.insert(obj);
+ HospitalDTO hospitalDTO = new HospitalDTO(obj);
+ return Optional.ofNullable(hospitalDTO).map(hospitalResponse -> ResponseEntity.ok().body(hospitalResponse))
+ .orElseGet(() -> ResponseEntity.notFound().build());
+ } catch (Exception e) {
+ LOGGER.error("insertHospital - Handling error with message: {}", e.getMessage());
+ return ResponseEntity.badRequest().build();
+ }
+ }
+
+ @DeleteMapping(path = "/{hospital_id}")
+ public ResponseEntity deleteById(@PathVariable String hospital_id) {
+ try {
+ Hospital obj = service.findById(hospital_id);
+ if (obj != null) {
+ service.delete(hospital_id);
+ }
+ return Optional.ofNullable(obj)
+ .map(hospitalResponse -> ResponseEntity.ok().body("Hospital apagado id: " + hospital_id))
+ .orElseGet(() -> ResponseEntity.notFound().build());
+ } catch (Exception e) {
+ LOGGER.error("deleteHospitalById - Handling error with message: {}", e.getMessage());
+ return ResponseEntity.badRequest().build();
+ }
+ }
+
+ @PutMapping(path = "/{hospital_id}")
+ public ResponseEntity update(@RequestBody HospitalDTO objDTO, @PathVariable String hospital_id) {
+ try {
+ Hospital obj = service.fromDTO(objDTO);
+ obj.setId(hospital_id);
+ if(obj.getName().equals("") || obj.getAddress().equals("") || obj.getBeds()<0 || obj.getAvailableBeds()<0) {
+ throw new ResourceNotFoundException("Preencha os campos corretamente!"); //precisa tratar erro
+ }
+ obj = service.update(obj);
+ HospitalDTO hospitalDTO = new HospitalDTO(obj);
+ return Optional.ofNullable(hospitalDTO).map(hospitalResponse -> ResponseEntity.ok().body(hospitalResponse))
+ .orElseGet(() -> ResponseEntity.notFound().build());
+ } catch (Exception e) {
+ LOGGER.error("updateHospital - Handling error with message: {}", e.getMessage());
+ return ResponseEntity.badRequest().build();
+ }
+ }
+
+ @GetMapping(path = "/{id}/leitos")
+ public Map verificaLeitosDisponiveis(@PathVariable String id) {
+ Hospital hospital = service.findById(id);
+ Map leitos = new HashMap<>();
+ leitos.put("leitos", hospital.getAvailableBeds());
+ return leitos;
+ }
+
+ @GetMapping(path = "/maisProximo")
+ public HospitalDTO hospitalMaisProximo(@RequestParam Double lat, @RequestParam Double lon, @RequestParam Double raioMaximo) {
+ return service.findHospitalMaisProximoComVagas(lat, lon, raioMaximo);
+ }
+
+ @PostMapping(path = "{id}/transferencia/{productId}")
+ public String transferenciaProduto(@PathVariable String id, @PathVariable String productId, @RequestBody Integer quantidade) {
+ Hospital hospital = service.findById(id);
+ return service.transfereProduto(hospital, productId, quantidade);
+ }
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/LocationResource.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/LocationResource.java
new file mode 100644
index 0000000..6cecd28
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/LocationResource.java
@@ -0,0 +1,66 @@
+package br.com.codenation.hospital.resource;
+
+import java.util.List;
+import java.util.Optional;import java.util.stream.Collector;
+import java.util.stream.Collectors;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.geo.Distance;
+import org.springframework.data.geo.Metrics;
+import org.springframework.data.geo.Point;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import br.com.codenation.hospital.constant.Constant;
+import br.com.codenation.hospital.domain.Hospital;
+import br.com.codenation.hospital.domain.Location;
+import br.com.codenation.hospital.domain.LocationCategory;
+import br.com.codenation.hospital.dto.HospitalDTO;
+import br.com.codenation.hospital.dto.LocationDTO;
+import br.com.codenation.hospital.dto.ProductDTO;
+import br.com.codenation.hospital.repository.LocationRepository;
+import br.com.codenation.hospital.services.HospitalService;
+import br.com.codenation.hospital.services.LocationService;
+
+@CrossOrigin("http://localhost:4200") // permissão para o Angular
+@RestController
+@RequestMapping(path = Constant.V1Path)
+public class LocationResource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(LocationResource.class);
+ @Autowired
+ private LocationService locationService;
+
+ @GetMapping(path = "/proximidades")
+ public ResponseEntity> findLocationNearHospitalBy(@PathVariable String hospital_id) {
+ try {
+ List locations = locationService.findLocationNearHospitalBy(hospital_id);
+
+ return Optional.ofNullable(locations).map(productReponse -> ResponseEntity.ok().body(productReponse))
+ .orElseGet(() -> ResponseEntity.notFound().build());
+ } catch (Exception ex) {
+ LOGGER.error("findLocationNearHospitalBy - Handling error with message: {}", ex.getMessage());
+ return ResponseEntity.badRequest().build();
+ }
+ }
+
+ @GetMapping(path = "/hospitaisProximos")
+ public ResponseEntity> findHospitalNearHospitalBy(@PathVariable String hospital_id, @RequestParam Double raio) {
+ try {
+ List locations = locationService.findHospitalNearHospitalBy(hospital_id, raio);
+
+ return Optional.ofNullable(locations).map(productReponse -> ResponseEntity.ok().body(productReponse))
+ .orElseGet(() -> ResponseEntity.notFound().build());
+ } catch (Exception ex) {
+ LOGGER.error("findHospitalNearHospitalBy - Handling error with message: {}", ex.getMessage());
+ return ResponseEntity.badRequest().build();
+ }
+ }
+}
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/PatientResource.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/PatientResource.java
new file mode 100644
index 0000000..ef62920
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/PatientResource.java
@@ -0,0 +1,113 @@
+package br.com.codenation.hospital.resource;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import br.com.codenation.hospital.constant.Constant;
+import br.com.codenation.hospital.domain.Hospital;
+import br.com.codenation.hospital.domain.Patient;
+import br.com.codenation.hospital.resource.exception.ResourceNotFoundException;
+import br.com.codenation.hospital.services.HospitalService;
+import br.com.codenation.hospital.services.PatientService;
+
+@CrossOrigin("http://localhost:4200") // permissão para o Angular
+@RestController
+@RequestMapping(path = Constant.V1Path)
+public class PatientResource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ProductResource.class);
+
+ @Autowired
+ private PatientService service;
+
+ @Autowired
+ private HospitalService hospitalService;
+
+ @GetMapping(path = "pacientes")
+ public ResponseEntity> findPatients(@PathVariable String hospital_id) {
+ try {
+ Hospital obj = hospitalService.findById(hospital_id);
+ List patientList = obj.getPatients();
+ if (patientList != null) {
+ return ResponseEntity.ok(patientList);
+ }
+ throw new ResourceNotFoundException("Hospital sem pacientes!");
+ } catch (Exception e) {
+ LOGGER.error("findPatients - Error with message: {}", e.getMessage());
+ return ResponseEntity.notFound().build();
+ }
+ }
+
+ @GetMapping(path = "pacientes/{patientId}")
+ public ResponseEntity findPatientById(@PathVariable String hospital_id, @PathVariable String patientId) {
+ try {
+ Patient patient = service.findById(patientId);
+ return ResponseEntity.ok().body(patient);
+ } catch (Exception e) {
+ LOGGER.error("findPatientById - Error with message: {}", e.getMessage());
+ return ResponseEntity.notFound().build();
+ }
+ }
+
+ // added post endpint for insert paciente
+ @PostMapping(path = "paciente")
+ public ResponseEntity insertPaciente(@RequestBody Patient patient) {
+ try {
+ Hospital hospital = hospitalService.findById(patient.getIdHospital());
+ return ResponseEntity.ok(hospitalService.checkIn(hospital, patient));
+ } catch (Exception e) {
+ LOGGER.error("insert Paciente - Error with message: {}", e.getMessage());
+ return ResponseEntity.notFound().build();
+ }
+ }
+
+
+ @PostMapping(path = "pacientes/checkin", produces = "application/json")
+ public ResponseEntity checkinPacient(@PathVariable("hospital_id") String idHospital, @RequestBody Patient patient) {
+ try {
+ Hospital hospital = hospitalService.findById(idHospital);
+ return ResponseEntity.ok(hospitalService.checkIn(hospital, patient));
+ } catch (Exception e) {
+ LOGGER.error("checkinPacient - Error with message: {}", e.getMessage());
+ return ResponseEntity.notFound().build();
+ }
+ }
+
+ @PostMapping(path = "pacientes/checkout", produces = "application/json")
+ public ResponseEntity checkoutPacient(@PathVariable("hospital_id") String idHospital, @RequestBody String idPatient) {
+ try {
+ Hospital hospital = hospitalService.findById(idHospital);
+ return ResponseEntity.ok(hospitalService.checkOut(hospital, idPatient));
+ } catch (Exception e) {
+ LOGGER.error("checkoutPacient - Error with message: {}", e.getMessage());
+ return ResponseEntity.notFound().build();
+ }
+ }
+
+ @PutMapping(path = "pacientes/{patientId}")
+ public ResponseEntity updatePatient(@PathVariable("hospital_id") String idHospital, @PathVariable String patientId,
+ @RequestBody Patient patient) {
+ try {
+ Patient p = service.findById(patientId);
+ p.setName(patient.getName());
+ p.setCpf(patient.getCpf());
+ p.setBirthDate(patient.getBirthDate());
+ p.setGender(patient.getGender());
+ return ResponseEntity.ok(service.update(p));
+ } catch (Exception e) {
+ LOGGER.error("updatePatient - Error with message: {}", e.getMessage());
+ return ResponseEntity.notFound().build();
+ }
+ }
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/ProductResource.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/ProductResource.java
new file mode 100644
index 0000000..1426242
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/ProductResource.java
@@ -0,0 +1,120 @@
+package br.com.codenation.hospital.resource;
+
+import java.util.List;
+import java.util.Optional;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import br.com.codenation.hospital.constant.Constant;
+import br.com.codenation.hospital.dto.ProductDTO;
+import br.com.codenation.hospital.services.ProductService;
+
+@CrossOrigin("http://localhost:4200") // permissão para o Angular
+@RestController
+//@RequestMapping(path = Constant.V1Path)
+
+//Para los resorurces de Product está utilizando como path base para los endpoints V1Path="/v1/hospitais/{hospital_id}/".
+//Dado que no se manejan aún los endpoint con variables en el paht ({hospital_id}), se utiliza como path base V1= "/v1/hospitais/"y
+//se modifican los endpoints correspondientes para obtener el id ({hospital_id}) sin necesidad de que vayan en el path
+@RequestMapping(path = Constant.V1)
+
+public class ProductResource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ProductResource.class);
+
+ @Autowired
+ private ProductService service;
+
+ @GetMapping(path = "estoque/{produto_id}")
+ public ResponseEntity findProductBy(@PathVariable String hospital_id, @PathVariable String produto_id) {
+ try {
+ ProductDTO productDTO = service.findById(produto_id);
+ return Optional.ofNullable(productDTO).map(productReponse -> ResponseEntity.ok().body(productReponse))
+ .orElseGet(() -> ResponseEntity.notFound().build());
+ } catch (Exception ex) {
+ LOGGER.error("findProductBy - Handling error with message: {}", ex.getMessage());
+ return ResponseEntity.notFound().build();
+ }
+ }
+
+ @GetMapping(path = "estoque")
+ public ResponseEntity> findAllProductBy(@PathVariable String hospital_id) {
+ try {
+ List productList = service.findByHospitalId(hospital_id);
+ return Optional.ofNullable(productList).map(productReponse -> ResponseEntity.ok().body(productReponse))
+ .orElseGet(() -> ResponseEntity.notFound().build());
+ } catch (Exception ex) {
+ LOGGER.error("findAllProductBy - Handling error with message: {}", ex.getMessage());
+ return ResponseEntity.badRequest().build();
+ }
+ }
+
+ /*@PostMapping(path = "estoque")
+ public ResponseEntity insert(@PathVariable String hospital_id, @RequestBody ProductDTO productDTO) {
+ try {
+ ProductDTO newProductDTO = service.insert(hospital_id, productDTO);
+ return Optional.ofNullable(newProductDTO).map(productReponse -> ResponseEntity.ok().body(productReponse))
+ .orElseGet(() -> ResponseEntity.notFound().build());
+ } catch (Exception ex) {
+ LOGGER.error("insert - Handling error with message: {}", ex.getMessage());
+ return ResponseEntity.badRequest().build();
+ }
+ }*/
+
+ //Modificado endpoint (original) para insertar un producto en un hospital sin utilizar PathVariable hospital_id.
+ //hospital_id lo obtiene del productDTO
+ @PostMapping(path = "estoque")
+ public ResponseEntity insert(@RequestBody ProductDTO productDTO) {
+ try {
+ String hospital_id = productDTO.getHospitalDTOId();
+ ProductDTO newProductDTO = service.insert(hospital_id, productDTO);
+ return Optional.ofNullable(newProductDTO).map(productReponse -> ResponseEntity.ok().body(productReponse))
+ .orElseGet(() -> ResponseEntity.notFound().build());
+ } catch (Exception ex) {
+ LOGGER.error("insert - Handling error with message: {}", ex.getMessage());
+ return ResponseEntity.badRequest().build();
+ }
+ }
+
+ @DeleteMapping(path = "estoque/{produto_id}")
+ public ResponseEntity delete(@PathVariable String hospital_id, @PathVariable String produto_id) {
+ try {
+ ProductDTO deleteProductDTO = service.findById(produto_id);
+ if (deleteProductDTO != null) {
+ service.delete(hospital_id, deleteProductDTO.getId());
+ }
+ return Optional.ofNullable(deleteProductDTO)
+ .map(productReponse -> ResponseEntity.ok().body("Produto apagado id: " + produto_id))
+ .orElseGet(() -> ResponseEntity.notFound().build());
+ } catch (Exception ex) {
+ LOGGER.error("delete - Handling error with message: {}", ex.getMessage());
+ return ResponseEntity.badRequest().build();
+ }
+ }
+
+ @PutMapping(path = "estoque/{produto_id}")
+ public ResponseEntity update(@RequestBody ProductDTO productDTO, @PathVariable String hospital_id,
+ @PathVariable String produto_id) {
+ try {
+ productDTO.setId(produto_id);
+ ProductDTO updateProductDTO = service.update(hospital_id, productDTO);
+ return Optional.ofNullable(updateProductDTO)
+ .map(hospitalReponse -> ResponseEntity.ok().body(hospitalReponse))
+ .orElseGet(() -> ResponseEntity.notFound().build());
+ } catch (Exception ex) {
+ LOGGER.error("update - Handling error with message: {}", ex.getMessage());
+ return ResponseEntity.badRequest().build();
+ }
+ }
+}
\ No newline at end of file
diff --git a/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/TestResource.java b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/TestResource.java
new file mode 100644
index 0000000..9eb063b
--- /dev/null
+++ b/sut-gestaoHospital/src/main/java/br/com/codenation/hospital/resource/TestResource.java
@@ -0,0 +1,51 @@
+package br.com.codenation.hospital.resource;
+
+import java.util.Optional;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.DeleteMapping;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import br.com.codenation.hospital.constant.Constant;
+import br.com.codenation.hospital.services.TestService;
+
+@RestController
+@RequestMapping(path = Constant.V1)
+
+// Added a resource for test
+
+public class TestResource {
+ private static final Logger LOGGER = LoggerFactory.getLogger(TestResource.class);
+
+ @Autowired
+ private TestService service;
+
+ @DeleteMapping(path = "/test/deleteAll")
+ public ResponseEntity deleteAll() {
+ try {
+ service.deleteAll();
+ return ResponseEntity.ok().body("Deleted all data");
+
+ } catch (Exception e) {
+ LOGGER.error("deleteAll - Handling error with message: {}", e.getMessage());
+ return ResponseEntity.badRequest().build();
+ }
+ }
+
+ @GetMapping(path = "/test/getAll")
+ public ResponseEntity