Search code examples
javapathannotations

How to get a PATH annotation inside a class


I have the next problem that i cannot solve.

I do not know how to access to the next annotation (@Path annotation of IdentificationCluster) in a different class from the main. The problem is that I follow the typical way to get an annotation by using the getAnnotation() method but it is impossible to get.

package org.example.n2composition;

import com.nedap.archie.rm.archetyped.FeederAudit;
import com.nedap.archie.rm.generic.Participation;
import com.nedap.archie.rm.generic.PartyIdentified;
import com.nedap.archie.rm.generic.PartyProxy;
import java.lang.String;
import java.time.temporal.TemporalAccessor;
import java.util.List;
import javax.annotation.processing.Generated;
import org.ehrbase.client.annotations.Archetype;
import org.ehrbase.client.annotations.Entity;
import org.ehrbase.client.annotations.Id;
import org.ehrbase.client.annotations.Path;
import org.ehrbase.client.annotations.Template;
import org.ehrbase.client.classgenerator.interfaces.CompositionEntity;
import org.ehrbase.client.classgenerator.shareddefinition.Category;
import org.ehrbase.client.classgenerator.shareddefinition.Language;
import org.ehrbase.client.classgenerator.shareddefinition.Setting;
import org.ehrbase.client.classgenerator.shareddefinition.Territory;
import org.ehrbase.client.openehrclient.VersionUid;
import org.example.n2composition.definition.CodedTextDefiningCode;
import org.example.n2composition.definition.IdentificationCluster;
import org.example.n2composition.definition.PatientroleCluster;
import org.example.n2composition.definition.ProblemDiagnosisEvaluation;

@Entity
@Archetype("openEHR-EHR-COMPOSITION.information.v0")
@Generated(
    value = "org.ehrbase.client.classgenerator.ClassGenerator",
    date = "2023-03-24T11:50:15.994180+01:00",
    comments = "https://github.com/ehrbase/openEHR_SDK Version: 1.26.0-SNAPSHOT"
)
@Template("2")
public class N2Composition implements CompositionEntity {
  /**
   * Path: 2/Coded text
   */
  @Path("/category[at0001]|defining_code")
  private CodedTextDefiningCode codedTextDefiningCode;

  /**
   * Path: 2/Event Context/CLUSTER/identification
   * Description: identification
   */
  @Path("/context[at0002]/other_context[at0018]/items[at0019]/items[openEHR-EHR-CLUSTER.identification.v0]")
  private IdentificationCluster identification;

Once i try to call the annotation, the next error happens.

package org.example;



import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.nedap.archie.rm.datavalues.DvCodedText;
import org.ehrbase.client.annotations.Template;
import org.example.n2composition.N2Composition;
import org.example.n2composition.definition.IdentificationCluster;


import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args) throws NoSuchFieldException {

        //Lectura del fichero para obtener los path y los valores

        ReadingFile r = new ReadingFile();

        r.resultado();

        String s1 = "C:\\Users\\omarah\\Documents\\ETL\\MAPEOS\\MAPEO1_1.txt";

        String s2 = "C:\\Users\\omarah\\Documents\\ETL\\MAPEOS\\ATRIBUTOSYVALORES-DIAGNÓSTICO2.txt";

        r.reading(s1,s2);

        /*System.out.println(r.getResult1());

        System.out.println(r.getResult1().size());

        System.out.println(r.getResult2());

        System.out.println(r.getResult2().size());

        System.out.println(r.getElements());

        System.out.println(r.getElements().size());*/

        List<String> list1 = r.getResult1();

        List<String> list2 = r.getResult2();

        //Finalización de la lectura del path

        //Creación de la composición y empezar a darle valores

        N2Composition n2 = new N2Composition(); //crear nueva COMPOSITION

        IdentificationCluster i = new IdentificationCluster();

        DvCodedText dv = new DvCodedText();

        dv.setValue("hola");

        i.setDvCodedText(dv);

        Field f = N2Composition.class.getDeclaredField("identification");

        String p = f.getAnnotation(Path.class).value();

        n2.setIdentification(i);

        //String p = s.g

        //System.out.println(p);






        //n2.setIdentification((i.setDvCodedText(dv.setValue(list2[])));

    }


}

enter image description here

Does anyone know how to solve it?


Solution

  • It looks like your imports are incorrect.

    In the N2Composition class you are using import org.ehrbase.client.annotations.Path;

    and then in the Main class (and also in the error message) java.nio.file.Path