private void addNewVersion ( Patient thePatient , Long theId ) { InstantDt publishedDate ; if ( ! myIdToPatientVersions . containsKey ( theId ) ) { myIdToPatientVersions . put ( theId , new LinkedList < Patient > ( ) ) ; publishedDate = InstantDt . withCurrentTime ( ) ; } else { Patient currentPatitne = myIdToPatientVersions . get ( theId ) . getLast ( ) ; Map < ResourceMetadataKeyEnum < ? > , Object > resourceMetadata = currentPatitne . getResourceMetadata ( ) ; publishedDate = ( InstantDt ) resourceMetadata . get ( ResourceMetadataKeyEnum . PUBLISHED ) ; } /* * PUBLISHED time will always be set to the time that the first version was stored. UPDATED time is set to the time that the new version was stored. */ thePatient . getResourceMetadata ( ) . put ( ResourceMetadataKeyEnum . PUBLISHED , publishedDate ) ; thePatient . getResourceMetadata ( ) . put ( ResourceMetadataKeyEnum . UPDATED , InstantDt . withCurrentTime ( ) ) ; Deque < Patient > existingVersions = myIdToPatientVersions . get ( theId ) ; // We just use the current number of versions as the next version number String newVersion = Integer . toString ( existingVersions . size ( ) ) ; // Create an ID with the new version and assign it back to the resource IdDt newId = new IdDt ( "Patient" , Long . toString ( theId ) , newVersion ) ; thePatient . setId ( newId ) ; existingVersions . add ( thePatient ) ; }
Stores a new version of the patient in memory so that it can be retrieved later .