Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
case class DiagnosisCode(rootCode: String, uniqueCode: String, 
                              description: Option[String] = None)

object Database {
 private val data: List[DiagnosisCode] = List(
  DiagnosisCode("A00", "A001", Some("Cholera due to Vibrio cholerae")),
  DiagnosisCode("A00", "A009", Some("Cholera, unspecified")),
  DiagnosisCode("A08", "A080", Some("Rotaviral enteritis")),
  DiagnosisCode("A08", "A083", Some("Other viral enteritis")),
  DiagnosisCode("B15", "B150", Some("Hepatitis A with hepatic coma")),
  DiagnosisCode("B15", "B159", Some("Hepatitis A without hepatic coma")),
  DiagnosisCode("H26", "H26001", Some("Other cataract right eye")),
  DiagnosisCode("H26", "H26002", Some("Other cataract left eye"))
 )

 def getAllUniqueCodes: Future[List[String]] = Future {
  Database.data.map(_.uniqueCode)
 }

 def fetchDiagnosisForUniqueCode(uniqueCode: String): 
  Future[Option[DiagnosisCode]] = Future {
  Database.data.find(_.uniqueCode.equalsIgnoreCase(uniqueCode))
 }

}

// ------Kindly find the method below---------------------
def fetchDiagnosisForUniqueCodes/*: Future[List[DiagnosisCode]]*/ = {
  Database.getAllUniqueCodes.map { (xs: List[String]) =>
    xs.map { (uq: String) =>
      Database.fetchDiagnosisForUniqueCode(uq)
    }
  }
}


What I have tried:

def fetchDiagnosisForUniqueCodes: Future[List[DiagnosisCode]] = {
  Database.getAllUniqueCodes.map { (xs: List[String]) =>
    xs.map { (uq: String) =>
      Database.fetchDiagnosisForUniqueCode(uq)
    }
  }
}
Posted
Comments
Richard Deeming 7-Sep-22 7:44am    
Well, go ahead: you have our permission to do that.

Feel free to come back and actually ask a question if you get stuck.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900