Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
Base de Datos
Browse files Browse the repository at this point in the history
  • Loading branch information
yoss0108 committed May 23, 2015
1 parent 982b20b commit 2e98f8c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 90 deletions.
13 changes: 2 additions & 11 deletions src/citasalud/apps/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
# coding=utf-8

from rest_framework import serializers
from citasalud.apps.main.models import Perfil, Medico, Especialidad
from django.contrib.auth.models import User


class PerfilUsuarioSerializer(serializers.ModelSerializer):
""" Serializador para Perfil de Usuario """

class Meta:
model = Perfil
from citasalud.apps.main.models import Usuario, Medico, Especialidad


class MedicoSerializer(serializers.ModelSerializer):
Expand All @@ -20,10 +12,9 @@ class Meta:


class UsuarioSerializer(serializers.ModelSerializer):
profile = PerfilUsuarioSerializer()

class Meta:
model = User
model = Usuario
# fields = ('id', 'username', 'profile','is_superuser')

def create(self, validated_data):
Expand Down
4 changes: 2 additions & 2 deletions src/citasalud/apps/api/viewsets.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from ..main.models import Medico, Especialidad, User
from ..main.models import Medico, Especialidad, Usuario
from .serializers import UsuarioSerializer, MedicoSerializer, EspecialidadSerializer
from rest_framework import viewsets


class UsuarioViewSet(viewsets.ModelViewSet):
serializer_class = UsuarioSerializer
queryset = User.objects.all()
queryset = Usuario.objects.all()


class MedicoViewSet(viewsets.ModelViewSet):
Expand Down
27 changes: 13 additions & 14 deletions src/citasalud/apps/main/admin.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
# coding=utf-8

from django.contrib import admin
from .models import Perfil, Especialidad, CitaMedica, Medico, Paciente, Personal
# from django.contrib.auth.admin import UserAdmin
from .models import (Usuario, Especialidad, CitaMedica, Medico,
Paciente, Empleado, HistoriaClinica, Examen,
TipoExamen,)
from django.contrib.auth.admin import UserAdmin


# class UsuarioAdmin(UserAdmin):
# model = Usuario

# fieldsets = UserAdmin.fieldsets + (
# (None, {'fields': ("dni", "nombre", "apellidos", "fecha_nacimiento", "telefono", "ciudad",)}),
# )
# ordering = []
admin.site.register(Perfil)
admin.site.register(Paciente)
admin.site.register(Personal)
admin.site.register(Medico)
admin.site.register(CitaMedica)
admin.site.register(Usuario)
admin.site.register(Especialidad)
admin.site.register(CitaMedica)
admin.site.register(Medico)
admin.site.register(Paciente)
admin.site.register(Empleado)
admin.site.register(HistoriaClinica)
admin.site.register(Examen)
admin.site.register(TipoExamen)

# admin.site.register(Usuario, UsuarioAdmin)

# class PersonalAdmin(admin.ModelAdmin):
Expand Down
125 changes: 63 additions & 62 deletions src/citasalud/apps/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
from django.db import models
from .constants import TIPO_MEDICO
from .customfields import DNIField, PrimaryNumberField
from django.contrib.auth.models import User
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager, PermissionsMixin


