def post(self, request, pk): ci = CaseInformation.objects.get(pk=pk) mi = MessageInformation.objects.create( case_information=ci, origin_facility=self.request.user.health_facility if self.request.user.health_facility else '', destination_facility=self.request.user.health_facility. linked_facility if self.request.user.health_facility else '', message_type=MESSAGE_TYPE_SENTBOX) case_information = { 'mi': mi.pk, 'ci': ci.pk, 'name': ci.name, 'gender': f'{ci.get_gender_display()}', 'age': ci.age, 'patient_contact': ci.patient_contact, 'disease_type': f'{ci.get_disease_type_display()}', 'case_report_type': f'{ci.get_case_report_type_display()}', 'classification_case': f'{ci.get_classification_case_display()}', 'address': ci.address, 'is_pregnant': ci.is_pregnant, } send_notification_email(self.request.user, self.request.user, case_information) return HttpResponse(status=HTTPStatus.OK)
def create_message(sender, instance: MessageInformation, created, **kwargs): if created: case_information = { 'mi': instance.pk, 'ci': instance.case_information.pk, 'name': instance.case_information.name, 'gender': f'{instance.case_information.get_gender_display()}', 'age': instance.case_information.age, 'patient_contact': instance.case_information.patient_contact, 'disease_type': f'{instance.case_information.get_disease_type_display()}', 'case_report_type': f'{instance.case_information.get_case_report_type_display()}', 'classification_case': f'{instance.case_information.get_classification_case_display()}', 'address': instance.case_information.address, 'province': instance.case_information.province.name, 'city': instance.case_information.city.name, 'district': instance.case_information.district.name, 'sub_district': instance.case_information.sub_district.name, 'is_pregnant': instance.case_information.is_pregnant, } send_notification_email(instance.case_information.user, instance.destination_facility, case_information)
def process_email_notification(body): reporter = User.objects.filter(email=body.get('email')).first() health_facility_member = User.objects.filter(health_facility__code=body.get('code')) case_information = { 'name': body.get('name'), 'gender': body.get('gender'), 'age': body.get('age'), 'patient_contact': body.get('patient_contact'), 'disease_type': body.get('disease_type'), 'case_report_type': body.get('case_report_type'), 'classification_case': body.get('classification_case'), 'address': body.get('address'), 'is_pregnant': body.get('is_pregnant') } for member in health_facility_member: send_notification_email(member, reporter, case_information)
def post(self, request: HttpRequest) -> HttpResponse: ci = CaseInformation.objects.create( name=json.loads(request.body)['name'], gender=json.loads(request.body)['gender'], age=json.loads(request.body)['age'], is_pregnant=json.loads(request.body)['is_pregnant'], patient_contact=json.loads(request.body)['patient_contact'], disease_type=json.loads(request.body)['disease_type'], case_report_type=json.loads(request.body)['case_report_type'], classification_case=json.loads( request.body)['classification_case'], address=json.loads(request.body)['address'], user=self.request.user) mi = MessageInformation.objects.create( case_information=ci, origin_facility=self.request.user.health_facility if self.request.user.health_facility else '', destination_facility=self.request.user.health_facility. linked_facility if self.request.user.health_facility else '', message_type=MESSAGE_TYPE_INBOX) case_information = { 'mi': mi.pk, 'ci': ci.pk, 'name': ci.name, 'gender': f'{ci.get_gender_display()}', 'age': ci.age, 'patient_contact': ci.patient_contact, 'disease_type': f'{ci.get_disease_type_display()}', 'case_report_type': f'{ci.get_case_report_type_display()}', 'classification_case': f'{ci.get_classification_case_display()}', 'address': ci.address, 'is_pregnant': ci.is_pregnant, } send_notification_email(self.request.user, self.request.user, case_information) response = HttpResponse(status=HTTPStatus.CREATED) response['Location'] = ci.pk return response