{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
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
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]
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
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. 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' {$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 :: Lens' DetectPHI Text
detectPHI_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 :: (Service -> Service) -> DetectPHI -> Request DetectPHI
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy DetectPHI
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse DetectPHI)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> 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'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"PaginationToken")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Entities" forall (f :: * -> *) a. Functor f => f (Maybe a) -> a -> f a
Core..!@ forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Either String a
Data..:> Key
"ModelVersion")
      )

instance Prelude.Hashable DetectPHI where
  hashWithSalt :: Int -> DetectPHI -> Int
hashWithSalt Int
_salt DetectPHI' {Text
text :: Text
$sel:text:DetectPHI' :: DetectPHI -> Text
..} =
    Int
_salt forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
text

instance Prelude.NFData DetectPHI where
  rnf :: DetectPHI -> ()
rnf DetectPHI' {Text
text :: Text
$sel:text:DetectPHI' :: DetectPHI -> Text
..} = forall a. NFData a => a -> ()
Prelude.rnf Text
text

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

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

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

instance Data.ToQuery DetectPHI where
  toQuery :: DetectPHI -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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 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
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]
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
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. 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 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'
    { $sel:paginationToken:DetectPHIResponse' :: Maybe Text
paginationToken =
        forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:DetectPHIResponse' :: Int
httpStatus = Int
pHttpStatus_,
      $sel:entities:DetectPHIResponse' :: [Entity]
entities = 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 :: Lens' DetectPHIResponse (Maybe Text)
detectPHIResponse_paginationToken = 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 :: Lens' DetectPHIResponse Int
detectPHIResponse_httpStatus = 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 Comprehend Medical; has in its
-- detection.
detectPHIResponse_entities :: Lens.Lens' DetectPHIResponse [Entity]
detectPHIResponse_entities :: Lens' DetectPHIResponse [Entity]
detectPHIResponse_entities = 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) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 :: Lens' DetectPHIResponse Text
detectPHIResponse_modelVersion = 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 where
  rnf :: DetectPHIResponse -> ()
rnf DetectPHIResponse' {Int
[Entity]
Maybe Text
Text
modelVersion :: Text
entities :: [Entity]
httpStatus :: Int
paginationToken :: Maybe Text
$sel:modelVersion:DetectPHIResponse' :: DetectPHIResponse -> Text
$sel:entities:DetectPHIResponse' :: DetectPHIResponse -> [Entity]
$sel:httpStatus:DetectPHIResponse' :: DetectPHIResponse -> Int
$sel:paginationToken:DetectPHIResponse' :: DetectPHIResponse -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
paginationToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf [Entity]
entities
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
modelVersion