Ejemplo n.º 1
0
 def discharge(self):
     '''
     Insert the admission finished date of the patient that was discharged from the hospital
     '''
     self.patient.discharge()
     self.end_date = timezone.now()
     self.save()
     ExecutedProtocol.cancelAllAssigned(patient=self.patient)
Ejemplo n.º 2
0
 def getNextProtocolAssignedMeasure(self):
     '''
     It returns when the patient information should be measured
     :return: tuple (datetime, schedule title)
     '''
     nextExecution = ExecutedProtocol.getNextExecution(patient=self.patient)
     return (nextExecution.schedule_time.strftime("%Y-%m-%d %H:%M"),
             nextExecution.schedule.title)
Ejemplo n.º 3
0
    def new(self, request, *args, **kwargs):
        '''
        Admission of a patient registed in the system and all the assigned protocols.
        '''
        #Create admission
        patient  = Patient.objects.get(id=request.data.get('patientID'))
        physician = Profile.objects.get(user=request.user)
        Admission.new(patient=patient,
                      physician=physician,
                      room=request.data.get('room'))
        #Assign protocols
        selectedProtocols  = request.data.get('seletedProtocols') #For now it is only one
        for selectedProtocol in selectedProtocols:
            protocol = Protocol.objects.get(id=selectedProtocol.get("id"))
            ExecutedProtocol.new(protocol=protocol, patient=patient, physician=physician)

        self.queryset = Admission.all(active=True)
        return super(AdmissionViewSet, self).list(request, *args, **kwargs)
Ejemplo n.º 4
0
 def getLastProtocolAssignedMeasurePhysician(self):
     '''
     Retrieves who made the last protocol measurement
     :return: datetime in string format
     '''
     lastProtocolExecution = ExecutedProtocol.getLastExecution(
         patient=self.patient, admissionDate=self.start_date)
     if (lastProtocolExecution):
         return lastProtocolExecution.physician
     return ""
Ejemplo n.º 5
0
 def getLastProtocolAssignedMeasure(self):
     '''
     Retrieves when was made the last protocol measurement
     :return: datetime in string format
     '''
     lastProtocolExecution = ExecutedProtocol.getLastExecution(
         patient=self.patient, admissionDate=self.start_date)
     if (lastProtocolExecution):
         return lastProtocolExecution.execution_time.strftime(
             "%Y-%m-%d %H:%M")
     return ""
Ejemplo n.º 6
0
    def assignPatients(self):
        try:
            physician_user = User.objects.create_user('João Almeida',
                                                      '*****@*****.**', '12345')
            physician = Profile(user=physician_user, role=Profile.PHYSICIAN)
            physician.save()
            max = len(Patient.objects.all()) / 4
            count = 0
            for patient in Patient.objects.all():
                # Create admission
                Admission.new(patient=patient,
                              physician=physician,
                              room="c." + str(patient.id))

                # Assign protocols
                protocol = Protocol.objects.get(title="Hypoglycemia")
                ExecutedProtocol.new(protocol=protocol,
                                     patient=patient,
                                     physician=physician)

                if count % 2 == 0:  #Execute one mesurement in some patients
                    inquiryData = {"Blood Glucose": "12", "Diet": "zero"}
                    CVPatient.addCVSet(inquiryData, patient)
                    assignment = ExecutedProtocol.getNextExecution(patient)
                    result = assignment.run(inquiryData)
                    # Next assigment
                    protocol = assignment.protocol
                    last_execution = assignment.schedule_time
                    ExecutedProtocol.new(protocol=protocol,
                                         patient=patient,
                                         physician=physician,
                                         last_execution=last_execution)

                count += 1
                if count == max:
                    break
        except Exception as ex:
            self.stdout.write(
                "\tError: Probably no protocol or doctors in the database!\n")
            self.stdout.write(ex)
Ejemplo n.º 7
0
    def run(self, request):
        patientId = request.data.get('patientID', None)
        protocolId = request.data.get('protocolID', None)
        inquiryData = request.data.get('inquiryData', None)

        if (patientId == None or protocolId == None or inquiryData == None):
            return Response({'error': "Invalid parameters"})

        physician = Profile.objects.get(user=request.user)
        patient = Patient.objects.get(id=patientId)
        CVPatient.addCVSet(inquiryData, patient)

        assignment = ExecutedProtocol.getNextExecution(patient)
        result = assignment.run(inquiryData=inquiryData, physician=physician)

        #Next assigment
        protocol = assignment.protocol
        last_execution = assignment.schedule_time
        ExecutedProtocol.new(protocol=protocol,
                             patient=patient,
                             physician=physician,
                             last_execution=last_execution)

        return Response({"results": result})
Ejemplo n.º 8
0
    def protocolInquiryComponents(self, request):
        patientid = self.request.query_params.get('patient', None)
        protocolid = self.request.query_params.get('protocol', None)

        if (patientid):
            patient = Patient.objects.get(id=patientid)
            assignment = ExecutedProtocol.getNextExecution(patient)
            protocol = assignment.protocol
        elif (protocolid):
            protocol = Protocol.objects.get(id=protocolid)
        else:
            return Response({'error': "Invalid parameters"})

        elements = ProtocolElement.all(protocol=protocol,
                                       type=ProtocolElement.INQUIRY)

        return Response({
            "results": {
                "Protocol": ProtocolSerializer(protocol).data,
                "Elements": PEInquirySerializer(elements, many=True).data
            }
        })
class AssignedProtocolViewSet(viewsets.ModelViewSet):
    queryset = ExecutedProtocol.all(state=ExecutedProtocol.ASSIGNED)
    serializer_class = ExecutedProtocolSerializer

    filter_backends = [DjangoFilterBackend, OrderingFilter]
    filter_fields = ["patient"]