{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.ComprehendMedical.DetectPHI
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Inspects the clinical text for protected health information (PHI)
-- entities and returns the entity category, location, and confidence score
-- for each entity. Amazon Comprehend Medical only detects entities in
-- English language texts.
module Amazonka.ComprehendMedical.DetectPHI
  ( -- * Creating a Request
    DetectPHI (..),
    newDetectPHI,

    -- * Request Lenses
    detectPHI_text,

    -- * Destructuring the Response
    DetectPHIResponse (..),
    newDetectPHIResponse,

    -- * Response Lenses
    detectPHIResponse_paginationToken,
    detectPHIResponse_httpStatus,
    detectPHIResponse_entities,
    detectPHIResponse_modelVersion,
  )
where

import Amazonka.ComprehendMedical.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newDetectPHI' smart constructor.
data DetectPHI = DetectPHI'
  { -- | A UTF-8 text string containing the clinical content being examined for
    -- PHI entities. Each string must contain fewer than 20,000 bytes of
    -- characters.
    DetectPHI -> Text
text :: Prelude.Text
  }
  deriving (DetectPHI -> DetectPHI -> Bool
(DetectPHI -> DetectPHI -> Bool)
-> (DetectPHI -> DetectPHI -> Bool) -> Eq DetectPHI
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectPHI -> DetectPHI -> Bool
$c/= :: DetectPHI -> DetectPHI -> Bool
== :: DetectPHI -> DetectPHI -> Bool
$c== :: DetectPHI -> DetectPHI -> Bool
Prelude.Eq, ReadPrec [DetectPHI]
ReadPrec DetectPHI
Int -> ReadS DetectPHI
ReadS [DetectPHI]
(Int -> ReadS DetectPHI)
-> ReadS [DetectPHI]
-> ReadPrec DetectPHI
-> ReadPrec [DetectPHI]
-> Read DetectPHI
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetectPHI]
$creadListPrec :: ReadPrec [DetectPHI]
readPrec :: ReadPrec DetectPHI
$creadPrec :: ReadPrec DetectPHI
readList :: ReadS [DetectPHI]
$creadList :: ReadS [DetectPHI]
readsPrec :: Int -> ReadS DetectPHI
$creadsPrec :: Int -> ReadS DetectPHI
Prelude.Read, Int -> DetectPHI -> ShowS
[DetectPHI] -> ShowS
DetectPHI -> String
(Int -> DetectPHI -> ShowS)
-> (DetectPHI -> String)
-> ([DetectPHI] -> ShowS)
-> Show DetectPHI
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectPHI] -> ShowS
$cshowList :: [DetectPHI] -> ShowS
show :: DetectPHI -> String
$cshow :: DetectPHI -> String
showsPrec :: Int -> DetectPHI -> ShowS
$cshowsPrec :: Int -> DetectPHI -> ShowS
Prelude.Show, (forall x. DetectPHI -> Rep DetectPHI x)
-> (forall x. Rep DetectPHI x -> DetectPHI) -> Generic DetectPHI
forall x. Rep DetectPHI x -> DetectPHI
forall x. DetectPHI -> Rep DetectPHI x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetectPHI x -> DetectPHI
$cfrom :: forall x. DetectPHI -> Rep DetectPHI x
Prelude.Generic)

-- |
-- Create a value of 'DetectPHI' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'text', 'detectPHI_text' - A UTF-8 text string containing the clinical content being examined for
-- PHI entities. Each string must contain fewer than 20,000 bytes of
-- characters.
newDetectPHI ::
  -- | 'text'
  Prelude.Text ->
  DetectPHI
newDetectPHI :: Text -> DetectPHI
newDetectPHI Text
pText_ = DetectPHI' :: Text -> DetectPHI
DetectPHI' {$sel:text:DetectPHI' :: Text
text = Text
pText_}

