Skip to content

Commit

Permalink
Consolidate ObservationMapper version and ObsBuilder versions
Browse files Browse the repository at this point in the history
  • Loading branch information
mseaton committed May 4, 2024
1 parent 76bbdf5 commit a7aeb88
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,18 @@
import org.openmrs.Concept;
import org.openmrs.Drug;
import org.openmrs.Obs;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.api.context.Context;
import org.openmrs.module.emrapi.encounter.domain.EncounterTransaction;
import org.openmrs.module.emrapi.encounter.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;

@Component("observationMapper")
@OpenmrsProfile(openmrsPlatformVersion = "[1.9.* - 1.11.*]")
public class ObservationMapper {
private ConceptMapper conceptMapper;
private DrugMapper drugMapper;
private UserMapper userMapper;

@Autowired(required = false)
private final ConceptMapper conceptMapper;
private final DrugMapper drugMapper;
private final UserMapper userMapper;

public ObservationMapper(ConceptMapper conceptMapper, DrugMapper drugMapper, UserMapper userMapper) {
this.conceptMapper = conceptMapper;
this.drugMapper = drugMapper;
Expand All @@ -59,6 +54,18 @@ public EncounterTransaction.Observation map(Obs obs) {
observation.addGroupMember(map(obsGroupMember));
}
}
observation.setFormNamespace(obs.getFormFieldNamespace());
observation.setFormFieldPath(obs.getFormFieldPath());

Obs.Interpretation obsInterpretation = obs.getInterpretation();
Obs.Status obsStatus = obs.getStatus();

String interpretation = (obsInterpretation != null) ? obsInterpretation.name() : null;
String status = (obsStatus != null) ? obsStatus.name() : null;

observation.setInterpretation(interpretation);
observation.setStatus(status);

return observation;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,9 @@ public ObsBuilder setEncounter(Encounter encounter) {
obs.setEncounter(encounter);
return this;
}

public ObsBuilder setFormField(String formNameSpace, String formFieldPath){
obs.setFormField(formNameSpace, formFieldPath);
return this;
}
}
6 changes: 6 additions & 0 deletions api/src/main/resources/moduleApplicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@
<constructor-arg name="observationTypeMatcher" ref="observationTypeMatcher"/>
</bean>

<bean id="observationMapper" class="org.openmrs.module.emrapi.encounter.ObservationMapper">
<constructor-arg name="conceptMapper" ref="conceptMapper"/>
<constructor-arg name="drugMapper" ref="drugMapper"/>
<constructor-arg name="userMapper" ref="userMapper"/>
</bean>

<bean id="conceptMapper" class="org.openmrs.module.emrapi.encounter.ConceptMapper"/>

<bean id="diagnosisMapper" class="org.openmrs.module.emrapi.encounter.DiagnosisMapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ public void setUp(){
@Test
public void shouldMapObservationWithNumericValue(){
when(conceptDatatype.isNumeric()).thenReturn(true);
Obs obs = obsBuilder.setValue(100.0).get();
Obs obs = obsBuilder.setValue(100.0).setFormField("form uuid", "formFieldPath").get();

EncounterTransaction.Observation observation = observationMapper.map(obs);

assertEquals(obs.getUuid(), observation.getUuid());
assertEquals(100.0, observation.getValue());
assertEquals(observation.getFormNamespace(), "form uuid");
assertEquals(observation.getFormFieldPath(), "formFieldPath");
}

@Test
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit a7aeb88

Please sign in to comment.