class ProblemTodoSerializer(serializers.ModelSerializer): labels = LabelSerializer(many=True) comments = CommentToDoSerializer(many=True) attachments = AttachmentToDoSerializer(many=True) patient = SafeUserSerializer() members = SafeUserSerializer(many=True) due_date = serializers.DateTimeField(format='%m/%d/%Y') class Meta: model = ToDo fields = ( 'id', 'patient', 'user', 'todo', 'accomplished', 'due_date', 'a1c', 'colon_cancer', 'labels', 'comments', 'attachments', 'members', 'document_set', 'created_at', 'created_on', )
class ObservationSerializer(serializers.ModelSerializer): subject = SafeUserSerializer() encounter = SafeUserSerializer() performer = SafeUserSerializer() author = SafeUserSerializer() observation_components = ObservationComponentSerializer(many=True, read_only=True) observation_units = ObservationUnitSerializer(many=True, read_only=True) class Meta: model = Observation fields = ( 'id', 'name', 'status', 'category', 'code', 'subject', 'encounter', 'performer', 'author', 'effective_datetime', 'comments', 'created_on', 'observation_components', 'observation_units', 'color', 'graph', )
class LabeledProblemListSerializer(serializers.ModelSerializer): user = SafeUserSerializer() patient = SafeUserSerializer() labels = ProblemLabelSerializer(many=True) class Meta: model = LabeledProblemList fields = ('id', 'user', 'patient', 'labels', 'note', 'name')
class MyStoryTabSerializer(serializers.ModelSerializer): patient = SafeUserSerializer() author = SafeUserSerializer() my_story_tab_components = MyStoryTextComponentSerializer(many=True) class Meta: model = MyStoryTab fields = ('id', 'patient', 'author', 'name', 'datetime', 'private', 'is_all', 'my_story_tab_components')
class MyStoryTextComponentSerializer(serializers.ModelSerializer): patient = SafeUserSerializer() author = SafeUserSerializer() text_component_entries = MyStoryTextComponentEntrySerializer(many=True) class Meta: model = MyStoryTextComponent fields = ('id', 'patient', 'author', 'tab', 'name', 'datetime', 'concept_id', 'private', 'is_all', 'text_component_entries')
class InrTextNoteSerializer(serializers.ModelSerializer): author = SafeUserSerializer() patient = SafeUserSerializer() class Meta: model = InrTextNote fields = ( 'id', 'author', 'note', 'datetime', 'patient', )
class ProblemLabelSerializer(serializers.ModelSerializer): author = SafeUserSerializer() patient = SafeUserSerializer() class Meta: model = ProblemLabel fields = ( 'id', 'name', 'css_class', 'author', 'patient', )
class INRPatientSerializer(serializers.ModelSerializer): """ """ avatar = serializers.SerializerMethodField() full_name = serializers.SerializerMethodField() date_of_birth = serializers.DateTimeField(format='%m/%d/%Y') problem_id = serializers.SerializerMethodField() user = SafeUserSerializer(many=False) class Meta: model = UserProfile fields = ('id', 'avatar', 'user', 'full_name', 'date_of_birth', 'problem_id') def get_avatar(self, obj): if hasattr(obj.portrait_image, 'path'): return obj.portrait_image.url def get_full_name(self, obj): return unicode(obj) def get_problem_id(self, obj): # Find patient's observation (INR data type) observation = ObservationComponent.objects.filter( component_code='6301-6').filter( observation__subject_id=obj.user_id).first() # Find all problem which is pinned to INR data if observation is not None and hasattr(observation, 'observation'): observation_pin_to_problem = ObservationPinToProblem.objects.filter( observation_id=observation.observation_id).first() if observation_pin_to_problem is not None: return observation_pin_to_problem.problem.id
class ColonCancerScreeningSerializer(serializers.ModelSerializer): colon_studies = ColonCancerStudySerializer(many=True, read_only=True) colon_risk_factors = RiskFactorSerializer(many=True, read_only=True) colon_cancer_todos = TodoSerializer(many=True, read_only=True) colon_notes = ColonCancerTextNoteSerializer(many=True, read_only=True) problem = ProblemSerializer() patient = UserSerializer() last_risk_updated_user = SafeUserSerializer() class Meta: model = ColonCancerScreening fields = ( 'id', 'patient', 'problem', 'created_on', 'patient_refused', 'not_appropriate', 'colon_studies', 'risk', 'colon_risk_factors', 'last_risk_updated_date', 'last_risk_updated_user', 'todo_past_five_years', 'colon_cancer_todos', 'patient_refused_on', 'not_appropriate_on', 'colon_notes', )
class ObservationComponentSerializer(serializers.ModelSerializer): date = serializers.SerializerMethodField() time = serializers.SerializerMethodField() author = SafeUserSerializer() observation_component_values = ObservationValueSerializer(many=True, read_only=True) class Meta: model = ObservationComponent fields = ( 'id', 'name', 'value_quantity', 'effective_datetime', 'created_on', 'author', 'observation', 'date', 'time', 'observation_component_values', 'component_code', ) def get_date(self, obj): if not obj.effective_datetime: return '' return obj.effective_datetime.strftime('%m/%d/%Y') def get_time(self, obj): if not obj.effective_datetime: return '' return obj.effective_datetime.strftime('%H:%M')
class LabeledToDoListSerializer(serializers.ModelSerializer): user = SafeUserSerializer() labels = LabelSerializer(many=True) class Meta: model = LabeledToDoList fields = ('id', 'user', 'labels', 'name')
class ProblemActivitySerializer(serializers.ModelSerializer): author = SafeUserSerializer() class Meta: model = ProblemActivity fields = ('id', 'author', 'activity', 'problem', 'is_input_type', 'is_output_type', 'created_on')
class ColonCancerStudySerializer(serializers.ModelSerializer): author = SafeUserSerializer() last_updated_user = SafeUserSerializer() study_images = StudyImageSerializer(many=True, read_only=True) class Meta: model = ColonCancerStudy fields = ( 'id', 'author', 'created_on', 'finding', 'result', 'note', 'study_date', 'last_updated_date', 'last_updated_user', 'study_images', )
class MedicationSerializer(serializers.ModelSerializer): author = SafeUserSerializer() patient = SafeUserSerializer() medication_notes = MedicationTextNoteSerializer(many=True, read_only=True) class Meta: model = Medication fields = ( 'id', 'author', 'patient', 'medication_notes', 'name', 'concept_id', 'current', 'search_str', 'created_on', )
class DocumentListSerializer(serializers.ModelSerializer): patient = SafeUserSerializer() class Meta: model = Document fields = ( 'id', 'document_name', 'patient', )
class ObservationValueTextNoteSerializer(serializers.ModelSerializer): author = SafeUserSerializer() class Meta: model = ObservationValueTextNote fields = ( 'id', 'author', 'note', 'datetime', )
class ObservationPinToProblemSerializer(serializers.ModelSerializer): author = SafeUserSerializer() class Meta: model = ObservationPinToProblem fields = ( 'id', 'author', 'observation', 'problem', )
class AOneCTextNoteSerializer(serializers.ModelSerializer): author = SafeUserSerializer() class Meta: model = AOneCTextNote fields = ( 'id', 'author', 'note', 'datetime', )
class TodoActivitySerializer(serializers.ModelSerializer): todo = TodoSerializer() author = SafeUserSerializer() comment = CommentToDoSerializer() attachment = AttachmentToDoSerializer() class Meta: model = TodoActivity fields = ('id', 'todo', 'author', 'activity', 'comment', 'attachment', 'created_on')
class ColonCancerTextNoteSerializer(serializers.ModelSerializer): author = SafeUserSerializer() class Meta: model = ColonCancerTextNote fields = ( 'id', 'author', 'note', 'datetime', )
class LabelSerializer(serializers.ModelSerializer): author = SafeUserSerializer() class Meta: model = Label fields = ( 'id', 'name', 'css_class', 'author', 'is_all', )
class DocumentTodoSerializer(serializers.ModelSerializer): document = DocumentSerializer() todo = TodoSerializer() author = SafeUserSerializer() class Meta: model = DocumentTodo fields = ( 'document', 'todo', 'author', )
class DocumentProblemSerializer(serializers.ModelSerializer): document = DocumentSerializer() problem = ProblemSerializer() author = SafeUserSerializer() class Meta: model = DocumentProblem fields = ( 'document', 'problem', 'author', )
class MedicationPinToProblemSerializer(serializers.ModelSerializer): author = SafeUserSerializer() medication = MedicationSerializer() class Meta: model = MedicationPinToProblem fields = ( 'id', 'author', 'medication', 'problem', )
class MedicationTextNoteSerializer(serializers.ModelSerializer): author = SafeUserSerializer() class Meta: model = MedicationTextNote fields = ( 'id', 'author', 'note', 'medication', 'datetime', )
class CommonProblemSerializer(serializers.ModelSerializer): author = SafeUserSerializer() class Meta: model = CommonProblem fields = ( 'id', 'problem_name', 'concept_id', 'problem_type', 'author', )
class CommentToDoSerializer(serializers.ModelSerializer): user = SafeUserSerializer() class Meta: model = ToDoComment fields = ( 'id', 'user', 'comment', 'datetime', )
def get_todo_info(request, todo_id): """ TODO: :param request: :param todo_id: :return: """ from encounters_app.serializers import EncounterSerializer todo_info = ToDo.objects.get(id=todo_id) comments = ToDoComment.objects.filter(todo=todo_info) attachments = ToDoAttachment.objects.filter(todo=todo_info) attachment_todos_holder = [] for attachment in attachments: attachment_dict = { 'attachment': attachment.filename(), 'datetime': datetime.strftime(attachment.datetime, '%Y-%m-%d'), 'id': attachment.id, 'user': SafeUserSerializer(attachment.user).data, 'todo': TodoSerializer(attachment.todo).data, } attachment_todos_holder.append(attachment_dict) # Load all document (aka Attachment) documents = DocumentTodo.objects.filter(todo=todo_info) document_todos_holder = [] for document in documents: document_todos_holder.append(DocumentSerializer(document.document).data) encounter_ids = EncounterTodoRecord.objects.filter(todo=todo_info).values_list("encounter__id", flat=True) related_encounters = Encounter.objects.filter(id__in=encounter_ids) activities = TodoActivity.objects.filter(todo=todo_info) sharing_patients = SharingPatient.objects.filter(shared=todo_info.patient).order_by('sharing__first_name', 'sharing__last_name') sharing_patients_list = [] for sharing_patient in sharing_patients: user_dict = UserProfileSerializer(sharing_patient.sharing.profile).data user_dict['problems'] = [x.id for x in sharing_patient.problems.all()] sharing_patients_list.append(user_dict) # Update tagged todo status to viewed is_tagged = TaggedToDoOrder.objects.filter(user=request.user).filter(todo=todo_info) if is_tagged.exists(): is_tagged.update(status=2) resp = {'success': True, 'info': TodoSerializer(todo_info).data, 'comments': ToDoCommentSerializer(comments, many=True).data, 'attachments': attachment_todos_holder, 'documents': document_todos_holder, 'related_encounters': EncounterSerializer(related_encounters, many=True).data, 'activities': TodoActivitySerializer(activities, many=True).data, 'sharing_patients': sharing_patients_list} return ajax_response(resp)
class AttachmentToDoSerializer(serializers.ModelSerializer): user = SafeUserSerializer() class Meta: model = ToDoAttachment fields = ( 'id', 'user', 'attachment', 'datetime', 'filename', 'is_image', )
class TodoSerializer(serializers.ModelSerializer): labels = LabelSerializer(many=True) comments = CommentToDoSerializer(many=True) attachments = AttachmentToDoSerializer(many=True) patient = SafeUserSerializer() members = SafeUserSerializer(many=True) due_date = serializers.DateTimeField(format='%m/%d/%Y') problem = serializers.SerializerMethodField() class Meta: model = ToDo fields = ( 'id', 'patient', 'user', 'problem', 'todo', 'accomplished', 'due_date', 'labels', 'comments', 'attachments', 'members', 'document_set', 'a1c', 'colon_cancer', 'created_at', 'created_on', ) def get_problem(self, obj): from problems_app.serializers import ProblemSerializer if obj.problem: return ProblemSerializer(obj.problem).data else: return None