-- | A UTF-8 text string containing the clinical content being examined for
-- PHI entities. Each string must contain fewer than 20,000 bytes of
-- characters.
detectPHI_text :: Lens.Lens' DetectPHI Prelude.Text
detectPHI_text :: (Text -> f Text) -> DetectPHI -> f DetectPHI
detectPHI_text = (DetectPHI -> Text)
-> (DetectPHI -> Text -> DetectPHI)
-> Lens DetectPHI DetectPHI Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectPHI' {Text
text :: Text
$sel:text:DetectPHI' :: DetectPHI -> Text
text} -> Text
text) (\s :: DetectPHI
s@DetectPHI' {} Text
a -> DetectPHI
s {$sel:text:DetectPHI' :: Text
text = Text
a} :: DetectPHI)

instance Core.AWSRequest DetectPHI where
  type AWSResponse DetectPHI = DetectPHIResponse
  request :: DetectPHI -> Request DetectPHI
request = Service -> DetectPHI -> Request DetectPHI
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy DetectPHI
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetectPHI)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse DetectPHI))
-> Logger
-> Service
-> Proxy DetectPHI
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetectPHI)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> [Entity] -> Text -> DetectPHIResponse
DetectPHIResponse'
            (Maybe Text -> Int -> [Entity] -> Text -> DetectPHIResponse)
-> Either String (Maybe Text)
-> Either String (Int -> [Entity] -> Text -> DetectPHIResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"PaginationToken")
            Either String (Int -> [Entity] -> Text -> DetectPHIResponse)
-> Either String Int
-> Either String ([Entity] -> Text -> DetectPHIResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            Either String ([Entity] -> Text -> DetectPHIResponse)
-> Either String [Entity]
-> Either String (Text -> DetectPHIResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe [Entity])
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Entities" Either String (Maybe [Entity])
-> [Entity] -> Either String [Entity]
forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ [Entity]
forall a. Monoid a => a
Prelude.mempty)
            Either String (Text -> DetectPHIResponse)
-> Either String Text -> Either String DetectPHIResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String Text
forall a. FromJSON a => Object -> Text -> Either String a
Core..:> Text
"ModelVersion")
      )

instance Prelude.Hashable DetectPHI

instance Prelude.NFData DetectPHI

instance Core.ToHeaders DetectPHI where
  toHeaders :: DetectPHI -> ResponseHeaders
toHeaders =
    ResponseHeaders -> DetectPHI -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"ComprehendMedical_20181030.DetectPHI" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON DetectPHI where
  toJSON :: DetectPHI -> Value
toJSON DetectPHI' {Text
text :: Text
$sel:text:DetectPHI' :: DetectPHI -> Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Text" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
text)]
      )

instance Core.ToPath DetectPHI where
  toPath :: DetectPHI -> ByteString
toPath = ByteString -> DetectPHI -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery DetectPHI where
  toQuery :: DetectPHI -> QueryString
