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)
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)
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})