class UsuarioManager(BaseUserManager):
def create_user(self, dni,fecha_nacimiento, nombres,apellido_paterno,password =None):
def create_user(self, dni,fecha_nacimiento, first_name,last_name,password =None):
"""
Creates and saves a User with the given email, date of
birth and password.
Expand All @@ -17,38 +16,38 @@ def create_user(self, dni,fecha_nacimiento, nombres,apellido_paterno,password =N

user = self.model(
dni=dni,
nombres=nombres,
apellido_paterno=apellido_paterno,
first_name=first_name,
last_name=last_name,
fecha_nacimiento=fecha_nacimiento
)

user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, dni,fecha_nacimiento, nombres,apellido_paterno,password):
def create_superuser(self, dni,fecha_nacimiento, first_name,last_name,password):
"""
Creates and saves a superuser with the given email, date of
birth and password.
"""
user = self.create_user(dni,
password=password,
nombres=nombres,
apellido_paterno=apellido_paterno,
first_name=first_name,
last_name=last_name,
fecha_nacimiento=fecha_nacimiento
)
user.is_active=True
user.is_admin = True
user.is_active = True
user.is_superuser = True
user.is_staff = True
user.save(using=self._db)
return user

# def normalize_dni (self,dni):


class Usuario(AbstractBaseUser):
dni = DNIField("DNI", unique=True , primary_key= True )
nombre = models.CharField("Nombre", max_length=32)
apellido_paterno = models.CharField("Ap. Paterno", max_length=16)
class Usuario(AbstractBaseUser, PermissionsMixin):
dni = DNIField("DNI", unique=True , primary_key= True)
username = models.CharField("Username", max_length=16)
first_name = models.CharField("Nombre", max_length=32)
last_name = models.CharField("Ap. Paterno", max_length=16)
apellido_materno = models.CharField("Ap. Materno", max_length=16)

fecha_nacimiento = models.DateField("Fecha de Nacimiento")
Expand All @@ -59,68 +58,38 @@ class Usuario(AbstractBaseUser):
email = models.EmailField("E-mail", unique=True, blank=True)
avatar = models.ImageField("Imagen", upload_to="avatar", null=False, default="/media/avatar/sin_imagen.png", blank=True)

is_active=models.BooleanField(default=False)
is_admin=models.BooleanField(default = False)

objects=UsuarioManager()
is_active = models.BooleanField(default = False)
is_staff = models.BooleanField(default = False)
objects = UsuarioManager()

USERNAME_FIELDS= 'dni'
REQUIRED_FIELDS = [ 'fecha_nacimiento','nombres' ,'apellido_paterno' ]
USERNAME_FIELD= 'dni'
REQUIRED_FIELDS = [ 'fecha_nacimiento','first_name' ,'last_name' ]

def get_name(self):
return self.nombre.split(" ")[0]
return self.first_name.split(" ")[0]

def get_full_name(self):
return "%s %s %s" % (self.nombre, self.apellido_paterno, self.apellido_materno)
return "%s %s %s" % (self.first_name, self.last_name, self.apellido_materno)

def get_short_name(self):
return "%s %s" % (self.get_name(), self.apellido_paterno)
return "%s %s" % (self.get_name(), self.last_name)

def __unicode__(self):
return "[%s] %s" % (self.dni, self.get_full_name())

@property
def is_staff(self):
"Is the user a member of staff?"
# Simplest possible answer: All admins are staff
return self.is_admin

# def has_perm(self, perm, obj=None):
# #"Does the user have a specific permission?"
# # Simplest possible answer: Yes, always
# return True
#
# def has_module_perms(self, app_label):
# "Does the user have permissions to view the app `app_label`?"
# # Simplest possible answer: Yes, always
# return True


class Paciente(models.Model):
usuario = models.ForeignKey(Usuario, unique=True, related_name="paciente")
nss = PrimaryNumberField("NSS", digits=9)

def __unicode__(self):
return "%s (%s)" % (self.usuario.get_short_name(), self.nss)

class Meta:
verbose_name = "Paciente"
verbose_name_plural = "Pacientes"


class Personal(models.Model):
usuario = models.ForeignKey(User, unique=True, related_name="personal")
nregistropersonal = PrimaryNumberField("N° Registro personal")
class Empleado(models.Model):
usuario = models.OneToOneField(Usuario, unique=True, related_name="personal")
nregistropersonal = PrimaryNumberField("N° Registro de Personal")
departamento = models.CharField("Departamento", max_length=32)

# class Meta:
# proxy = True
cargo = models.CharField("Cargo", max_length=32)
superior = models.ForeignKey('Empleado', related_name="jefe")


class Medico(Personal):
ncolegiado = PrimaryNumberField("N° Colegiado")
class Medico(Empleado):
ncolegiado = models.PositiveIntegerField("N° Colegiado")
especialidades = models.ManyToManyField("Especialidad", blank=True, related_name='especialidades')

def _tipo(self):
return TIPO_MEDICO.ESPECIALISTA if self.especialidades else TIPO_MEDICO.GENERAL
tipo = property(_tipo)
Expand Down Expand Up @@ -157,6 +126,38 @@ class Meta:
verbose_name = u"Cita médica"
verbose_name_plural = "Citas médicas"


class TipoExamen(models.Model):
nombre = models.CharField("Examen", max_length=64)
descripcion = models.CharField("Descripción", max_length=128)


class Resultado(models.Model):
examen = models.ForeignKey("Examen")
documento = models.PositiveIntegerField("N° de Documento Asociado")
descripcion = models.CharField("Descripción", max_length=256)


class Examen(models.Model):
fecha_solitud = models.DateField("Fecha de Solicitud")
tipo_examen = models.ForeignKey("TipoExamen")
fecha_aplicacion = models.DateField("Fecha de aplicación")
observacion = models.CharField("Observacion", max_length=256)
historia = models.ForeignKey("Paciente")


class Paciente(models.Model):
usuario = models.OneToOneField(Usuario, unique=True, related_name="paciente")
nss = PrimaryNumberField("NSS", digits=9)

def __unicode__(self):
return "%s (%s)" % (self.usuario.get_short_name(), self.nss)

class Meta:
verbose_name = "Paciente"
verbose_name_plural = "Pacientes"


class HistoriaClinica(models.Model):
paciente = models.ForeignKey("Paciente", unique=True)
numero = models.CharField("N° H.C.", max_length=5, primary_key=True)
paciente = models.OneToOneField("Paciente", unique=True)
2 changes: 1 addition & 1 deletion src/citasalud/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

ROOT_URLCONF = 'citasalud.urls'

AUTH_PROFILE_MODULE = 'main.PerfilUsuario'
AUTH_USER_MODEL = 'main.Usuario'

TEMPLATES = [
{
Expand Down

0 comments on commit 2e98f8c

Please sign in to comment.