toQuery = QueryString -> DetectPHI -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newDetectPHIResponse' smart constructor.
data DetectPHIResponse = DetectPHIResponse'
  { -- | If the result of the previous request to @DetectPHI@ was truncated,
    -- include the @PaginationToken@ to fetch the next page of PHI entities.
    DetectPHIResponse -> Maybe Text
paginationToken :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    DetectPHIResponse -> Int
httpStatus :: Prelude.Int,
    -- | The collection of PHI entities extracted from the input text and their
    -- associated information. For each entity, the response provides the
    -- entity text, the entity category, where the entity text begins and ends,
    -- and the level of confidence that Amazon Comprehend Medical has in its
    -- detection.
    DetectPHIResponse -> [Entity]
entities :: [Entity],
    -- | The version of the model used to analyze the documents. The version
    -- number looks like X.X.X. You can use this information to track the model
    -- used for a particular batch of documents.
    DetectPHIResponse -> Text
modelVersion :: Prelude.Text
  }
  deriving (DetectPHIResponse -> DetectPHIResponse -> Bool
(DetectPHIResponse -> DetectPHIResponse -> Bool)
-> (DetectPHIResponse -> DetectPHIResponse -> Bool)
-> Eq DetectPHIResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DetectPHIResponse -> DetectPHIResponse -> Bool
$c/= :: DetectPHIResponse -> DetectPHIResponse -> Bool
== :: DetectPHIResponse -> DetectPHIResponse -> Bool
$c== :: DetectPHIResponse -> DetectPHIResponse -> Bool
Prelude.Eq, ReadPrec [DetectPHIResponse]
ReadPrec DetectPHIResponse
Int -> ReadS DetectPHIResponse
ReadS [DetectPHIResponse]
(Int -> ReadS DetectPHIResponse)
-> ReadS [DetectPHIResponse]
-> ReadPrec DetectPHIResponse
-> ReadPrec [DetectPHIResponse]
-> Read DetectPHIResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DetectPHIResponse]
$creadListPrec :: ReadPrec [DetectPHIResponse]
readPrec :: ReadPrec DetectPHIResponse
$creadPrec :: ReadPrec DetectPHIResponse
readList :: ReadS [DetectPHIResponse]
$creadList :: ReadS [DetectPHIResponse]
readsPrec :: Int -> ReadS DetectPHIResponse
$creadsPrec :: Int -> ReadS DetectPHIResponse
Prelude.Read, Int -> DetectPHIResponse -> ShowS
[DetectPHIResponse] -> ShowS
DetectPHIResponse -> String
(Int -> DetectPHIResponse -> ShowS)
-> (DetectPHIResponse -> String)
-> ([DetectPHIResponse] -> ShowS)
-> Show DetectPHIResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DetectPHIResponse] -> ShowS
$cshowList :: [DetectPHIResponse] -> ShowS
show :: DetectPHIResponse -> String
$cshow :: DetectPHIResponse -> String
showsPrec :: Int -> DetectPHIResponse -> ShowS
$cshowsPrec :: Int -> DetectPHIResponse -> ShowS
Prelude.Show, (forall x. DetectPHIResponse -> Rep DetectPHIResponse x)
-> (forall x. Rep DetectPHIResponse x -> DetectPHIResponse)
-> Generic DetectPHIResponse
forall x. Rep DetectPHIResponse x -> DetectPHIResponse
forall x. DetectPHIResponse -> Rep DetectPHIResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep DetectPHIResponse x -> DetectPHIResponse
$cfrom :: forall x. DetectPHIResponse -> Rep DetectPHIResponse x
Prelude.Generic)

-- |
-- Create a value of 'DetectPHIResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'paginationToken', 'detectPHIResponse_paginationToken' - If the result of the previous request to @DetectPHI@ was truncated,
-- include the @PaginationToken@ to fetch the next page of PHI entities.
--
-- 'httpStatus', 'detectPHIResponse_httpStatus' - The response's http status code.
--
-- 'entities', 'detectPHIResponse_entities' - The collection of PHI entities extracted from the input text and their
-- associated information. For each entity, the response provides the
-- entity text, the entity category, where the entity text begins and ends,
-- and the level of confidence that Amazon Comprehend Medical has in its
-- detection.
--
-- 'modelVersion', 'detectPHIResponse_modelVersion' - The version of the model used to analyze the documents. The version
-- number looks like X.X.X. You can use this information to track the model
-- used for a particular batch of documents.
newDetectPHIResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  -- | 'modelVersion'
  Prelude.Text ->
  DetectPHIResponse
newDetectPHIResponse :: Int -> Text -> DetectPHIResponse
newDetectPHIResponse Int
pHttpStatus_ Text
pModelVersion_ =
  DetectPHIResponse' :: Maybe Text -> Int -> [Entity] -> Text -> DetectPHIResponse
DetectPHIResponse'
    { $sel:paginationToken:DetectPHIResponse' :: Maybe Text
paginationToken =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DetectPHIResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:entities:DetectPHIResponse' :: [Entity]
entities = [Entity]
forall a. Monoid a => a
Prelude.mempty,
      $sel:modelVersion:DetectPHIResponse' :: Text
modelVersion = Text
pModelVersion_
    }

-- | If the result of the previous request to @DetectPHI@ was truncated,
-- include the @PaginationToken@ to fetch the next page of PHI entities.
detectPHIResponse_paginationToken :: Lens.Lens' DetectPHIResponse (Prelude.Maybe Prelude.Text)
detectPHIResponse_paginationToken :: (Maybe Text -> f (Maybe Text))
-> DetectPHIResponse -> f DetectPHIResponse
detectPHIResponse_paginationToken = (DetectPHIResponse -> Maybe Text)
-> (DetectPHIResponse -> Maybe Text -> DetectPHIResponse)
-> Lens
     DetectPHIResponse DetectPHIResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectPHIResponse' {Maybe Text
