-
Notifications
You must be signed in to change notification settings - Fork 13
WIP: PeriodUtils and not complete MeasureReport implementation for R4 #10
base: master
Are you sure you want to change the base?
Conversation
{ | ||
final Map<String, Object> variables = new HashMap<>( scriptVariables ); | ||
|
||
final DataValueSet dataValueSet = getResource( fhirClientResource, context, ruleInfo, scriptVariables ).orElse( null ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block could be moved to version independent abstract class.
} | ||
|
||
//------------------------------ | ||
if ( ruleInfo.getRule().getDataSetIdLookupScript() == null ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be handled directly in Java code. No data set ID lookup script is required.
// String version = mr.getMeta().getVersionId(); | ||
|
||
dataValueSet.setId( createArtificialDataValueSetId( mr ) ); | ||
dataValueSet.setLastUpdated( lastUpdated ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will most likely be overridden by server.
|
||
dataValueSet.setId( createArtificialDataValueSetId( mr ) ); | ||
dataValueSet.setLastUpdated( lastUpdated ); | ||
dataValueSet.setPeriod( PeriodUtils.getDHIS2PeriodString( mr.getPeriod().getStart(), mr.getPeriod().getEnd() ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IllegalArgumentException that may be thrown by the period utils must be converted into a TransformerDataException.
dataSetId.ifPresent( dataValueSet::setDataSetId ); | ||
} | ||
|
||
if ( dataValueSet.getDataSetId() == null ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no data set ID could be determined, a TransformerDataException should be thrown.
organizationUnit.ifPresent( ou -> dataValueSet.setOrgUnitId( ou.getId() ) ); | ||
} | ||
|
||
if ( !organizationUnit.isPresent() ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TransformerDataException should be thrown.
|
||
dataValueSet.setId( createArtificialDataValueSetId( mr ) ); | ||
dataValueSet.setLastUpdated( lastUpdated ); | ||
dataValueSet.setPeriod( PeriodUtils.getDHIS2PeriodString( mr.getPeriod().getStart(), mr.getPeriod().getEnd() ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Period start and end are optional in FHIR. OpenLMIS profile will not be validated by the Adapter (in General profile checking could be added, but this has other advantages/disadavantages).
String periodString = String.valueOf( startDate.getYear() ); | ||
|
||
//Period is year | ||
if ( totalMonths == 12 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch could be used instead of if/else.
|
||
try | ||
{ | ||
if ( Objects.isNull( mr.getPeriod() ) || Objects.isNull( mr.getPeriod().getStart() ) || Objects.isNull( mr.getPeriod().getEnd() ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getPeriod() should never be null (contract of HAPI FHIR API, objects and lists and created always, isEmpty() can be used for null check).
{ | ||
try | ||
{ | ||
String measureUuid = measureReport.getMeasure().substring( 8 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Measure is canonical with a possible complex syntax. Eiteher the URI utils should be used or the utilities that are also able to retrieve the remote measure (see previous private chat).
try | ||
{ | ||
String measureUuid = measureReport.getMeasure().substring( 8 ); | ||
String locationId = measureReport.getReporter().getReference().substring( 9 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Location ID should be looked up by getOrgUnitId(). See also new transformers for FHIR CarePlan and QuestionnaireResponse (to DHIS2 transformers).
|
||
private void transformDataValues( MeasureReport measureReport, DataValueSet dataValueSet, ZonedDateTime lastUpdated ) | ||
{ | ||
for ( int i = 1; i < measureReport.getGroup().size(); i++ ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make any sense to use this kind of loop instead of the loop over an iterable? And why to skip the first group item???
D2INT-36