Search in sources :

Example 1 with LoincEntry

use of org.monarchinitiative.loinc2hpo.loinc.LoincEntry in project loinc2hpo by monarch-initiative.

the class ObservationDownloader method iteratorHapiFHIRServer.

public static void iteratorHapiFHIRServer() {
    // printObservationInfo();
    // printPatientInfo();
    // BufferedReader bufferedReader = new BufferedReader(new FileReader(""));
    // find20CompleteRecordOfEachType();
    String path = null;
    HashMap<String, StringBuilder> completeObservations = new HashMap<>();
    completeObservations.put("Qn", new StringBuilder());
    completeObservations.put("Ord", new StringBuilder());
    completeObservations.put("Nom", new StringBuilder());
    completeObservations.put("Nar", new StringBuilder());
    completeObservations.put("OrdQn", new StringBuilder());
    completeObservations.put("unkown", new StringBuilder());
    HashMap<String, Integer> countComplete = new HashMap<>();
    countComplete.put("Qn", 0);
    countComplete.put("Ord", 0);
    countComplete.put("Nom", 0);
    countComplete.put("Nar", 0);
    countComplete.put("OrdQn", 0);
    countComplete.put("unknown", 0);
    HashMap<String, StringBuilder> accetableObservations = new HashMap<>();
    accetableObservations.put("Qn", new StringBuilder());
    accetableObservations.put("Ord", new StringBuilder());
    accetableObservations.put("Nom", new StringBuilder());
    accetableObservations.put("Nar", new StringBuilder());
    accetableObservations.put("OrdQn", new StringBuilder());
    accetableObservations.put("unknown", new StringBuilder());
    HashMap<String, Integer> countAccetable = new HashMap<>();
    countAccetable.put("Qn", 0);
    countAccetable.put("Ord", 0);
    countAccetable.put("Nom", 0);
    countAccetable.put("Nar", 0);
    countAccetable.put("OrdQn", 0);
    countAccetable.put("unknown", 0);
    JFileChooser chooser = new JFileChooser();
    int returnVal = chooser.showOpenDialog(null);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        path = chooser.getSelectedFile().getAbsolutePath();
        System.out.println(path);
        Map<LoincId, LoincEntry> loincEntryMap = LoincEntry.getLoincEntryList(path);
        System.out.println("size of loinc table: " + loincEntryMap.size());
        for (LoincEntry loincEntry : loincEntryMap.values()) {
            if (countComplete.containsKey(loincEntry.getScale()) && countComplete.get(loincEntry.getScale()) < 50) {
                try {
                    List<Observation> results = ObservationDownloader.retrieveObservation(loincEntry.getLOINC_Number().toString());
                    if (results != null && !results.isEmpty()) {
                        for (Observation observation : results) {
                            if (isComplte(observation)) {
                                String aCompleteRecord = jsonParser.setPrettyPrint(true).encodeResourceToString(observation);
                                if (completeObservations.containsKey(loincEntry.getScale())) {
                                    completeObservations.get(loincEntry.getScale()).append(aCompleteRecord);
                                    completeObservations.get(loincEntry.getScale()).append("\n\n");
                                    completeObservations.get(loincEntry.getScale()).append(Character.toString((char) 12));
                                    countComplete.put(loincEntry.getScale(), countComplete.get(loincEntry.getScale()) + 1);
                                } else {
                                    completeObservations.get("unknown").append(aCompleteRecord);
                                    completeObservations.get("unknown").append("\n\n");
                                    completeObservations.get("unknown").append(Character.toString((char) 12));
                                    countComplete.put("unknown", countAccetable.get("unknown") + 1);
                                }
                                continue;
                            }
                            if (isAcceptable(observation)) {
                                String aAcceptableRecord = jsonParser.setPrettyPrint(true).encodeResourceToString(observation);
                                if (accetableObservations.containsKey(loincEntry.getScale()) && countAccetable.get(loincEntry.getScale()) < 50) {
                                    accetableObservations.get(loincEntry.getScale()).append(aAcceptableRecord);
                                    accetableObservations.get(loincEntry.getScale()).append("\n\n");
                                    accetableObservations.get(loincEntry.getScale()).append(Character.toString((char) 12));
                                    countAccetable.put(loincEntry.getScale(), countAccetable.get(loincEntry.getScale()) + 1);
                                } else if (countAccetable.get("unknown") < 50) {
                                    accetableObservations.get("unknown").append(aAcceptableRecord);
                                    accetableObservations.get("unknown").append("\n\n");
                                    accetableObservations.get("unknown").append(Character.toString((char) 12));
                                    countAccetable.put("unknown", countAccetable.get("unknown") + 1);
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    continue;
                }
            }
        }
    }
    for (String scale : completeObservations.keySet()) {
        if (!completeObservations.get(scale).toString().isEmpty()) {
            WriteToFile.writeToFile(completeObservations.get(scale).toString(), scale + "_complteObservations.txt");
        } else {
            System.out.println("No complete observations were found for loinc scale type: " + scale);
        }
    }
    for (String scale : accetableObservations.keySet()) {
        if (!accetableObservations.get(scale).toString().isEmpty()) {
            WriteToFile.writeToFile(accetableObservations.get(scale).toString(), scale + "_acceptableObservations.txt");
        } else {
            System.out.println("No acceptable observations were found for loinc scale type: " + scale);
        }
    }
}
Also used : HashMap(java.util.HashMap) LoincEntry(org.monarchinitiative.loinc2hpo.loinc.LoincEntry) LoincId(org.monarchinitiative.loinc2hpo.loinc.LoincId) JFileChooser(javax.swing.JFileChooser)

Example 2 with LoincEntry

use of org.monarchinitiative.loinc2hpo.loinc.LoincEntry in project loinc2hpo by monarch-initiative.

the class CurrentAnnotationController method populateTables.

private void populateTables() {
    if (model == null) {
        logger.error("model is null.");
        return;
    }
    this.currentAnnotation = model.getCurrentAnnotation();
    LoincEntry currentLoincEntry = model.getLoincEntryMap().get(currentAnnotation.getLoincId());
    annotationTitle.setText(String.format("Annotations for Loinc: %s[%s]", currentLoincEntry.getLOINC_Number(), currentLoincEntry.getLongName()));
    internalCodeAnnotations.clear();
    currentAnnotation.getCandidateHpoTerms().entrySet().stream().filter(p -> p.getKey().getSystem().equals(Loinc2HPOCodedValue.CODESYSTEM)).map(p -> new Annotation(p.getKey(), p.getValue())).forEach(internalCodeAnnotations::add);
    externalCodeAnnotations.clear();
    currentAnnotation.getCandidateHpoTerms().entrySet().stream().filter(p -> !p.getKey().getSystem().equals(Loinc2HPOCodedValue.CODESYSTEM)).map(p -> new Annotation(p.getKey(), p.getValue())).forEach(externalCodeAnnotations::add);
    interpretationCodeAnnotations.clear();
    for (Map.Entry<Code, Code> entry : CodeSystemConvertor.getCodeConversionMap().entrySet()) {
        logger.debug("key: " + entry.getKey() + "\nvalue: " + entry.getValue());
        HpoTermId4LoincTest result = currentAnnotation.loincInterpretationToHPO(entry.getValue());
        logger.debug("result is null? " + (result == null));
        if (result != null) {
            Annotation annotation = new Annotation(entry.getKey(), result);
            interpretationCodeAnnotations.add(annotation);
            logger.debug("interpretationCodeAnnotations size: " + interpretationCodeAnnotations.size());
        }
    }
    logger.debug("internalTableview is null: " + (internalTableview == null));
    logger.debug("internalCodeAnnotations is null: " + (internalTableview == null));
    logger.debug("internal annotation size: " + internalCodeAnnotations.size());
    internalCodeAnnotations.forEach(logger::info);
    logger.trace("exit initInternalTableview()");
}
Also used : javafx.scene.control(javafx.scene.control) Inject(com.google.inject.Inject) Node(javafx.scene.Node) Loinc2HPOCodedValue(org.monarchinitiative.loinc2hpo.codesystems.Loinc2HPOCodedValue) Model(org.monarchinitiative.loinc2hpo.model.Model) FXCollections(javafx.collections.FXCollections) LoincEntry(org.monarchinitiative.loinc2hpo.loinc.LoincEntry) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) FXML(javafx.fxml.FXML) ActionEvent(javafx.event.ActionEvent) Logger(org.apache.logging.log4j.Logger) HpoTermId4LoincTest(org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest) UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation) ReadOnlyBooleanWrapper(javafx.beans.property.ReadOnlyBooleanWrapper) Stage(javafx.stage.Stage) CodeSystemConvertor(org.monarchinitiative.loinc2hpo.codesystems.CodeSystemConvertor) Annotation(org.monarchinitiative.loinc2hpo.model.Annotation) Map(java.util.Map) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) LogManager(org.apache.logging.log4j.LogManager) Singleton(com.google.inject.Singleton) LoincEntry(org.monarchinitiative.loinc2hpo.loinc.LoincEntry) HpoTermId4LoincTest(org.monarchinitiative.loinc2hpo.loinc.HpoTermId4LoincTest) Map(java.util.Map) Code(org.monarchinitiative.loinc2hpo.codesystems.Code) UniversalLoinc2HPOAnnotation(org.monarchinitiative.loinc2hpo.loinc.UniversalLoinc2HPOAnnotation) Annotation(org.monarchinitiative.loinc2hpo.model.Annotation)

Aggregations

LoincEntry (org.monarchinitiative.loinc2hpo.loinc.LoincEntry)2 Inject (com.google.inject.Inject)1 Singleton (com.google.inject.Singleton)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ReadOnlyBooleanWrapper (javafx.beans.property.ReadOnlyBooleanWrapper)1 ReadOnlyStringWrapper (javafx.beans.property.ReadOnlyStringWrapper)1 FXCollections (javafx.collections.FXCollections)1 ObservableList (javafx.collections.ObservableList)1 ActionEvent (javafx.event.ActionEvent)1 FXML (javafx.fxml.FXML)1 Node (javafx.scene.Node)1 javafx.scene.control (javafx.scene.control)1 BorderPane (javafx.scene.layout.BorderPane)1 Stage (javafx.stage.Stage)1 JFileChooser (javax.swing.JFileChooser)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 Code (org.monarchinitiative.loinc2hpo.codesystems.Code)1 CodeSystemConvertor (org.monarchinitiative.loinc2hpo.codesystems.CodeSystemConvertor)1