@@ -41,6 +41,9 @@ public RecordedActionSet run(@NotNull PipelineJob pipelineJob) throws PipelineJo
4141 updateVaccineInformation (pipelineJob );
4242 updateChallengeAnchorDates (pipelineJob );
4343 updateArtInitiationAnchorDates (pipelineJob );
44+ updateJS46 ();
45+
46+ // TODO: Set other cohort-by-cohort params
4447
4548 return new RecordedActionSet ();
4649 }
@@ -283,4 +286,44 @@ public void setContainerUser(ContainerUser containerUser)
283286 {
284287 _containerUser = containerUser ;
285288 }
289+
290+ private void updateJS46 () throws PipelineJobException
291+ {
292+ updateTreatmentRecords ("JS46" , new SimpleFilter (FieldKey .fromString ("treatment" ), "SIV - Unknown" ), Map .of ("treatment" , "SIVmac239" , "route" , "IV" ));
293+ }
294+
295+ private void updateTreatmentRecords (String cohortName , SimpleFilter treatmentFilter , final Map <String , Object > additionalProps ) throws PipelineJobException
296+ {
297+ TableInfo assignments = QueryService .get ().getUserSchema (_containerUser .getUser (), _containerUser .getContainer (), "study" ).getTable ("assignment" );
298+ List <String > ids = new TableSelector (assignments , PageFlowUtil .set ("Id" ), new SimpleFilter (FieldKey .fromString ("study" ), cohortName ), null ).getArrayList (String .class );
299+ treatmentFilter .addCondition (FieldKey .fromString ("Id" ), ids , CompareType .IN );
300+
301+ TableInfo treatments = QueryService .get ().getUserSchema (_containerUser .getUser (), _containerUser .getContainer (), "study" ).getTable ("treatments" );
302+ List <Map <String , Object >> toUpdate = new ArrayList <>();
303+ new TableSelector (treatments , PageFlowUtil .set ("lsid" ), treatmentFilter , null ).forEachMap (rs -> {
304+ Map <String , Object > toAdd = new CaseInsensitiveHashMap <>(rs );
305+ toAdd .putAll (additionalProps );
306+ toUpdate .add (toAdd );
307+ });
308+
309+ if (!toUpdate .isEmpty ())
310+ {
311+ try
312+ {
313+ BatchValidationException bve = new BatchValidationException ();
314+
315+ List <Map <String , Object >> oldKeys = toUpdate .stream ().map (x -> (Map <String , Object >)new CaseInsensitiveHashMap <>(Map .of ("lsid" , x .get ("lsid" )))).toList ();
316+ treatments .getUpdateService ().updateRows (_containerUser .getUser (), _containerUser .getContainer (), toUpdate , oldKeys , bve , null , null );
317+
318+ if (bve .hasErrors ())
319+ {
320+ throw bve ;
321+ }
322+ }
323+ catch (SQLException | BatchValidationException | QueryUpdateServiceException | InvalidKeyException e )
324+ {
325+ throw new PipelineJobException (e );
326+ }
327+ }
328+ }
286329}
0 commit comments