コード例 #1
0
ファイル: attachments.py プロジェクト: ganap/so
    def post(self, request, *args, **kwargs):
        data = dict(request.data)
        if not request.user.is_authenticated():
            return Response({}, status.HTTP_401_UNAUTHORIZED)
        file_ = data['file'][0]
        user_pk = data.get('user_pk', [request.user.pk])
        user_pk = int(user_pk[0])
        if not user_pk:
            user_pk = request.user.pk
        path = google_cloud.upload_to_gc(file_)
        try:
            creation = data['date'][0]
            creation = helpers.date.timestamp_to_datetime(creation)
        except:
            creation = helpers.date.timestamp()

        title = os.path.splitext(file_.name)[0]
        attachment = info.Attachment(
            owner=user_pk,
            gcloud_path={
                'bucket': settings.GS_STORAGE_BUCKET,
                'path': path[0]
            },
            ext=path[1],
            title=title,
            creation=creation,
            timestamp=helpers.date.timestamp()
        )
        attachment.save()
        data = serializers.AttachmentSerializer(attachment)
        return Response(data.data)
コード例 #2
0
ファイル: fhir_profiles_creators.py プロジェクト: ganap/so
def saveDicomFromImagingStudy(reference, user_pk):
    r = requests.get("https://fhir-open-api.smarthealthit.org/" + reference,
                     stream=True)
    filename = helpers.id_generator(13)
    with open("/tmp/" + filename + ".dcm", 'wb') as f:
        r.raw.decode_content = True
        shutil.copyfileobj(r.raw, f)
    f = open("/tmp/" + filename + ".dcm")
    path = google_cloud.upload_to_gc(f)
    return path