Author: seanfinan Date: Sun Feb 4 19:12:03 2018 New Revision: 1823103 URL: http://svn.apache.org/viewvc?rev=1823103&view=rev Log: Set patientId in patient cas
Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/patient/PatientNoteStore.java ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/util/SourceMetadataUtil.java Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/patient/PatientNoteStore.java URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/patient/PatientNoteStore.java?rev=1823103&r1=1823102&r2=1823103&view=diff ============================================================================== --- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/patient/PatientNoteStore.java (original) +++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/patient/PatientNoteStore.java Sun Feb 4 19:12:03 2018 @@ -3,6 +3,8 @@ package org.apache.ctakes.core.patient; import org.apache.ctakes.core.util.DocumentIDAnnotationUtil; import org.apache.ctakes.core.util.SourceMetadataUtil; +import org.apache.ctakes.typesystem.type.structured.DocumentIdPrefix; +import org.apache.ctakes.typesystem.type.structured.Metadata; import org.apache.log4j.Logger; import org.apache.uima.UIMAException; import org.apache.uima.cas.CASException; @@ -239,6 +241,7 @@ public enum PatientNoteStore { if ( patientCas == null ) { try { patientCas = JCasFactory.createJCas(); + setPatientId( patientCas, patientId ); _patientMap.put( patientId, patientCas ); } catch ( UIMAException uE ) { LOGGER.error( uE.getMessage() ); @@ -260,6 +263,20 @@ public enum PatientNoteStore { } } + /** + * Make sure the patient cas contains its patient id + * + * @param jCas - + * @param patientId - + */ + static private void setPatientId( final JCas jCas, final String patientId ) { + final DocumentIdPrefix documentIdPrefix = new DocumentIdPrefix( jCas ); + documentIdPrefix.setDocumentIdPrefix( patientId ); + documentIdPrefix.addToIndexes(); + final Metadata metadata = SourceMetadataUtil.getOrCreateMetadata( jCas ); + metadata.setPatientIdentifier( patientId ); + } + ///////////////// view fetchers /////////////// /** Modified: ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/util/SourceMetadataUtil.java URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/util/SourceMetadataUtil.java?rev=1823103&r1=1823102&r2=1823103&view=diff ============================================================================== --- ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/util/SourceMetadataUtil.java (original) +++ ctakes/trunk/ctakes-core/src/main/java/org/apache/ctakes/core/util/SourceMetadataUtil.java Sun Feb 4 19:12:03 2018 @@ -56,7 +56,7 @@ final public class SourceMetadataUtil { * @param jcas ye olde jay-cas * @return the Metadata for the given jcas or null if one is not found */ - static private Metadata getMetadata( final JCas jcas ) { + static public Metadata getMetadata( final JCas jcas ) { final Collection<Metadata> metadatas = JCasUtil.select( jcas, Metadata.class ); if ( metadatas == null || metadatas.isEmpty() ) { return null; @@ -65,6 +65,20 @@ final public class SourceMetadataUtil { } /** + * @param jCas ye olde jay-cas + * @return the Metadata for the given jcas + */ + static public Metadata getOrCreateMetadata( final JCas jCas ) { + final Metadata metadata = getMetadata( jCas ); + if ( metadata != null ) { + return metadata; + } + final Metadata newMetadata = new Metadata( jCas ); + newMetadata.addToIndexes(); + return newMetadata; + } + + /** * The first step in utilizing SourceData is getting it! * * @param jcas ye olde jay-cas @@ -79,6 +93,21 @@ final public class SourceMetadataUtil { } /** + * @param jCas ye olde jay-cas + * @return the metadata for the source associated with the jcas + */ + static public SourceData getOrCreateSourceData( final JCas jCas ) { + final SourceData sourceData = getSourceData( jCas ); + if ( sourceData != null ) { + return sourceData; + } + final Metadata metadata = getOrCreateMetadata( jCas ); + final SourceData newSourceData = new SourceData( jCas ); + metadata.setSourceData( newSourceData ); + return newSourceData; + } + + /** * @param sourcedata - * @return the instance id or -1 if there isn't one * @throws ResourceProcessException if the internal value is not parseable as long