paginationToken :: Maybe Text
$sel:paginationToken:DetectPHIResponse' :: DetectPHIResponse -> Maybe Text
paginationToken} -> Maybe Text
paginationToken) (\s :: DetectPHIResponse
s@DetectPHIResponse' {} Maybe Text
a -> DetectPHIResponse
s {$sel:paginationToken:DetectPHIResponse' :: Maybe Text
paginationToken = Maybe Text
a} :: DetectPHIResponse)

-- | The response's http status code.
detectPHIResponse_httpStatus :: Lens.Lens' DetectPHIResponse Prelude.Int
detectPHIResponse_httpStatus :: (Int -> f Int) -> DetectPHIResponse -> f DetectPHIResponse
detectPHIResponse_httpStatus = (DetectPHIResponse -> Int)
-> (DetectPHIResponse -> Int -> DetectPHIResponse)
-> Lens DetectPHIResponse DetectPHIResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectPHIResponse' {Int
httpStatus :: Int
$sel:httpStatus:DetectPHIResponse' :: DetectPHIResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: DetectPHIResponse
s@DetectPHIResponse' {} Int
a -> DetectPHIResponse
s {$sel:httpStatus:DetectPHIResponse' :: Int
httpStatus = Int
a} :: DetectPHIResponse)

-- | The collection of PHI entities extracted from the input text and their
-- associated information. For each entity, the response provides the
-- entity text, the entity category, where the entity text begins and ends,
-- and the level of confidence that Amazon Comprehend Medical has in its
-- detection.
detectPHIResponse_entities :: Lens.Lens' DetectPHIResponse [Entity]
detectPHIResponse_entities :: ([Entity] -> f [Entity])
-> DetectPHIResponse -> f DetectPHIResponse
detectPHIResponse_entities = (DetectPHIResponse -> [Entity])
-> (DetectPHIResponse -> [Entity] -> DetectPHIResponse)
-> Lens DetectPHIResponse DetectPHIResponse [Entity] [Entity]
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectPHIResponse' {[Entity]
entities :: [Entity]
$sel:entities:DetectPHIResponse' :: DetectPHIResponse -> [Entity]
entities} -> [Entity]
entities) (\s :: DetectPHIResponse
s@DetectPHIResponse' {} [Entity]
a -> DetectPHIResponse
s {$sel:entities:DetectPHIResponse' :: [Entity]
entities = [Entity]
a} :: DetectPHIResponse) (([Entity] -> f [Entity])
 -> DetectPHIResponse -> f DetectPHIResponse)
-> (([Entity] -> f [Entity]) -> [Entity] -> f [Entity])
-> ([Entity] -> f [Entity])
-> DetectPHIResponse
-> f DetectPHIResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. ([Entity] -> f [Entity]) -> [Entity] -> f [Entity]
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The version of the model used to analyze the documents. The version
-- number looks like X.X.X. You can use this information to track the model
-- used for a particular batch of documents.
detectPHIResponse_modelVersion :: Lens.Lens' DetectPHIResponse Prelude.Text
detectPHIResponse_modelVersion :: (Text -> f Text) -> DetectPHIResponse -> f DetectPHIResponse
detectPHIResponse_modelVersion = (DetectPHIResponse -> Text)
-> (DetectPHIResponse -> Text -> DetectPHIResponse)
-> Lens DetectPHIResponse DetectPHIResponse Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\DetectPHIResponse' {Text
modelVersion :: Text
$sel:modelVersion:DetectPHIResponse' :: DetectPHIResponse -> Text
modelVersion} -> Text
modelVersion) (\s :: DetectPHIResponse
s@DetectPHIResponse' {} Text
a -> DetectPHIResponse
s {$sel:modelVersion:DetectPHIResponse' :: Text
modelVersion = Text
a} :: DetectPHIResponse)

instance Prelude.NFData DetectPHIResponse