use of org.monarchinitiative.loinc2hpo.loinc.LoincId in project loinc2hpo by monarch-initiative.
the class MainController method handleSaveSession.
@FXML
private void handleSaveSession(ActionEvent e) {
logger.trace("user wants to save a session");
// Create a session if it is saved for the first time
if (model.getPathToLastSession() == null) {
createNewSession();
}
// save annotations to "basic_annotations" and "advanced_annotations"
String pathToAnnotations = model.getPathToLastSession() + File.separator + "basic_annotations.tsv";
try {
WriteToFile.toTSVbasicAnnotations(pathToAnnotations, model.getLoincAnnotationMap());
} catch (IOException e1) {
PopUps.showWarningDialog("Error message", "Failure to save basic annotations data", "An error occurred. Try again!");
}
String pathToAnnotations2 = model.getPathToLastSession() + File.separator + "advanced_annotations.tsv";
try {
WriteToFile.toTSVadvancedAnnotations(pathToAnnotations2, model.getLoincAnnotationMap());
} catch (IOException e1) {
PopUps.showWarningDialog("Error message", "Failure to save advanced annotations data", "An error occurred. Try again!");
}
String pathToLoincCategory = model.getPathToLastSession() + File.separator + LOINC_CATEGORY_folder;
if (!new File(pathToLoincCategory).exists()) {
new File(pathToLoincCategory).mkdir();
}
model.getUserCreatedLoincLists().entrySet().forEach(p -> {
String path = pathToLoincCategory + File.separator + p.getKey() + ".txt";
Set<LoincId> loincIds = model.getUserCreatedLoincLists().get(p.getKey());
StringBuilder builder = new StringBuilder();
loincIds.forEach(l -> {
builder.append(l);
builder.append("\n");
});
WriteToFile.writeToFile(builder.toString().trim(), path);
});
// reset the session change tracker
model.setSessionChanged(false);
if (e != null) {
e.consume();
}
}
use of org.monarchinitiative.loinc2hpo.loinc.LoincId in project loinc2hpo by monarch-initiative.
the class FhirResourceRetriever method fhir2testrest.
@Deprecated
public static LabTestResultInHPO fhir2testrest(JsonNode node, Map<LoincId, Loinc2HPOAnnotation> testmap) throws Loinc2HpoException {
boolean interpretationDetected = false;
String interpretationCode = null;
LoincId lid;
ObservationResultInInternalCode observation;
String comment;
System.out.println(node.toString());
String resourcetype = node.get("resourceType").asText();
if (!resourcetype.equals("Observation"))
throw new WrongElementException("Unexpected resource type " + resourcetype + "(expected: LabTestResultInHPO)");
JsonNode codeNode = node.get("code");
lid = getLoincId(codeNode);
JsonNode interpretationNode = node.get("interpretation");
observation = getInterpretationCode(interpretationNode);
if (observation != null && lid != null) {
Loinc2HPOAnnotation test = testmap.get(lid);
if (test == null) {
logger.error("Could not retrieve test for " + lid.toString());
debugPrint(testmap);
return null;
}
HpoTermId4LoincTest hpoId = test.loincInterpretationToHpo(observation);
return new BasicLabTestResultInHPO(hpoId, observation, "?");
}
logger.info("interpretation node: " + interpretationNode.asText());
if (interpretationNode.isMissingNode()) {
//
} else {
JsonNode codingNode = interpretationNode.get("coding");
logger.info("coding node: " + codingNode.asText());
if (codingNode.isMissingNode()) {
logger.info("coding node is not array");
} else {
if (!codingNode.isArray()) {
//
} else {
logger.info("coding node is array");
for (JsonNode loinc : codingNode) {
if (!loinc.path("code").isMissingNode()) {
interpretationDetected = true;
interpretationCode = loinc.path("code").asText();
logger.info("code is detected: " + interpretationCode);
// if (interpretationCode.equalsIgnoreCase("H")) {
// return new BasicLabTestResultInHPO()
// }
}
/**
* String system = loinc.path("system").asText();
* logger.info("system: " + system);
* if (!system.equals("http://loinc.org")) {
* System.err.println("[ERROR] Non Loinc code detected...");
* //continue;
* }
*
* String display = loinc.path("display").asText();
* logger.info("display: " + display);
*/
}
}
}
}
if (!interpretationDetected) {
double valueObserved = 9999.0;
JsonNode valueNode = node.get("valueQuantity");
// System.out.println("found valueNode: " + valueNode.asText());
try {
logger.info("value observed: " + valueNode.get("value").asText());
valueObserved = Double.parseDouble(valueNode.get("value").asText());
logger.info("value retrieved: " + valueObserved);
} catch (NumberFormatException e) {
logger.error("measured value is not a double");
}
if (Math.abs(valueObserved - 9999.0) > 0.00001) {
// we want to compare the observed value with the normal range
if (valueObserved < 0) {
interpretationCode = "L";
}
if (valueObserved > 1) {
interpretationCode = "H";
} else {
interpretationCode = "N";
}
}
}
return null;
// return LabTestResultInHPO(interpretationCode);
}
use of org.monarchinitiative.loinc2hpo.loinc.LoincId in project loinc2hpo by monarch-initiative.
the class WriteToFile method fromTSVBasic.
public static Map<LoincId, UniversalLoinc2HPOAnnotation> fromTSVBasic(String path, Map<TermId, HpoTerm> hpoTermMap) throws FileNotFoundException {
Map<LoincId, UniversalLoinc2HPOAnnotation> deserializedMap = new LinkedHashMap<>();
BufferedReader reader = new BufferedReader(new FileReader(path));
reader.lines().forEach(serialized -> {
String[] elements = serialized.split("\\t");
if (elements.length == 13 && !serialized.startsWith("loincId")) {
try {
LoincId loincId = new LoincId(elements[0]);
LoincScale loincScale = LoincScale.string2enum(elements[1]);
TermId low = convertToTermID(elements[2]);
TermId intermediate = convertToTermID(elements[3]);
TermId high = convertToTermID(elements[4]);
boolean inverse = Boolean.parseBoolean(elements[5]);
String note = elements[6].equals(MISSINGVALUE) ? null : elements[6];
boolean flag = Boolean.parseBoolean(elements[7]);
double version = Double.parseDouble(elements[8]);
LocalDateTime createdOn = elements[9].equals(MISSINGVALUE) ? null : LocalDateTime.parse(elements[9]);
String createdBy = elements[10].equals(MISSINGVALUE) ? null : elements[10];
LocalDateTime lastEditedOn = elements[11].equals(MISSINGVALUE) ? null : LocalDateTime.parse(elements[11]);
String lastEditedBy = elements[12].equals(MISSINGVALUE) ? null : elements[12];
if (!deserializedMap.containsKey(loincId)) {
UniversalLoinc2HPOAnnotation.Builder builder = new UniversalLoinc2HPOAnnotation.Builder();
builder.setLoincId(loincId).setLoincScale(loincScale).setLowValueHpoTerm(hpoTermMap.get(low)).setIntermediateValueHpoTerm(hpoTermMap.get(intermediate)).setHighValueHpoTerm(hpoTermMap.get(high)).setIntermediateNegated(inverse).setCreatedOn(createdOn).setCreatedBy(createdBy).setLastEditedOn(lastEditedOn).setLastEditedBy(lastEditedBy).setVersion(version).setNote(note).setFlag(flag);
deserializedMap.put(loincId, builder.build());
}
} catch (MalformedLoincCodeException e) {
logger.error("Malformed loinc code line: " + serialized);
}
} else {
if (elements.length != 13) {
logger.error(String.format("line does not have 13 elements, but has %d elements. Line: %s", elements.length, serialized));
} else {
logger.info("line is header: " + serialized);
}
}
});
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return deserializedMap;
}
use of org.monarchinitiative.loinc2hpo.loinc.LoincId in project loinc2hpo by monarch-initiative.
the class WriteToFile method fromTSVAdvanced.
public static void fromTSVAdvanced(String path, Map<LoincId, UniversalLoinc2HPOAnnotation> deserializedMap, Map<TermId, HpoTerm> hpoTermMap) throws FileNotFoundException {
BufferedReader reader = new BufferedReader(new FileReader(path));
reader.lines().forEach(serialized -> {
String[] elements = serialized.split("\\t");
if (elements.length == 13 && !serialized.startsWith("loincId")) {
try {
LoincId loincId = new LoincId(elements[0]);
String system = elements[2];
String codeString = elements[3];
TermId termId = convertToTermID(elements[4]);
boolean inverse = Boolean.parseBoolean(elements[5]);
UniversalLoinc2HPOAnnotation annotation = deserializedMap.get(loincId);
Code code = Code.getNewCode().setSystem(system).setCode(codeString);
annotation.addAdvancedAnnotation(code, new HpoTermId4LoincTest(hpoTermMap.get(termId), inverse));
} catch (MalformedLoincCodeException e) {
logger.error("Malformed loinc code line: " + serialized);
}
} else {
if (elements.length != 13) {
logger.error(String.format("line does not have 13 elements, but has %d elements. Line: %s", elements.length, serialized));
} else {
logger.info("line is header: " + serialized);
}
}
});
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations